use of io.apiman.manager.api.rest.exceptions.ContractNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method deleteContract.
/**
* @see IOrganizationResource#deleteContract(java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
*/
@Override
public void deleteContract(String organizationId, String clientId, String version, Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException, InvalidClientStatusException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
try {
storage.beginTx();
ContractBean contract = storage.getContract(contractId);
if (contract == null) {
throw ExceptionFactory.contractNotFoundException(contractId);
}
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(version)) {
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 = getClientVersionFromStorage(organizationId, clientId, version);
clientV.setModifiedBy(securityContext.getCurrentUser());
clientV.setModifiedOn(new Date());
storage.updateClientVersion(clientV);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Deleted contract: %s", contract));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.ContractNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method getContract.
/**
* @see IOrganizationResource#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
*/
@Override
public ContractBean getContract(String organizationId, String clientId, String version, Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.clientView, organizationId);
try {
storage.beginTx();
ContractBean contract = storage.getContract(contractId);
if (contract == null)
throw ExceptionFactory.contractNotFoundException(contractId);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Got contract %s: %s", contract.getId(), contract));
return contract;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.ContractNotFoundException in project apiman by apiman.
the class ContractService method deleteContract.
@Transactional
public void deleteContract(String organizationId, String clientId, String version, Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException, InvalidClientStatusException {
try {
ArrayList<ContractBean> allContracts = Lists.newArrayList(tryAction(() -> storage.getAllContracts(organizationId, clientId, version)));
ContractBean contractToDelete = storage.getContract(contractId);
deleteContractsInternal(organizationId, clientId, version, allContracts, List.of(contractToDelete));
} catch (Exception e) {
throw new SystemErrorException(e);
}
}
Aggregations