bug 12877: fixed pagesize=-1 behavior

status 12877: resolved fixed
This commit is contained in:
Alena Prokharchyk 2012-01-09 13:24:47 -08:00
parent 5ea56cdfeb
commit 223497baa4
3 changed files with 17 additions and 7 deletions

View File

@ -24,6 +24,7 @@ import com.cloud.exception.InvalidParameterValueException;
public abstract class BaseListCmd extends BaseCmd {
private static Long MAX_PAGESIZE = null;
public static Long PAGESIZE_UNLIMITED = -1L;
// ///////////////////////////////////////////////////
// ///////// BaseList API parameters /////////////////
@ -58,7 +59,7 @@ public abstract class BaseListCmd extends BaseCmd {
throw new InvalidParameterValueException("Page size can't exceed max allowed page size value: " + MAX_PAGESIZE.longValue());
}
if (pageSize != null && pageSize.longValue() == -1 && page != null) {
if (pageSize != null && pageSize.longValue() == PAGESIZE_UNLIMITED && page != null) {
throw new InvalidParameterValueException("Can't specify page parameter when pagesize is -1 (Unlimited)");
}
@ -66,7 +67,7 @@ public abstract class BaseListCmd extends BaseCmd {
}
static void configure() {
if (_configService.getDefaultPageSize().longValue() != -1) {
if (_configService.getDefaultPageSize().longValue() != PAGESIZE_UNLIMITED) {
MAX_PAGESIZE = _configService.getDefaultPageSize();
}
}
@ -80,8 +81,12 @@ public abstract class BaseListCmd extends BaseCmd {
public Long getPageSizeVal() {
Long defaultPageSize = MAX_PAGESIZE;
Integer pageSizeInt = getPageSize();
if (pageSizeInt != null && pageSizeInt.intValue() != -1) {
defaultPageSize = pageSizeInt.longValue();
if (pageSizeInt != null) {
if (pageSizeInt.longValue() == PAGESIZE_UNLIMITED) {
defaultPageSize = null;
} else {
defaultPageSize = pageSizeInt.longValue();
}
}
return defaultPageSize;
}

View File

@ -9,7 +9,6 @@ import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.StorageNetworkIpRangeResponse;
import com.cloud.dc.StorageNetworkIpRange;
import com.cloud.event.EventTypes;

View File

@ -175,9 +175,15 @@ public class ApiDispatcher {
Map<String, Object> unpackedParams = cmd.unpackParams(params);
if (cmd instanceof BaseListCmd) {
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (unpackedParams.get(ApiConstants.PAGE_SIZE) != null)) {
Object pageSizeObj = unpackedParams.get(ApiConstants.PAGE_SIZE);
Long pageSize = null;
if (pageSizeObj != null) {
pageSize = Long.valueOf((String)pageSizeObj);
}
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
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)) {
} else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
}
}