use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class ErrorEventTest method testEventSubProcessErrorWithScript.
@Test
public void testEventSubProcessErrorWithScript() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-EventSubProcessErrorWithScript.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Request Handler", new SignallingTaskHandlerDecorator(ExceptionOnPurposeHandler.class, "Error-90277"));
ksession.getWorkItemManager().registerWorkItemHandler("Error Handler", new SystemOutWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess("com.sample.process");
assertProcessInstanceAborted(processInstance);
assertEquals("90277", ((WorkflowProcessInstance) processInstance).getOutcome());
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.
@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
Map<String, String> resources = new HashMap<String, String>();
String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
String drl = "package org.jbpm; global java.util.List service; " + " rule \"Start Hello1\"" + " when" + " then" + " System.out.println(\"Hello\");" + " end";
resources.put("src/main/resources/simple.drl", drl);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
installKjar(releaseId, kJar1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
assertNotNull(factory);
assertTrue(factory instanceof InternalRegisterableItemsFactory);
assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
assertEquals(1, descriptor.getMarshallingStrategies().size());
// assertEquals(1, descriptor.getConfiguration().size());
assertEquals(1, descriptor.getEnvironmentEntries().size());
assertEquals(1, descriptor.getEventListeners().size());
assertEquals(1, descriptor.getGlobals().size());
assertEquals(1, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(0, descriptor.getRequiredRoles().size());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
KieSession kieSession = engine.getKieSession();
// configuration
assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
assertNotNull(bc);
assertTrue(bc instanceof TestBusinessCalendar);
// globals
Object service = kieSession.getGlobal("service");
assertNotNull(service);
assertTrue(service instanceof ArrayList);
// work item handler
ProcessInstance processInstance = kieSession.startProcess("ManualTask");
long processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
assertNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// process event listener
assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
processEvents.clear();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// task event listener
processInstance = kieSession.startProcess("UserTask");
processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// marshalling strategy
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "marshal");
processInstance = kieSession.startProcess("ParentProcess", params);
processInstanceId = processInstance.getId();
ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
assertNotNull(pi);
String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
manager.disposeRuntimeEngine(engine);
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class ProcessInstanceImpl method getDescription.
public String getDescription() {
if (description == null) {
description = process.getName();
if (process != null) {
Object metaData = process.getMetaData().get("customDescription");
if (metaData instanceof String) {
String customDescription = (String) metaData;
Map<String, String> replacements = new HashMap<String, String>();
Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(customDescription);
while (matcher.find()) {
String paramName = matcher.group(1);
if (replacements.get(paramName) == null) {
try {
String value = (String) MVELSafeHelper.getEvaluator().eval(paramName, new ProcessInstanceResolverFactory(((WorkflowProcessInstance) this)));
replacements.put(paramName, value);
} catch (Throwable t) {
logger.error("Could not resolve customDescription, parameter " + paramName, t);
logger.error("Continuing without setting description.");
}
}
}
for (Map.Entry<String, String> replacement : replacements.entrySet()) {
customDescription = customDescription.replace("#{" + replacement.getKey() + "}", replacement.getValue());
}
description = customDescription;
}
}
}
return description;
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class ProcessInstanceMigrationTest method testProcessInstanceMigrationWithGatewaysAndSameUniqueId.
@Test
public void testProcessInstanceMigrationWithGatewaysAndSameUniqueId() throws Exception {
PersistenceWorkItemHandler handler = new PersistenceWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", 5);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.BPMN2ProcessVersion3", params);
long pid = processInstance.getId();
assertEquals(1, processInstance.getNodeInstances().size());
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("UserTask", "StartTask");
// upgrade to version to of the process
ExplicitUpgradeCommand c = new ExplicitUpgradeCommand(pid, mapping, "com.sample.BPMN2ProcessVersion4");
ksession.execute(c);
assertEquals("com.sample.BPMN2ProcessVersion4", ksession.getProcessInstance(pid).getProcessId());
assertEquals(1, processInstance.getNodeInstances().size());
NodeInstance current = processInstance.getNodeInstances().iterator().next();
handler.completeWorkItem(((WorkItemNodeInstance) current).getWorkItem(), ksession.getWorkItemManager());
handler.completeWorkItem(handler.getWorkItem("FirstPath"), ksession.getWorkItemManager());
handler.completeWorkItem(handler.getWorkItem("SecondPath"), ksession.getWorkItemManager());
List<? extends VariableInstanceLog> vars = engine.getAuditService().findVariableInstances(pid, "x");
assertNotNull(vars);
assertEquals(2, vars.size());
assertEquals("10", vars.get(1).getValue());
assertDefinitionChanged(pid, "com.sample.BPMN2ProcessVersion4", true);
}
use of org.jbpm.workflow.instance.WorkflowProcessInstance in project jbpm by kiegroup.
the class ProcessInstanceMigrationTest method testProcessInstanceMigrationExplicitSubprocesses.
@Test
public void testProcessInstanceMigrationExplicitSubprocesses() throws Exception {
PersistenceWorkItemHandler handler = new PersistenceWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler);
WorkflowProcessInstance processInstance = (WorkflowProcessInstance) ksession.startProcess("com.sample.bpmn.migration3");
long pid = processInstance.getId();
assertEquals("com.sample.bpmn.migration3", ksession.getProcessInstance(pid).getProcessId());
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
Map<String, String> mapping = new HashMap<String, String>();
mapping.put("ForJohn", "ForMary");
ExplicitUpgradeCommand c = new ExplicitUpgradeCommand(pid, mapping, "com.sample.bpmn.migration4");
ksession.execute(c);
assertEquals("com.sample.bpmn.migration4", ksession.getProcessInstance(pid).getProcessId());
handler.completeWorkItem(handler.getWorkItem("ForJohn"), ksession.getWorkItemManager());
handler.completeWorkItem(handler.getWorkItem("ForBill"), ksession.getWorkItemManager());
assertDefinitionChanged(pid, "com.sample.bpmn.migration4", true);
}
Aggregations