use of io.apiman.manager.api.beans.clients.NewClientVersionBean in project apiman by apiman.
the class OrganizationResourceImpl method createClient.
/**
* @see IOrganizationResource#createClient(java.lang.String, io.apiman.manager.api.beans.clients.NewClientBean)
*/
@Override
public ClientBean createClient(String organizationId, NewClientBean bean) throws OrganizationNotFoundException, ClientAlreadyExistsException, NotAuthorizedException, InvalidNameException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
FieldValidator.validateName(bean.getName());
ClientBean newClient = new ClientBean();
newClient.setId(BeanUtils.idFromName(bean.getName()));
newClient.setName(bean.getName());
newClient.setDescription(bean.getDescription());
newClient.setCreatedBy(securityContext.getCurrentUser());
newClient.setCreatedOn(new Date());
try {
// Store/persist the new client
storage.beginTx();
OrganizationBean org = getOrganizationFromStorage(organizationId);
newClient.setOrganization(org);
if (storage.getClient(org.getId(), newClient.getId()) != null) {
throw ExceptionFactory.clientAlreadyExistsException(bean.getName());
}
storage.createClient(newClient);
storage.createAuditEntry(AuditUtils.clientCreated(newClient, securityContext));
if (bean.getInitialVersion() != null) {
NewClientVersionBean newClientVersion = new NewClientVersionBean();
newClientVersion.setVersion(bean.getInitialVersion());
createClientVersionInternal(newClientVersion, newClient);
}
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created client %s: %s", newClient.getName(), newClient));
return newClient;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.clients.NewClientVersionBean 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.beans.clients.NewClientVersionBean in project apiman by apiman.
the class OrganizationResourceImpl method createClientVersionInternal.
/**
* Creates a new client version.
* @param bean
* @param client
* @throws StorageException
*/
protected ClientVersionBean createClientVersionInternal(NewClientVersionBean bean, ClientBean client) throws StorageException {
if (!BeanUtils.isValidVersion(bean.getVersion())) {
// $NON-NLS-1$
throw new StorageException("Invalid/illegal client version: " + bean.getVersion());
}
ClientVersionBean newVersion = new ClientVersionBean();
newVersion.setClient(client);
newVersion.setCreatedBy(securityContext.getCurrentUser());
newVersion.setCreatedOn(new Date());
newVersion.setModifiedBy(securityContext.getCurrentUser());
newVersion.setModifiedOn(new Date());
newVersion.setStatus(ClientStatus.Created);
newVersion.setVersion(bean.getVersion());
newVersion.setApikey(bean.getApiKey());
if (newVersion.getApikey() == null) {
newVersion.setApikey(apiKeyGenerator.generate());
}
storage.createClientVersion(newVersion);
storage.createAuditEntry(AuditUtils.clientVersionCreated(newVersion, securityContext));
// $NON-NLS-1$
log.debug(String.format("Created new client version %s: %s", newVersion.getClient().getName(), newVersion));
return newVersion;
}
use of io.apiman.manager.api.beans.clients.NewClientVersionBean in project apiman by apiman.
the class ClientAppService method createClientVersionInternal.
/**
* Creates a new client version.
* @param bean
* @param client
* @throws StorageException
*/
protected ClientVersionBean createClientVersionInternal(NewClientVersionBean bean, ClientBean client) throws StorageException {
if (!BeanUtils.isValidVersion(bean.getVersion())) {
// $NON-NLS-1$
throw new StorageException("Invalid/illegal client version: " + bean.getVersion());
}
ClientVersionBean newVersion = new ClientVersionBean();
newVersion.setClient(client);
newVersion.setCreatedBy(securityContext.getCurrentUser());
newVersion.setCreatedOn(new Date());
newVersion.setModifiedBy(securityContext.getCurrentUser());
newVersion.setModifiedOn(new Date());
newVersion.setStatus(ClientStatus.Created);
newVersion.setVersion(bean.getVersion());
newVersion.setApikey(bean.getApiKey());
if (newVersion.getApikey() == null) {
newVersion.setApikey(apiKeyGenerator.generate());
}
storage.createClientVersion(newVersion);
storage.createAuditEntry(AuditUtils.clientVersionCreated(newVersion, securityContext));
// $NON-NLS-1$
LOGGER.debug("Created new client version {0}: {1}", newVersion.getClient().getName(), newVersion);
return newVersion;
}
use of io.apiman.manager.api.beans.clients.NewClientVersionBean 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