Search in sources :

Example 1 with PolicyDefinitionSummaryBean

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;
}
Also used : PolicyFormType(io.apiman.manager.api.beans.summary.PolicyFormType) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean)

Example 2 with PolicyDefinitionSummaryBean

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;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 3 with PolicyDefinitionSummaryBean

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);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) NewPluginBean(io.apiman.manager.api.beans.plugins.NewPluginBean) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) PluginNotFoundException(io.apiman.manager.api.rest.exceptions.PluginNotFoundException) PluginResourceNotFoundException(io.apiman.manager.api.rest.exceptions.PluginResourceNotFoundException) InvalidPluginException(io.apiman.manager.api.core.exceptions.InvalidPluginException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) IOException(java.io.IOException) PluginAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PluginAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)

Example 4 with PolicyDefinitionSummaryBean

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;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Aggregations

PolicyDefinitionSummaryBean (io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean)4 ArrayList (java.util.ArrayList)2 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 TermsQueryBuilder (org.elasticsearch.index.query.TermsQueryBuilder)2 SearchHit (org.elasticsearch.search.SearchHit)2 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)2 FieldSortBuilder (org.elasticsearch.search.sort.FieldSortBuilder)2 NewPluginBean (io.apiman.manager.api.beans.plugins.NewPluginBean)1 PluginBean (io.apiman.manager.api.beans.plugins.PluginBean)1 PolicyDefinitionBean (io.apiman.manager.api.beans.policies.PolicyDefinitionBean)1 PolicyFormType (io.apiman.manager.api.beans.summary.PolicyFormType)1 InvalidPluginException (io.apiman.manager.api.core.exceptions.InvalidPluginException)1 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)1 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)1 PluginAlreadyExistsException (io.apiman.manager.api.rest.exceptions.PluginAlreadyExistsException)1 PluginNotFoundException (io.apiman.manager.api.rest.exceptions.PluginNotFoundException)1 PluginResourceNotFoundException (io.apiman.manager.api.rest.exceptions.PluginResourceNotFoundException)1 PolicyDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)1