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: {
                        throw new RuntimeException("Missing case for switch!"); //$NON-NLS-1$
                    }
                }

                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(
                    Messages.i18n.format("ErrorAggregatingPolicies", e)); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }
Check to see if the contract already exists, by getting a list of all the
client's contracts and comparing with the one being created.
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ContractService.java