use of io.apiman.manager.api.rest.exceptions.ClientNotFoundException 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);
}
}
}
use of io.apiman.manager.api.rest.exceptions.ClientNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method getClient.
/**
* @see IOrganizationResource#getClient(java.lang.String, java.lang.String)
*/
@Override
public ClientBean getClient(String organizationId, String clientId) throws ClientNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.clientView, organizationId);
try {
storage.beginTx();
ClientBean clientBean = getClientFromStorage(organizationId, clientId);
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Got client %s: %s", clientBean.getName(), clientBean));
return clientBean;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.rest.exceptions.ClientNotFoundException 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.ClientNotFoundException in project apiman by apiman.
the class OrganizationResourceImpl method createClientVersion.
/**
* @see IOrganizationResource#createClientVersion(java.lang.String, java.lang.String, io.apiman.manager.api.beans.clients.NewClientVersionBean)
*/
@Override
public ClientVersionBean createClientVersion(String organizationId, String clientId, NewClientVersionBean bean) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException, ClientVersionAlreadyExistsException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
FieldValidator.validateVersion(bean.getVersion());
ClientVersionBean newVersion;
try {
storage.beginTx();
ClientBean client = getClientFromStorage(organizationId, clientId);
if (storage.getClientVersion(organizationId, clientId, bean.getVersion()) != null) {
throw ExceptionFactory.clientVersionAlreadyExistsException(clientId, bean.getVersion());
}
newVersion = createClientVersionInternal(bean, client);
storage.commitTx();
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
if (bean.isClone() && bean.getCloneVersion() != null) {
try {
List<ContractSummaryBean> contracts = getClientVersionContracts(organizationId, clientId, bean.getCloneVersion());
for (ContractSummaryBean contract : contracts) {
NewContractBean ncb = new NewContractBean();
ncb.setPlanId(contract.getPlanId());
ncb.setApiId(contract.getApiId());
ncb.setApiOrgId(contract.getApiOrganizationId());
ncb.setApiVersion(contract.getApiVersion());
createContract(organizationId, clientId, newVersion.getVersion(), ncb);
}
List<PolicySummaryBean> policies = listClientPolicies(organizationId, clientId, bean.getCloneVersion());
for (PolicySummaryBean policySummary : policies) {
PolicyBean policy = getClientPolicy(organizationId, clientId, bean.getCloneVersion(), policySummary.getId());
NewPolicyBean npb = new NewPolicyBean();
npb.setDefinitionId(policy.getDefinition().getId());
npb.setConfiguration(policy.getConfiguration());
createClientPolicy(organizationId, clientId, newVersion.getVersion(), npb);
}
} catch (Exception e) {
// TODO it's ok if the clone fails - we did our best
}
}
return newVersion;
}
use of io.apiman.manager.api.rest.exceptions.ClientNotFoundException 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);
}
}
Aggregations