use of io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException 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.ClientVersionAlreadyExistsException in project apiman by apiman.
the class ClientAppService method createClientVersion.
public ClientVersionBean createClientVersion(String organizationId, String clientId, NewClientVersionBean bean) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException, ClientVersionAlreadyExistsException {
FieldValidator.validateVersion(bean.getVersion());
ClientVersionBean newVersion;
try {
ClientBean client = getClientFromStorage(organizationId, clientId);
if (storage.getClientVersion(organizationId, clientId, bean.getVersion()) != null) {
throw ExceptionFactory.clientVersionAlreadyExistsException(clientId, bean.getVersion());
}
newVersion = createClientVersionInternal(bean, client);
} catch (AbstractRestException e) {
throw e;
} catch (Exception e) {
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());
contractService.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;
}
Aggregations