Search in sources :

Example 6 with WorkflowProcessInstance

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());
}
Also used : ExceptionOnPurposeHandler(org.jbpm.bpmn2.objects.ExceptionOnPurposeHandler) KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) SignallingTaskHandlerDecorator(org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 7 with WorkflowProcessInstance

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);
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) ArrayList(java.util.ArrayList) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) RegisterableItemsFactory(org.kie.api.runtime.manager.RegisterableItemsFactory) KieServices(org.kie.api.KieServices) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) KieSession(org.kie.api.runtime.KieSession) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) ReleaseId(org.kie.api.builder.ReleaseId) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) TaskSummary(org.kie.api.task.model.TaskSummary) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Example 8 with WorkflowProcessInstance

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;
}
Also used : ProcessInstanceResolverFactory(org.jbpm.workflow.instance.impl.ProcessInstanceResolverFactory) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Map(java.util.Map) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance)

Example 9 with WorkflowProcessInstance

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);
}
Also used : HashMap(java.util.HashMap) NodeInstance(org.kie.api.runtime.process.NodeInstance) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Example 10 with WorkflowProcessInstance

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);
}
Also used : HashMap(java.util.HashMap) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Test(org.junit.Test)

Aggregations

WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)24 HashMap (java.util.HashMap)16 Test (org.junit.Test)15 KieSession (org.kie.api.runtime.KieSession)8 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)8 Date (java.util.Date)6 RegistryContext (org.drools.core.command.impl.RegistryContext)5 Context (org.kie.api.runtime.Context)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ExecutableCommand (org.drools.core.command.impl.ExecutableCommand)3 NodeInstance (org.kie.api.runtime.process.NodeInstance)3 Matcher (java.util.regex.Matcher)2 CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)2 ProcessStartedEventImpl (org.drools.core.event.ProcessStartedEventImpl)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 SignallingTaskHandlerDecorator (org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)2