Search in sources :

Example 1 with PolicyType

use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.

the class ContractService method aggregateContractPolicies.

/**
 * Aggregates the API, client, and plan policies into a single ordered list.
 */
public List<Policy> aggregateContractPolicies(ContractSummaryBean contractBean) {
    try {
        List<Policy> policies = new ArrayList<>();
        PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
        for (PolicyType policyType : types) {
            String org, id, ver;
            switch(policyType) {
                case Client:
                    {
                        org = contractBean.getClientOrganizationId();
                        id = contractBean.getClientId();
                        ver = contractBean.getClientVersion();
                        break;
                    }
                case Plan:
                    {
                        org = contractBean.getApiOrganizationId();
                        id = contractBean.getPlanId();
                        ver = contractBean.getPlanVersion();
                        break;
                    }
                case Api:
                    {
                        org = contractBean.getApiOrganizationId();
                        id = contractBean.getApiId();
                        ver = contractBean.getApiVersion();
                        break;
                    }
                default:
                    {
                        // $NON-NLS-1$
                        throw new RuntimeException("Missing case for switch!");
                    }
            }
            List<PolicySummaryBean> clientPolicies = query.getPolicies(org, id, ver, policyType);
            for (PolicySummaryBean policySummaryBean : clientPolicies) {
                PolicyBean policyBean = storage.getPolicy(policyType, org, id, ver, policySummaryBean.getId());
                Policy policy = new Policy();
                policy.setPolicyJsonConfig(policyBean.getConfiguration());
                policy.setPolicyImpl(policyBean.getDefinition().getPolicyImpl());
                policies.add(policy);
            }
        }
        return policies;
    } catch (Exception e) {
        throw ExceptionFactory.actionException(Messages.i18n.format("ErrorAggregatingPolicies", contractBean.getClientId() + "->" + contractBean.getApiDescription()), // $NON-NLS-1$ //$NON-NLS-2$
        e);
    }
}
Also used : Policy(io.apiman.gateway.engine.beans.Policy) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) ArrayList(java.util.ArrayList) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)

Example 2 with PolicyType

use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.

the class StorageImportDispatcher method aggregateContractPolicies.

/**
 * Aggregates the api, client, and plan policies into a single ordered list.
 * @param contractBean
 * @param clientInfo
 */
private List<Policy> aggregateContractPolicies(ContractBean contractBean, EntityInfo clientInfo) throws StorageException {
    List<Policy> policies = new ArrayList<>();
    PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
    for (PolicyType policyType : types) {
        String org, id, ver;
        switch(policyType) {
            case Client:
                {
                    org = clientInfo.organizationId;
                    id = clientInfo.id;
                    ver = clientInfo.version;
                    break;
                }
            case Plan:
                {
                    org = contractBean.getApi().getApi().getOrganization().getId();
                    id = contractBean.getPlan().getPlan().getId();
                    ver = contractBean.getPlan().getVersion();
                    break;
                }
            case Api:
                {
                    org = contractBean.getApi().getApi().getOrganization().getId();
                    id = contractBean.getApi().getApi().getId();
                    ver = contractBean.getApi().getVersion();
                    break;
                }
            default:
                {
                    // $NON-NLS-1$
                    throw new RuntimeException("Missing case for switch!");
                }
        }
        Iterator<PolicyBean> clientPolicies = storage.getAllPolicies(org, id, ver, policyType);
        while (clientPolicies.hasNext()) {
            PolicyBean policyBean = clientPolicies.next();
            Policy policy = new Policy();
            policy.setPolicyJsonConfig(policyBean.getConfiguration());
            policy.setPolicyImpl(policyBean.getDefinition().getPolicyImpl());
            policies.add(policy);
        }
    }
    return policies;
}
Also used : Policy(io.apiman.gateway.engine.beans.Policy) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) ArrayList(java.util.ArrayList)

Example 3 with PolicyType

use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.

the class ContractService method aggregateContractPolicies.

public List<PolicyBean> aggregateContractPolicies(ContractBean contractBean) {
    try {
        List<PolicyBean> policies = new ArrayList<>();
        PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
        for (PolicyType policyType : types) {
            String org, id, ver;
            switch(policyType) {
                case Client:
                    {
                        org = contractBean.getClient().getClient().getOrganization().getId();
                        id = contractBean.getClient().getClient().getId();
                        ver = contractBean.getClient().getVersion();
                        break;
                    }
                case Plan:
                    {
                        org = contractBean.getPlan().getPlan().getOrganization().getId();
                        id = contractBean.getPlan().getPlan().getId();
                        ver = contractBean.getPlan().getVersion();
                        break;
                    }
                case Api:
                    {
                        org = contractBean.getApi().getApi().getOrganization().getId();
                        id = contractBean.getApi().getApi().getId();
                        ver = contractBean.getApi().getVersion();
                        break;
                    }
                default:
                    {
                        // $NON-NLS-1$
                        throw new RuntimeException("Missing case for switch!");
                    }
            }
            List<PolicySummaryBean> clientPolicies = query.getPolicies(org, id, ver, policyType);
            for (PolicySummaryBean policySummaryBean : clientPolicies) {
                policies.add(storage.getPolicy(policyType, org, id, ver, policySummaryBean.getId()));
            }
        }
        return policies;
    } catch (Exception e) {
        throw ExceptionFactory.actionException(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.i18n.format("ErrorAggregatingPolicies", e));
    }
}
Also used : PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) ArrayList(java.util.ArrayList) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)

Example 4 with PolicyType

use of io.apiman.manager.api.beans.policies.PolicyType in project apiman by apiman.

the class ActionResourceImpl method aggregateContractPolicies.

/**
 * Aggregates the API, client, and plan policies into a single ordered list.
 * @param contractBean
 */
private List<Policy> aggregateContractPolicies(ContractSummaryBean contractBean) {
    try {
        List<Policy> policies = new ArrayList<>();
        PolicyType[] types = new PolicyType[] { PolicyType.Client, PolicyType.Plan, PolicyType.Api };
        for (PolicyType policyType : types) {
            String org, id, ver;
            switch(policyType) {
                case Client:
                    {
                        org = contractBean.getClientOrganizationId();
                        id = contractBean.getClientId();
                        ver = contractBean.getClientVersion();
                        break;
                    }
                case Plan:
                    {
                        org = contractBean.getApiOrganizationId();
                        id = contractBean.getPlanId();
                        ver = contractBean.getPlanVersion();
                        break;
                    }
                case Api:
                    {
                        org = contractBean.getApiOrganizationId();
                        id = contractBean.getApiId();
                        ver = contractBean.getApiVersion();
                        break;
                    }
                default:
                    {
                        // $NON-NLS-1$
                        throw new RuntimeException("Missing case for switch!");
                    }
            }
            List<PolicySummaryBean> clientPolicies = query.getPolicies(org, id, ver, policyType);
            try {
                storage.beginTx();
                for (PolicySummaryBean policySummaryBean : clientPolicies) {
                    PolicyBean policyBean = storage.getPolicy(policyType, org, id, ver, policySummaryBean.getId());
                    Policy policy = new Policy();
                    policy.setPolicyJsonConfig(policyBean.getConfiguration());
                    policy.setPolicyImpl(policyBean.getDefinition().getPolicyImpl());
                    policies.add(policy);
                }
            } finally {
                storage.rollbackTx();
            }
        }
        return policies;
    } catch (Exception e) {
        throw ExceptionFactory.actionException(Messages.i18n.format("ErrorAggregatingPolicies", contractBean.getClientId() + "->" + contractBean.getApiDescription()), // $NON-NLS-1$ //$NON-NLS-2$
        e);
    }
}
Also used : Policy(io.apiman.gateway.engine.beans.Policy) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) ArrayList(java.util.ArrayList) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) ActionException(io.apiman.manager.api.rest.exceptions.ActionException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)

Aggregations

PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)4 PolicyType (io.apiman.manager.api.beans.policies.PolicyType)4 ArrayList (java.util.ArrayList)4 Policy (io.apiman.gateway.engine.beans.Policy)3 PolicySummaryBean (io.apiman.manager.api.beans.summary.PolicySummaryBean)3 StorageException (io.apiman.manager.api.core.exceptions.StorageException)3 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)3 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)2 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)2 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)2 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)2 ContractAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)2 ContractNotFoundException (io.apiman.manager.api.rest.exceptions.ContractNotFoundException)2 InvalidClientStatusException (io.apiman.manager.api.rest.exceptions.InvalidClientStatusException)2 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)2 PlanNotFoundException (io.apiman.manager.api.rest.exceptions.PlanNotFoundException)2 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)2 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)1 ActionException (io.apiman.manager.api.rest.exceptions.ActionException)1 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)1