use of io.apiman.manager.api.beans.summary.PlanSummaryBean in project apiman by apiman.
the class EsMarshalling method unmarshallPlanSummary.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the plan summary
*/
public static PlanSummaryBean unmarshallPlanSummary(Map<String, Object> source) {
if (source == null) {
return null;
}
PlanSummaryBean bean = new PlanSummaryBean();
bean.setOrganizationId(asString(source.get("organizationId")));
bean.setOrganizationName(asString(source.get("organizationName")));
bean.setId(asString(source.get("id")));
bean.setName(asString(source.get("name")));
bean.setDescription(asString(source.get("description")));
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.beans.summary.PlanSummaryBean in project apiman by apiman.
the class JpaStorage method findPlans.
/**
* {@inheritDoc}
*/
@Override
public SearchResultsBean<PlanSummaryBean> findPlans(String organizationId, SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
Consumer<CriteriaBuilder<PlanBean>> constraintFunc = builder -> {
};
if (permissionConstraint.isConstrained()) {
constraintFunc = builder -> builder.whereOr().where("plan.organization.id").in(permissionConstraint.getPermittedOrgs()).where("plan.id").in().from(DiscoverabilityEntity.class, "d").select("d.planId").where("d.orgId").eq(organizationId).where("d.planId").isNotNull().where("d.discoverability").in(permissionConstraint.getAllowedDiscoverabilities()).end().endOr();
}
SearchResultsBean<PlanBean> result = find(criteria, List.of(new OrderByBean(true, PlanBean_.ID), new OrderByBean(true, "organization.id")), constraintFunc, PlanBean.class, "plan", true);
// TODO(msavy): replace with projection or mapping
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.summary.PlanSummaryBean in project apiman by apiman.
the class JpaStorage method getPlansInOrgs.
/**
* {@inheritDoc}
*/
@Override
public List<PlanSummaryBean> getPlansInOrgs(Set<String> orgIds) throws StorageException {
List<PlanSummaryBean> rval = new ArrayList<>();
if (orgIds == null || orgIds.isEmpty()) {
return rval;
}
try {
EntityManager entityManager = getActiveEntityManager();
String jpql = "SELECT p FROM PlanBean p JOIN p.organization o WHERE o.id IN :orgs ORDER BY p.id ASC";
TypedQuery<PlanBean> query = entityManager.createQuery(jpql, PlanBean.class).setParameter("orgs", orgIds).setMaxResults(500);
List<PlanBean> qr = query.getResultList();
for (PlanBean bean : qr) {
PlanSummaryBean summary = new PlanSummaryBean();
summary.setId(bean.getId());
summary.setName(bean.getName());
summary.setDescription(bean.getDescription());
OrganizationBean org = bean.getOrganization();
summary.setOrganizationId(org.getId());
summary.setOrganizationName(org.getName());
rval.add(summary);
}
return rval;
} catch (Throwable t) {
LOGGER.error(t.getMessage(), t);
throw new StorageException(t);
}
}
use of io.apiman.manager.api.beans.summary.PlanSummaryBean in project apiman by apiman.
the class EsStorage method getPlansInOrgs.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getPlansInOrgs(java.util.Set)
*/
@Override
public List<PlanSummaryBean> getPlansInOrgs(Set<String> organizationIds) throws StorageException {
@SuppressWarnings("nls") SearchSourceBuilder builder = new SearchSourceBuilder().sort(new FieldSortBuilder("organizationName.keyword").order(SortOrder.ASC)).sort(new FieldSortBuilder("name.keyword").order(SortOrder.ASC)).size(500);
// $NON-NLS-1$
TermsQueryBuilder query = QueryBuilders.termsQuery("organizationId", organizationIds.toArray(new String[organizationIds.size()]));
builder.query(query);
List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_PLAN, builder);
List<PlanSummaryBean> rval = new ArrayList<>(hits.size());
for (SearchHit hit : hits) {
PlanSummaryBean bean = EsMarshalling.unmarshallPlanSummary(hit.getSourceAsMap());
rval.add(bean);
}
return rval;
}
Aggregations