mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 12877: fixed pagesize=-1 behavior
status 12877: resolved fixed
This commit is contained in:
parent
5ea56cdfeb
commit
223497baa4
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user