use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.
the class EsMarshalling method unmarshallPlanVersionSummary.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the plan version summary
*/
public static PlanVersionSummaryBean unmarshallPlanVersionSummary(Map<String, Object> source) {
if (source == null) {
return null;
}
PlanVersionSummaryBean bean = new PlanVersionSummaryBean();
bean.setDescription(asString(source.get("planDescription")));
bean.setId(asString(source.get("planId")));
bean.setName(asString(source.get("planName")));
bean.setOrganizationId(asString(source.get("organizationId")));
bean.setOrganizationName(asString(source.get("organizationName")));
bean.setStatus(asEnum(source.get("status"), PlanStatus.class));
bean.setVersion(asString(source.get("version")));
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean 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.summary.PlanVersionSummaryBean in project apiman by apiman.
the class PlanService method deletePlan.
public void deletePlan(String organizationId, String planId) throws ApiNotFoundException, NotAuthorizedException, InvalidPlanStatusException {
List<PlanVersionSummaryBean> lockedPlans = listPlanVersions(organizationId, planId).stream().filter(summary -> summary.getStatus() == PlanStatus.Locked).collect(toList());
if (!lockedPlans.isEmpty())
throw ExceptionFactory.invalidPlanStatusException(lockedPlans);
tryAction(() -> {
PlanBean plan = storage.getPlan(organizationId, planId);
storage.deletePlan(plan);
});
}
use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.
the class JpaStorage method getPlanVersions.
/**
* {@inheritDoc}
*/
@Override
public List<PlanVersionSummaryBean> getPlanVersions(String orgId, String planId) throws StorageException {
try {
EntityManager entityManager = getActiveEntityManager();
String jpql = "SELECT v from PlanVersionBean v" + " JOIN v.plan p" + " JOIN p.organization o" + " WHERE o.id = :orgId" + " AND p.id = :planId" + " ORDER BY v.createdOn DESC";
TypedQuery<PlanVersionBean> query = entityManager.createQuery(jpql, PlanVersionBean.class).setMaxResults(500).setParameter("orgId", orgId).setParameter("planId", planId);
List<PlanVersionBean> planVersions = query.getResultList();
List<PlanVersionSummaryBean> rval = new ArrayList<>(planVersions.size());
for (PlanVersionBean planVersion : planVersions) {
PlanVersionSummaryBean pvsb = new PlanVersionSummaryBean();
pvsb.setOrganizationId(planVersion.getPlan().getOrganization().getId());
pvsb.setOrganizationName(planVersion.getPlan().getOrganization().getName());
pvsb.setId(planVersion.getPlan().getId());
pvsb.setName(planVersion.getPlan().getName());
pvsb.setDescription(planVersion.getPlan().getDescription());
pvsb.setVersion(planVersion.getVersion());
pvsb.setStatus(planVersion.getStatus());
rval.add(pvsb);
}
return rval;
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
throw new StorageException(t);
}
}
use of io.apiman.manager.api.beans.summary.PlanVersionSummaryBean in project apiman by apiman.
the class EsStorage method getPlanVersions.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getPlanVersions(java.lang.String, java.lang.String)
*/
@Override
public List<PlanVersionSummaryBean> getPlanVersions(String organizationId, String planId) throws StorageException {
@SuppressWarnings("nls") BoolQueryBuilder query = QueryBuilders.boolQuery();
List<QueryBuilder> filter = query.filter();
filter.add(QueryBuilders.termQuery("organizationId", organizationId));
filter.add(QueryBuilders.termQuery("planId", planId));
@SuppressWarnings("nls") SearchSourceBuilder builder = new SearchSourceBuilder().sort(// $NON-NLS-1$
new FieldSortBuilder("createdOn").order(SortOrder.DESC)).query(query).size(500);
// $NON-NLS-1$
List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_PLAN_VERSION, builder);
List<PlanVersionSummaryBean> rval = new ArrayList<>(hits.size());
for (SearchHit hit : hits) {
PlanVersionSummaryBean bean = EsMarshalling.unmarshallPlanVersionSummary(hit.getSourceAsMap());
rval.add(bean);
}
return rval;
}
Aggregations