bug 7223: pagesize and page should be specified together in "list" api commands

status 7223: resolved fixed
This commit is contained in:
alena 2010-11-19 13:29:48 -08:00
parent 516e944d2c
commit e5c137e303
3 changed files with 13 additions and 3 deletions

View File

@ -161,4 +161,6 @@ public class ApiConstants {
public static final String VOLUME_ID = "volumeid";
public static final String ZONE_ID = "zoneid";
public static final String NETWORK_TYPE = "networktype";
public static final String PAGE = "page";
public static final String PAGE_SIZE = "pagesize";
}

View File

@ -119,8 +119,16 @@ public class ApiDispatcher {
}
}
public static void setupParameters(BaseCmd cmd, Map<String, String> params) {
public static void setupParameters(BaseCmd cmd, Map<String, String> params){
Map<String, Object> unpackedParams = cmd.unpackParams(params);
if (cmd instanceof BaseListCmd) {
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (unpackedParams.get(ApiConstants.PAGE_SIZE) != null)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
} else if ((unpackedParams.get(ApiConstants.PAGE_SIZE) == null) && (unpackedParams.get(ApiConstants.PAGE) != null)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
}
}
Field[] fields = cmd.getClass().getDeclaredFields();
Class<?> superClass = cmd.getClass().getSuperclass();
while (BaseCmd.class.isAssignableFrom(superClass)) {

View File

@ -11,10 +11,10 @@ public abstract class BaseListCmd extends BaseCmd {
private String keyword;
// FIXME: Need to be able to specify next/prev/first/last, so Integer might not be right
@Parameter(name="page", type=CommandType.INTEGER)
@Parameter(name=ApiConstants.PAGE, type=CommandType.INTEGER)
private Integer page;
@Parameter(name="pagesize", type=CommandType.INTEGER)
@Parameter(name=ApiConstants.PAGE_SIZE, type=CommandType.INTEGER)
private Integer pageSize;
/////////////////////////////////////////////////////