use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class EsMarshalling method marshall.
/**
* Marshals the given bean into the given map.
* @param bean the bean
* @return the content builder
* @throws StorageException when a storage problem occurs while storing a bean
*/
public static XContentBuilder marshall(ClientVersionBean bean) throws StorageException {
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
ClientBean client = bean.getClient();
OrganizationBean org = client.getOrganization();
preMarshall(bean);
builder.startObject().field("organizationId", org.getId()).field("organizationName", org.getName()).field("clientId", client.getId()).field("clientName", client.getName()).field("clientDescription", client.getDescription()).field("version", bean.getVersion()).field("apikey", bean.getApikey()).field("status", bean.getStatus()).field("createdBy", bean.getCreatedBy()).field("createdOn", bean.getCreatedOn().getTime()).field("modifiedBy", bean.getModifiedBy()).field("modifiedOn", bean.getModifiedOn().getTime()).field("publishedOn", bean.getPublishedOn() != null ? bean.getPublishedOn().getTime() : null).field("retiredOn", bean.getRetiredOn() != null ? bean.getRetiredOn().getTime() : null).endObject();
postMarshall(bean);
return builder;
} catch (IOException e) {
throw new StorageException(e);
}
}
use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class EsMarshallingTest method testMarshallClientBean.
/**
* Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.beans.clients.ClientBean)}.
*/
@Test
public void testMarshallClientBean() throws Exception {
ClientBean bean = createBean(ClientBean.class);
XContentBuilder builder = EsMarshalling.marshall(bean);
Assert.assertEquals("{\"organizationId\":\"ID\",\"organizationName\":\"NAME\",\"id\":\"ID\",\"name\":\"NAME\",\"description\":\"DESCRIPTION\",\"createdBy\":\"CREATEDBY\",\"createdOn\":1}", Strings.toString(builder));
}
use of io.apiman.manager.api.beans.clients.ClientBean in project apiman by apiman.
the class OrganizationResourceImpl method deleteClient.
/**
* @see IOrganizationResource#deleteClient(java.lang.String, java.lang.String)
*/
@Override
public void deleteClient(@PathParam("organizationId") String organizationId, @PathParam("clientId") String clientId) throws OrganizationNotFoundException, NotAuthorizedException, EntityStillActiveException {
securityContext.checkPermissions(PermissionType.clientAdmin, organizationId);
try {
storage.beginTx();
ClientBean client = getClientFromStorage(organizationId, clientId);
Iterator<ClientVersionBean> clientVersions = storage.getAllClientVersions(organizationId, clientId);
Iterable<ClientVersionBean> iterable = () -> clientVersions;
List<ClientVersionBean> registeredElems = StreamSupport.stream(iterable.spliterator(), false).filter(clientVersion -> clientVersion.getStatus() == ClientStatus.Registered).limit(5).collect(toList());
if (!registeredElems.isEmpty()) {
throw ExceptionFactory.entityStillActiveExceptionClientVersions(registeredElems);
}
storage.deleteClient(client);
storage.commitTx();
// $NON-NLS-1$
log.debug("Deleted ClientApp: " + client.getName());
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.clients.ClientBean 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.beans.clients.ClientBean 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;
}
Aggregations