use of io.apiman.manager.api.rest.exceptions.InvalidClientStatusException 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.InvalidClientStatusException in project apiman by apiman.
the class OrganizationResourceImpl method updateClientApiKey.
/**
* @see IOrganizationResource#updateClientApiKey(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.clients.ApiKeyBean)
*/
@Override
public ApiKeyBean updateClientApiKey(String organizationId, String clientId, String version, ApiKeyBean bean) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException, InvalidClientStatusException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
try {
ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version);
if (clientVersion.getStatus() == ClientStatus.Registered) {
throw ExceptionFactory.invalidClientStatusException();
}
String newApiKey = bean.getApiKey();
if (StringUtils.isEmpty(newApiKey)) {
newApiKey = apiKeyGenerator.generate();
}
clientVersion.setApikey(newApiKey);
clientVersion.setModifiedBy(securityContext.getCurrentUser());
clientVersion.setModifiedOn(new Date());
storage.beginTx();
storage.updateClientVersion(clientVersion);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Updated an API Key for client %s version %s", clientVersion.getClient().getName(), clientVersion));
ApiKeyBean rval = new ApiKeyBean();
rval.setApiKey(newApiKey);
return rval;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.InvalidClientStatusException 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