use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.
the class EsMarshalling method unmarshallOrganization.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the organization
*/
public static OrganizationBean unmarshallOrganization(Map<String, Object> source) {
if (source == null) {
return null;
}
OrganizationBean bean = new OrganizationBean();
bean.setId(asString(source.get("id")));
bean.setName(asString(source.get("name")));
bean.setDescription(asString(source.get("description")));
bean.setCreatedOn(asDate(source.get("createdOn")));
bean.setCreatedBy(asString(source.get("createdBy")));
bean.setModifiedOn(asDate(source.get("modifiedOn")));
bean.setModifiedBy(asString(source.get("modifiedBy")));
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.beans.orgs.OrganizationBean 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.orgs.OrganizationBean in project apiman by apiman.
the class EsMarshallingTest method testMarshallOrganizationBean.
/**
* Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.beans.orgs.OrganizationBean)}.
*/
@Test
public void testMarshallOrganizationBean() throws Exception {
OrganizationBean bean = createBean(OrganizationBean.class);
XContentBuilder builder = EsMarshalling.marshall(bean);
Assert.assertEquals("{\"id\":\"ID\",\"name\":\"NAME\",\"description\":\"DESCRIPTION\",\"createdBy\":\"CREATEDBY\",\"createdOn\":1,\"modifiedBy\":\"MODIFIEDBY\",\"modifiedOn\":1}", Strings.toString(builder));
}
use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.
the class OrganizationResourceImpl method update.
/**
* @see IOrganizationResource#update(java.lang.String, io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)
*/
@Override
public void update(String organizationId, UpdateOrganizationBean bean) throws OrganizationNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.orgEdit, organizationId);
try {
storage.beginTx();
OrganizationBean orgForUpdate = getOrganizationFromStorage(organizationId);
EntityUpdatedData auditData = new EntityUpdatedData();
if (AuditUtils.valueChanged(orgForUpdate.getDescription(), bean.getDescription())) {
// $NON-NLS-1$
auditData.addChange("description", orgForUpdate.getDescription(), bean.getDescription());
orgForUpdate.setDescription(bean.getDescription());
}
storage.updateOrganization(orgForUpdate);
storage.createAuditEntry(AuditUtils.organizationUpdated(orgForUpdate, auditData, securityContext));
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Updated organization %s: %s", orgForUpdate.getName(), orgForUpdate));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.
the class OrganizationResourceImpl method createPlan.
/**
* @see IOrganizationResource#createPlan(java.lang.String,
* io.apiman.manager.api.beans.plans.NewPlanBean)
*/
@Override
public PlanBean createPlan(String organizationId, NewPlanBean bean) throws OrganizationNotFoundException, PlanAlreadyExistsException, NotAuthorizedException, InvalidNameException {
securityContext.checkPermissions(PermissionType.planEdit, organizationId);
FieldValidator.validateName(bean.getName());
PlanBean newPlan = new PlanBean();
newPlan.setName(bean.getName());
newPlan.setDescription(bean.getDescription());
newPlan.setId(BeanUtils.idFromName(bean.getName()));
newPlan.setCreatedOn(new Date());
newPlan.setCreatedBy(securityContext.getCurrentUser());
try {
// Store/persist the new plan
storage.beginTx();
OrganizationBean orgBean = getOrganizationFromStorage(organizationId);
if (storage.getPlan(orgBean.getId(), newPlan.getId()) != null) {
throw ExceptionFactory.planAlreadyExistsException(newPlan.getName());
}
newPlan.setOrganization(orgBean);
storage.createPlan(newPlan);
storage.createAuditEntry(AuditUtils.planCreated(newPlan, securityContext));
if (bean.getInitialVersion() != null) {
NewPlanVersionBean newPlanVersion = new NewPlanVersionBean();
newPlanVersion.setVersion(bean.getInitialVersion());
createPlanVersionInternal(newPlanVersion, newPlan);
}
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Created plan: %s", newPlan));
return newPlan;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations