use of io.apiman.manager.api.beans.plans.PlanBean in project apiman by apiman.
the class JpaStorage method findPlans.
/**
* @see io.apiman.manager.api.core.IStorageQuery#findPlans(java.lang.String, io.apiman.manager.api.beans.search.SearchCriteriaBean)
*/
@Override
public SearchResultsBean<PlanSummaryBean> findPlans(String organizationId, SearchCriteriaBean criteria) throws StorageException {
criteria.addFilter("organization.id", organizationId, SearchCriteriaFilterOperator.eq);
SearchResultsBean<PlanBean> result = find(criteria, PlanBean.class);
SearchResultsBean<PlanSummaryBean> rval = new SearchResultsBean<>();
rval.setTotalSize(result.getTotalSize());
List<PlanBean> plans = result.getBeans();
rval.setBeans(new ArrayList<>(plans.size()));
for (PlanBean plan : plans) {
PlanSummaryBean summary = new PlanSummaryBean();
OrganizationBean organization = plan.getOrganization();
summary.setId(plan.getId());
summary.setName(plan.getName());
summary.setDescription(plan.getDescription());
summary.setOrganizationId(plan.getOrganization().getId());
summary.setOrganizationName(organization.getName());
rval.getBeans().add(summary);
}
return rval;
}
use of io.apiman.manager.api.beans.plans.PlanBean in project apiman by apiman.
the class EsStorage method getPlan.
/**
* @see io.apiman.manager.api.core.IStorage#getPlan(java.lang.String, java.lang.String)
*/
@Override
public PlanBean getPlan(String organizationId, String id) throws StorageException {
Map<String, Object> source = getEntity(INDEX_MANAGER_POSTFIX_PLAN, id(organizationId, id));
if (source == null) {
return null;
}
PlanBean bean = EsMarshalling.unmarshallPlan(source);
bean.setOrganization(getOrganization(organizationId));
return bean;
}
use of io.apiman.manager.api.beans.plans.PlanBean in project apiman by apiman.
the class EsMarshallingTest method testMarshallPlanBean.
/**
* Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.beans.plans.PlanBean)}.
*/
@Test
public void testMarshallPlanBean() throws Exception {
PlanBean bean = createBean(PlanBean.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.plans.PlanBean in project apiman by apiman.
the class OrganizationResourceImpl method deletePlan.
@Override
public void deletePlan(@PathParam("organizationId") String organizationId, @PathParam("planId") String planId) throws ApiNotFoundException, NotAuthorizedException, InvalidPlanStatusException {
securityContext.checkPermissions(PermissionType.planAdmin, organizationId);
List<PlanVersionSummaryBean> lockedPlans = listPlanVersions(organizationId, planId).stream().filter(summary -> summary.getStatus() == PlanStatus.Locked).collect(toList());
if (!lockedPlans.isEmpty())
throw ExceptionFactory.invalidPlanStatusException(lockedPlans);
try {
storage.beginTx();
PlanBean plan = storage.getPlan(organizationId, planId);
storage.deletePlan(plan);
storage.commitTx();
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.plans.PlanBean 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