use of io.apiman.manager.api.beans.idm.PermissionConstraint in project apiman by apiman.
the class JpaStorage method findOrganizations.
/**
* {@inheritDoc}
*/
@Override
public SearchResultsBean<OrganizationSummaryBean> findOrganizations(SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
Consumer<CriteriaBuilder<OrganizationBean>> constraintFunc = builder -> {
};
if (permissionConstraint.isConstrained()) {
// With constraint, first allow the user's explicitly permitted orgs, plus orgs with discoverable APIs.
constraintFunc = (builder) -> builder.whereOr().where(OrganizationBean_.ID).in(permissionConstraint.getPermittedOrgs()).where("org.id").in().from(DiscoverabilityEntity.class, "d").select("d.orgId").where("d.discoverability").isNotNull().where("d.discoverability").in(permissionConstraint.getAllowedDiscoverabilities()).end().endOr();
}
SearchResultsBean<OrganizationBean> orgs = find(criteria, List.of(new OrderByBean(true, OrganizationBean_.ID)), constraintFunc, OrganizationBean.class, "org", true);
SearchResultsBean<OrganizationSummaryBean> rval = new SearchResultsBean<>();
rval.setTotalSize(orgs.getTotalSize());
List<OrganizationBean> beans = orgs.getBeans();
for (OrganizationBean bean : beans) {
OrganizationSummaryBean osb = new OrganizationSummaryBean();
osb.setId(bean.getId());
osb.setName(bean.getName());
osb.setDescription(bean.getDescription());
rval.getBeans().add(osb);
}
return rval;
}
use of io.apiman.manager.api.beans.idm.PermissionConstraint 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.idm.PermissionConstraint in project apiman by apiman.
the class JpaStorage method findClients.
/**
* {@inheritDoc}
*/
@Override
public SearchResultsBean<ClientSummaryBean> findClients(SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
// If unconstrained, do nothing.
Consumer<CriteriaBuilder<ClientBean>> constraintFunc = builder -> {
};
if (permissionConstraint.isConstrained()) {
constraintFunc = (builder) -> builder.where("organization.id").in(permissionConstraint.getPermittedOrgs());
}
SearchResultsBean<ClientBean> result = find(criteria, List.of(new OrderByBean(true, ClientBean_.ID), new OrderByBean(true, "organization.id")), constraintFunc, ClientBean.class, "client", true);
SearchResultsBean<ClientSummaryBean> rval = new SearchResultsBean<>();
rval.setTotalSize(result.getTotalSize());
List<ClientBean> beans = result.getBeans();
rval.setBeans(new ArrayList<>(beans.size()));
for (ClientBean client : beans) {
ClientSummaryBean summary = new ClientSummaryBean();
OrganizationBean organization = client.getOrganization();
summary.setId(client.getId());
summary.setName(client.getName());
summary.setDescription(client.getDescription());
summary.setImage(client.getImage());
// TODO find the number of contracts - probably need native SQL for that
summary.setNumContracts(0);
summary.setOrganizationId(client.getOrganization().getId());
summary.setOrganizationName(organization.getName());
rval.getBeans().add(summary);
}
return rval;
}
Aggregations