use of com.cloud.legacymodel.utils.Ternary in project cosmic by MissionCriticalCloud.
the class VpcManagerImpl method listPrivateGateway.
@Override
public Pair<List<PrivateGateway>, Integer> listPrivateGateway(final ListPrivateGatewaysCmd cmd) {
final String ipAddress = cmd.getIpAddress();
final String networkId = cmd.getNetworkId();
final Long vpcId = cmd.getVpcId();
final Long id = cmd.getId();
Boolean isRecursive = cmd.isRecursive();
final Boolean listAll = cmd.listAll();
Long domainId = cmd.getDomainId();
final String accountName = cmd.getAccountName();
final Account caller = CallContext.current().getCallingAccount();
final List<Long> permittedAccounts = new ArrayList<>();
final String state = cmd.getState();
final Long projectId = cmd.getProjectId();
final Filter searchFilter = new Filter(VpcGatewayVO.class, "id", false, cmd.getStartIndex(), cmd.getPageSizeVal());
final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(domainId, isRecursive, null);
_accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
domainId = domainIdRecursiveListProject.first();
isRecursive = domainIdRecursiveListProject.second();
final ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
final SearchBuilder<VpcGatewayVO> sb = _vpcGatewayDao.createSearchBuilder();
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
final SearchCriteria<VpcGatewayVO> sc = sb.create();
_accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (id != null) {
sc.addAnd("id", Op.EQ, id);
}
if (ipAddress != null) {
sc.addAnd("ip4Address", Op.EQ, ipAddress);
}
if (state != null) {
sc.addAnd("state", Op.EQ, state);
}
if (vpcId != null) {
sc.addAnd("vpcId", Op.EQ, vpcId);
}
if (networkId != null) {
sc.addAnd("networkId", Op.EQ, networkId);
}
final Pair<List<VpcGatewayVO>, Integer> vos = _vpcGatewayDao.searchAndCount(sc, searchFilter);
final List<PrivateGateway> privateGtws = new ArrayList<>(vos.first().size());
for (final VpcGateway vo : vos.first()) {
privateGtws.add(getPrivateGatewayProfile(vo));
}
return new Pair<>(privateGtws, vos.second());
}
Aggregations