private ClientStatus deleteContractsInternal(String organizationId, String clientId, String clientVersion, List<ContractBean> allContracts, List<ContractBean> contractsToDelete)
            throws Exception {
        Preconditions.checkArgument(allContracts.size() > 0, "Must have at least 1 contract if you want to delete");
        Preconditions.checkArgument(contractsToDelete.size() > 0, "Must nominate at least 1 contract to delete");
        for (ContractBean contract : contractsToDelete) {
            Long contractId = contract.getId();
            if (!contract.getClient().getClient().getOrganization().getId().equals(organizationId)) {
                throw ExceptionFactory.contractNotFoundException(contractId);
            }
            if (!contract.getClient().getClient().getId().equals(clientId)) {
                throw ExceptionFactory.contractNotFoundException(contractId);
            }
            if (!contract.getClient().getVersion().equals(clientVersion)) {
                throw ExceptionFactory.contractNotFoundException(contractId);
            }
            // if (contract.getClient().getStatus() == ClientStatus.Retired) {
            //     throw ExceptionFactory.invalidClientStatusException();
            // }
            storage.deleteContract(contract);
            storage.createAuditEntry(AuditUtils.contractBrokenFromClient(contract, securityContext));
            storage.createAuditEntry(AuditUtils.contractBrokenToApi(contract, securityContext));
        }

        // Update the version with new meta-data (e.g. modified-by)
        ClientVersionBean clientV = clientAppService.getClientVersion(organizationId, clientId, clientVersion);
        clientV.setModifiedBy(securityContext.getCurrentUser());
        clientV.setModifiedOn(new Date());

        ClientStatus newStatus = clientValidator.determineStatus(clientV, allContracts);
        LOGGER.debug("New status for client version {0} is: {1}", clientV, newStatus);
        clientV.setStatus(newStatus);
        storage.updateClientVersion(clientV);
        LOGGER.debug("Deleted contract(s): {0}", contractsToDelete); //$NON-NLS-1$
        return newStatus;
    }
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