use of io.apiman.manager.api.beans.summary.ClientSummaryBean in project apiman by apiman.
the class EsMarshalling method unmarshallClientSummary.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the client summary
*/
public static ClientSummaryBean unmarshallClientSummary(Map<String, Object> source) {
if (source == null) {
return null;
}
ClientSummaryBean bean = new ClientSummaryBean();
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.ClientSummaryBean in project apiman by apiman.
the class EsStorage method getClientsInOrgs.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getClientsInOrgs(java.util.Set)
*/
@Override
public List<ClientSummaryBean> getClientsInOrgs(Set<String> organizationIds) throws StorageException {
@SuppressWarnings("nls") SearchSourceBuilder builder = new SearchSourceBuilder().sort("organizationName.keyword", SortOrder.ASC).sort("name.keyword", 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_CLIENT, builder);
List<ClientSummaryBean> rval = new ArrayList<>(hits.size());
for (SearchHit hit : hits) {
ClientSummaryBean bean = EsMarshalling.unmarshallClientSummary(hit.getSourceAsMap());
rval.add(bean);
}
return rval;
}
use of io.apiman.manager.api.beans.summary.ClientSummaryBean 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