mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CS-19072: fixed broken pagination and count in listVpcOfferings
This commit is contained in:
parent
8b98cc2202
commit
fa74b3a300
@ -20,6 +20,8 @@ package com.cloud.network.vpc;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public interface VpcProvisioningService {
|
||||
|
||||
public VpcOffering getVpcOffering(long vpcOfferingId);
|
||||
@ -29,7 +31,7 @@ public interface VpcProvisioningService {
|
||||
Map serviceCapabilitystList,
|
||||
Long serviceOfferingId);
|
||||
|
||||
List<? extends VpcOffering> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr, Boolean isDefault, String keyword,
|
||||
Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr, Boolean isDefault, String keyword,
|
||||
String state, Long startIndex, Long pageSizeVal);
|
||||
|
||||
/**
|
||||
|
||||
@ -19,16 +19,16 @@ package org.apache.cloudstack.api.command.user.vpc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.VpcOfferingResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.vpc.VpcOffering;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listVPCOfferings", description = "Lists VPC offerings", responseObject = VpcOfferingResponse.class,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
@ -93,17 +93,17 @@ public class ListVPCOfferingsCmd extends BaseListCmd {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<? extends VpcOffering> offerings =
|
||||
Pair<List<? extends VpcOffering>, Integer> offerings =
|
||||
_vpcProvSvc.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(), getSupportedServices(), isDefault, this.getKeyword(), getState(),
|
||||
this.getStartIndex(), this.getPageSizeVal());
|
||||
ListResponse<VpcOfferingResponse> response = new ListResponse<VpcOfferingResponse>();
|
||||
List<VpcOfferingResponse> offeringResponses = new ArrayList<VpcOfferingResponse>();
|
||||
for (VpcOffering offering : offerings) {
|
||||
for (VpcOffering offering : offerings.first()) {
|
||||
VpcOfferingResponse offeringResponse = _responseGenerator.createVpcOfferingResponse(offering);
|
||||
offeringResponses.add(offeringResponse);
|
||||
}
|
||||
|
||||
response.setResponses(offeringResponses);
|
||||
response.setResponses(offeringResponses, offerings.second());
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
@ -113,6 +113,7 @@ import com.cloud.user.ResourceLimitService;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.Ternary;
|
||||
import com.cloud.utils.component.ManagerBase;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
@ -608,9 +609,9 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends VpcOffering> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr, Boolean isDefault, String keyword,
|
||||
public Pair<List<? extends VpcOffering>,Integer> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr, Boolean isDefault, String keyword,
|
||||
String state, Long startIndex, Long pageSizeVal) {
|
||||
Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, startIndex, pageSizeVal);
|
||||
Filter searchFilter = new Filter(VpcOfferingVO.class, "created", false, null, null);
|
||||
SearchCriteria<VpcOfferingVO> sc = _vpcOffDao.createSearchCriteria();
|
||||
|
||||
if (keyword != null) {
|
||||
@ -670,9 +671,21 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
}
|
||||
}
|
||||
|
||||
return supportedOfferings;
|
||||
List<?> wPagination = StringUtils.applyPagination(supportedOfferings, startIndex, pageSizeVal);
|
||||
if (wPagination != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>((List<VpcOffering>) wPagination, supportedOfferings.size());
|
||||
return listWPagination;
|
||||
}
|
||||
return new Pair<List<? extends VpcOffering>, Integer>(supportedOfferings, supportedOfferings.size());
|
||||
} else {
|
||||
return offerings;
|
||||
List<?> wPagination = StringUtils.applyPagination(offerings, startIndex, pageSizeVal);
|
||||
if (wPagination != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<List<? extends VpcOffering>, Integer> listWPagination = new Pair<List<? extends VpcOffering>, Integer>((List<VpcOffering>) wPagination, offerings.size());
|
||||
return listWPagination;
|
||||
}
|
||||
return new Pair<List<? extends VpcOffering>, Integer>(offerings, offerings.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user