Search in sources :

Example 11 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactory method getWorkItemHandlersFromDescriptor.

protected Map<String, WorkItemHandler> getWorkItemHandlersFromDescriptor(RuntimeEngine runtime) {
    Map<String, WorkItemHandler> defaultHandlers = new HashMap<String, WorkItemHandler>();
    DeploymentDescriptor descriptor = getRuntimeManager().getDeploymentDescriptor();
    if (descriptor != null) {
        Map<String, Object> params = getParametersMap(runtime);
        for (NamedObjectModel model : descriptor.getWorkItemHandlers()) {
            Object hInstance = getInstanceFromModel(model, getRuntimeManager().getEnvironment().getClassLoader(), params);
            if (hInstance != null) {
                defaultHandlers.put(model.getName(), (WorkItemHandler) hInstance);
            }
        }
    }
    return defaultHandlers;
}
Also used : WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) LocalHTWorkItemHandler(org.jbpm.services.task.wih.LocalHTWorkItemHandler) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor)

Example 12 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DeploymentDescriptorManagerTest method testDeploymentDescriptorFromKieContainer.

@Test
public void testDeploymentDescriptorFromKieContainer() {
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    DeploymentDescriptor descriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    descriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/simple.drl", SIMPLE_DRL);
    resources.put("src/main/resources/META-INF/kie-deployment-descriptor.xml", descriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    assertNotNull(kieContainer);
    List<DeploymentDescriptor> descriptorHierarchy = manager.getDeploymentDescriptorHierarchy(kieContainer);
    assertNotNull(descriptorHierarchy);
    assertEquals(2, descriptorHierarchy.size());
    descriptor = descriptorHierarchy.get(0);
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(0, descriptor.getWorkItemHandlers().size());
    descriptor = descriptorHierarchy.get(1);
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(0, descriptor.getWorkItemHandlers().size());
}
Also used : HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 13 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DeploymentDescriptorManagerTest method testDeploymentDescriptorFromKieContainerNoDescInKjar.

@Test
public void testDeploymentDescriptorFromKieContainerNoDescInKjar() {
    DeploymentDescriptorManager manager = new DeploymentDescriptorManager("org.jbpm.domain");
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/simple.drl", SIMPLE_DRL);
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    assertNotNull(kieContainer);
    List<DeploymentDescriptor> descriptorHierarchy = manager.getDeploymentDescriptorHierarchy(kieContainer);
    assertNotNull(descriptorHierarchy);
    assertEquals(1, descriptorHierarchy.size());
    DeploymentDescriptor descriptor = descriptorHierarchy.get(0);
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(0, descriptor.getWorkItemHandlers().size());
}
Also used : HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 14 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DeploymentDescriptorManagerTest method roundTripDescriptorMarshallingTest.

@Test
public void roundTripDescriptorMarshallingTest() throws Exception {
    DeploymentDescriptorImpl depDescImpl = new DeploymentDescriptorImpl();
    List<Field> fieldsToFill = new LinkedList<Field>();
    for (Field field : DeploymentDescriptorImpl.class.getDeclaredFields()) {
        if (field.getAnnotation(XmlElement.class) != null) {
            fieldsToFill.add(field);
        }
    }
    for (Field field : fieldsToFill) {
        field.setAccessible(true);
        Class fieldType = field.getType();
        if (fieldType.equals(String.class)) {
            field.set(depDescImpl, getStringVal());
        } else if (fieldType.equals(Boolean.class)) {
            field.set(depDescImpl, true);
        } else if (fieldType.equals(PersistenceMode.class)) {
            field.set(depDescImpl, PersistenceMode.NONE);
        } else if (fieldType.equals(AuditMode.class)) {
            field.set(depDescImpl, AuditMode.JMS);
        } else if (fieldType.equals(RuntimeStrategy.class)) {
            field.set(depDescImpl, RuntimeStrategy.PER_PROCESS_INSTANCE);
        } else if (Set.class.isAssignableFrom(fieldType)) {
            Type genType = field.getGenericType();
            Type genParamType = ((ParameterizedType) genType).getActualTypeArguments()[0];
            Set val = new HashSet();
            if (genParamType.equals(String.class)) {
                val.add(getStringVal());
            } else if (genParamType.equals(ObjectModel.class)) {
                val.add(getObjectModelParameter(getStringVal(), false));
            } else if (genParamType.equals(NamedObjectModel.class)) {
                val.add(getObjectModelParameter(getStringVal(), true));
            }
            field.set(depDescImpl, val);
        }
    }
    String depDescXml = DeploymentDescriptorIO.toXml(depDescImpl);
    ByteArrayInputStream inputStream = new ByteArrayInputStream(depDescXml.getBytes());
    DeploymentDescriptor copyDepDescImpl = DeploymentDescriptorIO.fromXml(inputStream);
    Assertions.assertThat(depDescImpl).isEqualToComparingFieldByFieldRecursively(copyDepDescImpl);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) LinkedList(java.util.LinkedList) ParameterizedType(java.lang.reflect.ParameterizedType) Field(java.lang.reflect.Field) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) AuditMode(org.kie.internal.runtime.conf.AuditMode) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlElement(javax.xml.bind.annotation.XmlElement) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with DeploymentDescriptor

use of org.kie.internal.runtime.conf.DeploymentDescriptor in project jbpm by kiegroup.

the class DeploymentDescriptorMergerTest method testDeploymentDesciptorMergeMergeCollectionsAvoidDuplicatesNamedObject.

@Test
public void testDeploymentDesciptorMergeMergeCollectionsAvoidDuplicatesNamedObject() {
    DeploymentDescriptor master = new DeploymentDescriptorImpl("org.jbpm.domain");
    master.getBuilder().addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()"));
    assertNotNull(master);
    assertEquals("org.jbpm.domain", master.getPersistenceUnit());
    assertEquals("org.jbpm.domain", master.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, master.getAuditMode());
    assertEquals(PersistenceMode.JPA, master.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, master.getRuntimeStrategy());
    assertEquals(0, master.getMarshallingStrategies().size());
    assertEquals(0, master.getConfiguration().size());
    assertEquals(0, master.getEnvironmentEntries().size());
    assertEquals(0, master.getEventListeners().size());
    assertEquals(0, master.getGlobals().size());
    assertEquals(0, master.getTaskEventListeners().size());
    assertEquals(1, master.getWorkItemHandlers().size());
    DeploymentDescriptor slave = new DeploymentDescriptorImpl("org.jbpm.domain");
    slave.getBuilder().auditMode(AuditMode.JMS).persistenceMode(PersistenceMode.JPA).persistenceUnit(null).auditPersistenceUnit("").addWorkItemHandler(new NamedObjectModel("mvel", "Log", "new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()"));
    assertNotNull(slave);
    assertEquals(null, slave.getPersistenceUnit());
    assertEquals("", slave.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, slave.getAuditMode());
    assertEquals(PersistenceMode.JPA, slave.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, slave.getRuntimeStrategy());
    assertEquals(0, slave.getMarshallingStrategies().size());
    assertEquals(0, slave.getConfiguration().size());
    assertEquals(0, slave.getEnvironmentEntries().size());
    assertEquals(0, slave.getEventListeners().size());
    assertEquals(0, slave.getGlobals().size());
    assertEquals(0, slave.getTaskEventListeners().size());
    assertEquals(1, slave.getWorkItemHandlers().size());
    // and now let's merge them
    DeploymentDescriptorMerger merger = new DeploymentDescriptorMerger();
    DeploymentDescriptor outcome = merger.merge(master, slave, MergeMode.MERGE_COLLECTIONS);
    assertNotNull(outcome);
    assertEquals("org.jbpm.domain", outcome.getPersistenceUnit());
    assertEquals("org.jbpm.domain", outcome.getAuditPersistenceUnit());
    assertEquals(AuditMode.JMS, outcome.getAuditMode());
    assertEquals(PersistenceMode.JPA, outcome.getPersistenceMode());
    assertEquals(RuntimeStrategy.SINGLETON, outcome.getRuntimeStrategy());
    assertEquals(0, outcome.getMarshallingStrategies().size());
    assertEquals(0, outcome.getConfiguration().size());
    assertEquals(0, outcome.getEnvironmentEntries().size());
    assertEquals(0, outcome.getEventListeners().size());
    assertEquals(0, outcome.getGlobals().size());
    assertEquals(0, outcome.getTaskEventListeners().size());
    assertEquals(1, outcome.getWorkItemHandlers().size());
    // let's check if the slave version is preserved
    NamedObjectModel model = outcome.getWorkItemHandlers().get(0);
    assertEquals("Log", model.getName());
    assertEquals("new org.jbpm.process.instance.impl.demo.CustomSystemOutWorkItemHandler()", model.getIdentifier());
}
Also used : NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) Test(org.junit.Test)

Aggregations

DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)98 Test (org.junit.Test)55 NamedObjectModel (org.kie.internal.runtime.conf.NamedObjectModel)43 ObjectModel (org.kie.internal.runtime.conf.ObjectModel)34 HashMap (java.util.HashMap)27 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)26 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)23 KieServices (org.kie.api.KieServices)22 ArrayList (java.util.ArrayList)21 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)21 ReleaseId (org.kie.api.builder.ReleaseId)21 ByteArrayInputStream (java.io.ByteArrayInputStream)16 File (java.io.File)13 KieMavenRepository (org.kie.scanner.KieMavenRepository)12 FileOutputStream (java.io.FileOutputStream)11 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)11 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)10 InputStream (java.io.InputStream)9 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)9 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)8