|
40 | 40 | import javax.inject.Inject; |
41 | 41 | import javax.naming.ConfigurationException; |
42 | 42 |
|
43 | | -import com.cloud.network.security.SecurityGroupService; |
44 | | -import org.apache.log4j.Logger; |
45 | | - |
46 | 43 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
47 | 44 | import org.apache.cloudstack.acl.SecurityChecker.AccessType; |
48 | 45 | import org.apache.cloudstack.api.command.admin.network.CreateNetworkCmdByAdmin; |
|
57 | 54 | import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService; |
58 | 55 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
59 | 56 | import org.apache.cloudstack.network.element.InternalLoadBalancerElementService; |
| 57 | +import org.apache.log4j.Logger; |
60 | 58 |
|
61 | 59 | import com.cloud.api.ApiDBUtils; |
62 | 60 | import com.cloud.configuration.Config; |
|
129 | 127 | import com.cloud.network.rules.FirewallRuleVO; |
130 | 128 | import com.cloud.network.rules.RulesManager; |
131 | 129 | import com.cloud.network.rules.dao.PortForwardingRulesDao; |
| 130 | +import com.cloud.network.security.SecurityGroupService; |
132 | 131 | import com.cloud.network.vpc.NetworkACL; |
133 | 132 | import com.cloud.network.vpc.PrivateIpVO; |
134 | 133 | import com.cloud.network.vpc.Vpc; |
@@ -1624,33 +1623,16 @@ public Pair<List<? extends Network>, Integer> searchForNetworks(ListNetworksCmd |
1624 | 1623 | } |
1625 | 1624 |
|
1626 | 1625 | //Now apply pagination |
1627 | | - //Most likely pageSize will never exceed int value, and we need integer to partition the listToReturn |
1628 | | - boolean notNull = cmd.getStartIndex() != null && cmd.getPageSizeVal() != null; |
1629 | | - if (notNull && cmd.getStartIndex() <= Integer.MAX_VALUE && cmd.getStartIndex() >= Integer.MIN_VALUE && cmd.getPageSizeVal() <= Integer.MAX_VALUE |
1630 | | - && cmd.getPageSizeVal() >= Integer.MIN_VALUE) { |
1631 | | - int index = cmd.getStartIndex().intValue() == 0 ? 0 : cmd.getStartIndex().intValue() / cmd.getPageSizeVal().intValue(); |
1632 | | - List<NetworkVO> wPagination = new ArrayList<NetworkVO>(); |
1633 | | - List<List<NetworkVO>> partitions = partitionNetworks(networksToReturn, cmd.getPageSizeVal().intValue()); |
1634 | | - if (index < partitions.size()) { |
1635 | | - wPagination = partitions.get(index); |
1636 | | - } |
1637 | | - return new Pair<List<? extends Network>, Integer>(wPagination, networksToReturn.size()); |
| 1626 | + List<?> wPagination = StringUtils.applyPagination(networksToReturn, cmd.getStartIndex(), cmd.getPageSizeVal()); |
| 1627 | + if (wPagination != null) { |
| 1628 | + @SuppressWarnings("unchecked") |
| 1629 | + Pair<List<? extends Network>, Integer> listWPagination = new Pair<List<? extends Network>, Integer>((List<NetworkVO>) wPagination, networksToReturn.size()); |
| 1630 | + return listWPagination; |
1638 | 1631 | } |
1639 | 1632 |
|
1640 | 1633 | return new Pair<List<? extends Network>, Integer>(networksToReturn, networksToReturn.size()); |
1641 | 1634 | } |
1642 | 1635 |
|
1643 | | - private static List<List<NetworkVO>> partitionNetworks(List<NetworkVO> originalList, int chunkSize) { |
1644 | | - List<List<NetworkVO>> listOfChunks = new ArrayList<List<NetworkVO>>(); |
1645 | | - for (int i = 0; i < originalList.size() / chunkSize; i++) { |
1646 | | - listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize + chunkSize)); |
1647 | | - } |
1648 | | - if (originalList.size() % chunkSize != 0) { |
1649 | | - listOfChunks.add(originalList.subList(originalList.size() - originalList.size() % chunkSize, originalList.size())); |
1650 | | - } |
1651 | | - return listOfChunks; |
1652 | | - } |
1653 | | - |
1654 | 1636 | private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO> sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType, |
1655 | 1637 | String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean specifyIpRanges, Long vpcId, |
1656 | 1638 | Map<String, String> tags, Boolean display) { |
|
0 commit comments