Search in sources :

Example 11 with PoliciesBean

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

the class EsStorage method createPlanVersion.

/**
 * @see io.apiman.manager.api.core.IStorage#createPlanVersion(io.apiman.manager.api.beans.plans.PlanVersionBean)
 */
@Override
public void createPlanVersion(PlanVersionBean version) throws StorageException {
    PlanBean plan = version.getPlan();
    String id = id(plan.getOrganization().getId(), plan.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_PLAN_VERSION, id, EsMarshalling.marshall(version));
    PoliciesBean policies = PoliciesBean.from(PolicyType.Plan, plan.getOrganization().getId(), plan.getId(), version.getVersion());
    indexEntity(INDEX_MANAGER_POSTFIX_PLAN_POLICIES, id, EsMarshalling.marshall(policies));
}
Also used : PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean)

Example 12 with PoliciesBean

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

the class EsMarshallingTest method testMarshallPoliciesBean.

/**
 * Test method for {@link io.apiman.manager.api.es.EsMarshalling#marshall(io.apiman.manager.api.es.beans.PoliciesBean)}.
 */
@Test
public void testMarshallPoliciesBean() throws Exception {
    PoliciesBean bean = new PoliciesBean();
    bean.setEntityId("ENTITY_ID");
    bean.setOrganizationId("ORG_ID");
    bean.setEntityVersion("VERSION");
    bean.setType(PolicyType.Api);
    XContentBuilder builder = EsMarshalling.marshall(bean);
    Assert.assertEquals("{\"organizationId\":\"ORG_ID\",\"entityId\":\"ENTITY_ID\",\"entityVersion\":\"VERSION\",\"type\":\"Api\"}", Strings.toString(builder));
    PolicyBean policy = new PolicyBean();
    policy.setCreatedBy("CREATED_BY");
    policy.setCreatedOn(new Date(1));
    policy.setConfiguration("CONFIGURATION");
    policy.setDescription("DESCRIPTION HERE.");
    policy.setEntityId("ENTITY_ID");
    policy.setEntityVersion("ENTITY_VERSION");
    policy.setId(17L);
    policy.setModifiedBy("MODIFIED_BY");
    policy.setModifiedOn(new Date(2));
    policy.setName("NAME");
    policy.setOrderIndex(9);
    policy.setOrganizationId("ORG_ID");
    policy.setType(PolicyType.Api);
    policy.setDefinition(new PolicyDefinitionBean());
    policy.getDefinition().setDeleted(false);
    policy.getDefinition().setDescription("POLICY_DEF_DESCRIPTION");
    policy.getDefinition().setForm("FORM");
    policy.getDefinition().setFormType(PolicyFormType.JsonSchema);
    policy.getDefinition().setIcon("ICON");
    policy.getDefinition().setId("POLICY_DEF_ID");
    policy.getDefinition().setName("POLICY DEF NAME");
    policy.getDefinition().setPluginId(27L);
    policy.getDefinition().setPolicyImpl("POLICY_IMPL");
    PolicyDefinitionTemplateBean template = new PolicyDefinitionTemplateBean();
    template.setTemplate("TEMPLATE");
    template.setLanguage("EN_US");
    policy.getDefinition().getTemplates().add(template);
    bean.getPolicies().add(policy);
    builder = EsMarshalling.marshall(bean);
    Assert.assertEquals("{\"organizationId\":\"ORG_ID\",\"entityId\":\"ENTITY_ID\",\"entityVersion\":\"VERSION\",\"type\":\"Api\",\"policies\":[" + "{\"id\":17,\"name\":\"NAME\",\"configuration\":\"CONFIGURATION\",\"createdBy\":\"CREATED_BY\",\"createdOn\":1,\"modifiedBy\":\"MODIFIED_BY\",\"modifiedOn\":2,\"definitionId\":\"POLICY_DEF_ID\",\"orderIndex\":9}]}", Strings.toString(builder));
}
Also used : PolicyDefinitionTemplateBean(io.apiman.manager.api.beans.policies.PolicyDefinitionTemplateBean) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PoliciesBean(io.apiman.manager.api.es.beans.PoliciesBean) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Date(java.util.Date) Test(org.junit.Test)

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