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;
}
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());
}
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());
}
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);
}
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());
}
Aggregations