use of io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean in project apiman by apiman.
the class EsMarshalling method unmarshallPolicyDefinitionSummary.
/**
* Unmarshals the given map source into a bean.
* @param map the search map
* @return the policy definition summary
*/
public static PolicyDefinitionSummaryBean unmarshallPolicyDefinitionSummary(Map<String, Object> map) {
PolicyDefinitionSummaryBean bean = new PolicyDefinitionSummaryBean();
bean.setId(asString(map.get("id")));
bean.setName(asString(map.get("name")));
if (map.containsKey("description")) {
bean.setDescription(asString(map.get("description")));
}
bean.setPolicyImpl(asString(map.get("policyImpl")));
if (map.containsKey("icon")) {
bean.setIcon(asString(map.get("icon")));
}
if (map.containsKey("pluginId")) {
bean.setPluginId(asLong(map.get("pluginId")));
}
if (map.containsKey("formType")) {
bean.setFormType(asEnum(map.get("formType"), PolicyFormType.class));
}
postMarshall(bean);
return bean;
}
use of io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean in project apiman by apiman.
the class EsStorage method listPluginPolicyDefs.
/**
* @see io.apiman.manager.api.core.IStorageQuery#listPluginPolicyDefs(java.lang.Long)
*/
@Override
public List<PolicyDefinitionSummaryBean> listPluginPolicyDefs(Long pluginId) throws StorageException {
@SuppressWarnings("nls") QueryBuilder qb = QueryBuilders.termQuery("pluginId", pluginId);
@SuppressWarnings("nls") String[] fields = { "id", "policyImpl", "name", "description", "icon", "pluginId", "formType" };
SearchSourceBuilder builder = new SearchSourceBuilder().fetchSource(fields, null).query(qb).sort(new FieldSortBuilder("name.keyword").order(SortOrder.ASC)).size(// $NON-NLS-1$
100);
// $NON-NLS-1$
List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_POLICY_DEF, builder);
List<PolicyDefinitionSummaryBean> rval = new ArrayList<>(hits.size());
for (SearchHit hit : hits) {
PolicyDefinitionSummaryBean bean = EsMarshalling.unmarshallPolicyDefinitionSummary(hit.getSourceAsMap());
rval.add(bean);
}
return rval;
}
use of io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean in project apiman by apiman.
the class PluginResourceImpl method delete.
/**
* @see IPluginResource#delete(java.lang.Long)
*/
@Override
public void delete(Long pluginId) throws PluginNotFoundException, NotAuthorizedException {
securityContext.checkAdminPermissions();
try {
List<PolicyDefinitionSummaryBean> policyDefs = query.listPluginPolicyDefs(pluginId);
PluginBean pbean = storage.getPlugin(pluginId);
if (pbean == null) {
throw ExceptionFactory.pluginNotFoundException(pluginId);
}
pbean.setDeleted(true);
storage.updatePlugin(pbean);
// Now delete all the policy definitions for this plugin.
for (PolicyDefinitionSummaryBean policyDef : policyDefs) {
PolicyDefinitionBean definition = storage.getPolicyDefinition(policyDef.getId());
if (definition != null) {
definition.setDeleted(true);
storage.updatePolicyDefinition(definition);
}
}
LOGGER.info(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"Deleted plugin mvn:%s:%s:%s", // $NON-NLS-1$
pbean.getGroupId(), // $NON-NLS-1$
pbean.getArtifactId(), pbean.getVersion()));
} catch (AbstractRestException e) {
throw e;
} catch (Exception e) {
throw new SystemErrorException(e);
}
}
use of io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean in project apiman by apiman.
the class EsStorage method listPolicyDefinitions.
/**
* @see io.apiman.manager.api.core.IStorageQuery#listPolicyDefinitions()
*/
@Override
@SuppressWarnings("nls")
public List<PolicyDefinitionSummaryBean> listPolicyDefinitions() throws StorageException {
String[] fields = { "id", "policyImpl", "name", "description", "icon", "pluginId", "formType" };
QueryBuilder query = QueryBuilders.boolQuery().filter(QueryBuilders.termQuery("deleted", false));
SearchSourceBuilder builder = new SearchSourceBuilder().fetchSource(fields, null).query(query).sort(// $NON-NLS-1$
new FieldSortBuilder("name.keyword").order(SortOrder.ASC)).size(100);
// $NON-NLS-1$
List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_POLICY_DEF, builder);
List<PolicyDefinitionSummaryBean> rval = new ArrayList<>(hits.size());
for (SearchHit hit : hits) {
PolicyDefinitionSummaryBean bean = EsMarshalling.unmarshallPolicyDefinitionSummary(hit.getSourceAsMap());
rval.add(bean);
}
return rval;
}
Aggregations