Search in sources :

Example 36 with Ternary

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());
}
Also used : Account(com.cloud.legacymodel.user.Account) Ternary(com.cloud.legacymodel.utils.Ternary) ArrayList(java.util.ArrayList) PrivateGateway(com.cloud.legacymodel.network.vpc.PrivateGateway) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) VpcGateway(com.cloud.legacymodel.network.vpc.VpcGateway) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Pair(com.cloud.legacymodel.utils.Pair)

Aggregations

Ternary (com.cloud.legacymodel.utils.Ternary)36 ArrayList (java.util.ArrayList)33 Account (com.cloud.legacymodel.user.Account)31 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)30 Filter (com.cloud.utils.db.Filter)28 List (java.util.List)24 Pair (com.cloud.legacymodel.utils.Pair)23 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)12 TemplateFilter (com.cloud.legacymodel.storage.VirtualMachineTemplate.TemplateFilter)12 ResourceTagVO (com.cloud.tags.ResourceTagVO)8 LinkedList (java.util.LinkedList)6 IPAddressVO (com.cloud.network.dao.IPAddressVO)5 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)3 Vpc (com.cloud.legacymodel.network.vpc.Vpc)3 HypervisorType (com.cloud.model.enumeration.HypervisorType)3 DomainVO (com.cloud.domain.DomainVO)2 HostVO (com.cloud.host.HostVO)2 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)2 SSHKeyPair (com.cloud.legacymodel.user.SSHKeyPair)2 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)2