use of io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException in project apiman by apiman.
the class OrganizationResourceImpl method createContract.
/**
* @see IOrganizationResource#createContract(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.contracts.NewContractBean)
*/
@Override
public ContractBean createContract(String organizationId, String clientId, String version, NewContractBean bean) throws OrganizationNotFoundException, ClientNotFoundException, ApiNotFoundException, PlanNotFoundException, ContractAlreadyExistsException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
try {
storage.beginTx();
ContractBean contract = createContractInternal(organizationId, clientId, version, bean);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created new contract %s: %s", contract.getId(), contract));
return contract;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
// reduce overhead on the typical happy path.
if (contractAlreadyExists(organizationId, clientId, version, bean)) {
throw ExceptionFactory.contractAlreadyExistsException();
} else {
throw new SystemErrorException(e);
}
}
}
Aggregations