Search in sources :

Example 1 with PoliciesBean

use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.

the class EsMarshalling method unmarshallPolicies.

/**
 * Unmarshals the given map source into a bean.
 * @param source the source
 * @return the policy beans
 */
@SuppressWarnings("unchecked")
public static PoliciesBean unmarshallPolicies(Map<String, Object> source) {
    if (source == null) {
        return null;
    }
    PoliciesBean bean = new PoliciesBean();
    bean.setOrganizationId(asString(source.get("organizationId")));
    bean.setEntityId(asString(source.get("entityId")));
    bean.setEntityVersion(asString(source.get("entityVersion")));
    bean.setType(asEnum(source.get("type"), PolicyType.class));
    List<Map<String, Object>> policies = (List<Map<String, Object>>) source.get("policies");
    if (policies != null) {
        for (Map<String, Object> policyMap : policies) {
            PolicyBean policy = new PolicyBean();
            policy.setOrganizationId(bean.getOrganizationId());
            policy.setEntityId(bean.getEntityId());
            policy.setEntityVersion(bean.getEntityVersion());
            policy.setType(bean.getType());
            policy.setConfiguration(asString(policyMap.get("configuration")));
            policy.setCreatedBy(asString(policyMap.get("createdBy")));
            policy.setCreatedOn(asDate(policyMap.get("createdOn")));
            PolicyDefinitionBean def = new PolicyDefinitionBean();
            def.setId(asString(policyMap.get("definitionId")));
            // Note: this is a placeholder that needs to be resolved later.
            policy.setDefinition(def);
            policy.setId(asLong(policyMap.get("id")));
            policy.setModifiedBy(asString(policyMap.get("modifiedBy")));
            policy.setModifiedOn(asDate(policyMap.get("modifiedOn")));
            policy.setName(asString(policyMap.get("name")));
            policy.setOrderIndex(asInt(policyMap.get("orderIndex")));
            bean.getPolicies().add(policy);
        }
    }
    postMarshall(bean);
    return bean;
}
Also used : PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with PoliciesBean

use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.

the class EsStorage method createClientVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#createClientVersion(io.apiman.manager.api.beans.clients.ClientVersionBean)
 */
@Override
public void createClientVersion(ClientVersionBean version) throws StorageException {
    ClientBean client = version.getClient();
    String id = id(client.getOrganization().getId(), client.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_CLIENT_VERSION, id, EsMarshalling.marshall(version));
    PoliciesBean policies = PoliciesBean.from(PolicyType.Client, client.getOrganization().getId(), client.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_CLIENT_POLICIES, id, EsMarshalling.marshall(policies));
}
Also used : ClientBean(io.apiman.manager.api.beans.clients.ClientBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean)

Example 3 with PoliciesBean

use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.

the class EsStorage method updatePolicy.

/**
 * @see io.apiman.manager.api.core.IStorage#updatePolicy(io.apiman.manager.api.beans.policies.PolicyBean)
 */
@Override
public void updatePolicy(PolicyBean policy) throws StorageException {
    String docType = getPoliciesDocType(policy.getType());
    String pid = id(policy.getOrganizationId(), policy.getEntityId(), policy.getEntityVersion());
    Map<String, Object> source = getEntity(docType, pid);
    if (source == null) {
        // $NON-NLS-1$
        throw new StorageException("Policy not found.");
    }
    PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
    List<PolicyBean> policyBeans = policies.getPolicies();
    boolean found = false;
    if (policyBeans != null) {
        for (PolicyBean policyBean : policyBeans) {
            if (policyBean.getId().equals(policy.getId())) {
                policyBean.setConfiguration(policy.getConfiguration());
                policyBean.setModifiedBy(policy.getModifiedBy());
                policyBean.setModifiedOn(policy.getModifiedOn());
                found = true;
                break;
            }
        }
    }
    if (found) {
        updateEntity(docType, pid, EsMarshalling.marshall(policies));
    } else {
        // $NON-NLS-1$
        throw new StorageException("Policy not found.");
    }
}
Also used : PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 4 with PoliciesBean

use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.

the class EsStorage method createApiVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#createApiVersion(io.apiman.manager.api.beans.apis.ApiVersionBean)
 */
@Override
public void createApiVersion(ApiVersionBean version) throws StorageException {
    ApiBean api = version.getApi();
    String id = id(api.getOrganization().getId(), api.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_API_VERSION, id, EsMarshalling.marshall(version));
    PoliciesBean policies = PoliciesBean.from(PolicyType.Api, api.getOrganization().getId(), api.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_API_POLICIES, id, EsMarshalling.marshall(policies));
}
Also used : ApiBean(io.apiman.manager.api.beans.apis.ApiBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean)

Example 5 with PoliciesBean

use of io.apiman.manager.api.es.beans.PoliciesBean in project apiman by apiman.

the class EsStorage method getPolicy.

/**
 * @see io.apiman.manager.api.core.IStorage#getPolicy(io.apiman.manager.api.beans.policies.PolicyType, java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
 */
@Override
public PolicyBean getPolicy(PolicyType type, String organizationId, String entityId, String version, Long id) throws StorageException {
    String docType = getPoliciesDocType(type);
    String pid = id(organizationId, entityId, version);
    Map<String, Object> source = getEntity(docType, pid);
    if (source == null) {
        return null;
    }
    PoliciesBean policies = EsMarshalling.unmarshallPolicies(source);
    if (policies == null)
        return null;
    List<PolicyBean> policyBeans = policies.getPolicies();
    if (policyBeans != null) {
        for (PolicyBean policyBean : policyBeans) {
            if (policyBean.getId().equals(id)) {
                PolicyDefinitionBean def = getPolicyDefinition(policyBean.getDefinition().getId());
                policyBean.setDefinition(def);
                return policyBean;
            }
        }
    }
    return null;
}
Also used : PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean)

Aggregations

PoliciesBean (io.apiman.manager.api.es.beans.PoliciesBean)12 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)8 PolicyDefinitionBean (io.apiman.manager.api.beans.policies.PolicyDefinitionBean)5 StorageException (io.apiman.manager.api.core.exceptions.StorageException)5 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)1 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)1 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)1 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)1 PolicyDefinitionTemplateBean (io.apiman.manager.api.beans.policies.PolicyDefinitionTemplateBean)1 PolicyType (io.apiman.manager.api.beans.policies.PolicyType)1 PolicySummaryBean (io.apiman.manager.api.beans.summary.PolicySummaryBean)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 Test (org.junit.Test)1