Search in sources :

Example 41 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class AuditCommandsTest method testFindProcessInstanceCommands.

@Test
public void testFindProcessInstanceCommands() throws Exception {
    String processId = "IntermediateCatchEvent";
    KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventSignal.bpmn2");
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    ProcessInstance processInstance = ksession.startProcess(processId);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
    Command<?> cmd = new FindProcessInstancesCommand();
    Object result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    List<ProcessInstanceLog> logList = (List<ProcessInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 1, logList.size());
    ProcessInstanceLog log = logList.get(0);
    assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId());
    assertEquals(log.getProcessId(), processInstance.getProcessId());
    cmd = new FindActiveProcessInstancesCommand(processId);
    result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof List);
    logList = (List<ProcessInstanceLog>) result;
    assertEquals("Log list size is incorrect.", 1, logList.size());
    log = logList.get(0);
    assertEquals("Process instance id", log.getProcessInstanceId().longValue(), processInstance.getId());
    assertEquals("Process id", log.getProcessId(), processInstance.getProcessId());
    assertEquals("Status", log.getStatus().intValue(), ProcessInstance.STATE_ACTIVE);
    cmd = new FindProcessInstanceCommand(processInstance.getId());
    result = ksession.execute(cmd);
    assertNotNull("Command result is empty!", result);
    assertTrue(result instanceof ProcessInstanceLog);
    log = (ProcessInstanceLog) result;
    assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId());
    assertEquals(log.getProcessId(), processInstance.getProcessId());
    // now signal process instance
    ksession = restoreSession(ksession, true);
    ksession.signalEvent("MyMessage", "SomeValue", processInstance.getId());
    assertProcessInstanceCompleted(processInstance.getId(), ksession);
    cmd = new ClearHistoryLogsCommand();
    result = ksession.execute(cmd);
    assertEquals("There should be no more logs", 0, logService.findProcessInstances().size());
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) List(java.util.List) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog) Test(org.junit.Test)

Example 42 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class CallActivitiesWithUserTasksProcessTest method testCallActivitiesWith2ndUserTaskInSub.

@Test
public void testCallActivitiesWith2ndUserTaskInSub() throws Exception {
    TaskCleanUpProcessEventListener taskListener = new TaskCleanUpProcessEventListener(null);
    addWorkItemHandler("Sysout", new SystemOutWorkItemHandler());
    addProcessEventListener(taskListener);
    InitialContext context = new InitialContext();
    UserTransaction ut = (UserTransaction) context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
    RuntimeManager manager = createRuntimeManager(strategy, (String) null, "org/jbpm/test/functional/subprocess/CallActivityWithTaskInSub-Main.bpmn2", "org/jbpm/test/functional/subprocess/CallActivityWithTaskInSub-Sub.bpmn2");
    RuntimeEngine runtimeEngine;
    if (Strategy.SINGLETON.equals(strategy)) {
        runtimeEngine = getRuntimeEngine();
    } else if (Strategy.PROCESS_INSTANCE.equals(strategy)) {
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
    } else {
        throw new IllegalStateException("Not possible!");
    }
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    // set created task service on listener
    taskListener.setTaskService((InternalTaskService) taskService);
    if (userManagedTx) {
        ut.begin();
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("pActorId", "john");
    ProcessInstance processInstance = ksession.startProcess("PolicyValueAnalysis", params);
    if (userManagedTx) {
        ut.commit();
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
        ut.begin();
    } else {
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
    }
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    Long taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    if (userManagedTx) {
        ut.commit();
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
        ut.begin();
    } else {
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
    }
    // sub process task
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    if (userManagedTx) {
        ut.commit();
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
        ut.begin();
    } else {
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
    }
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    if (userManagedTx) {
        ut.commit();
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
        ut.begin();
    } else {
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
    }
    // sub process task
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    if (userManagedTx) {
        // since we are checking in same transaction it will already see it as completed
        assertProcessInstanceCompleted(processInstance.getId());
        ut.commit();
    }
    assertProcessInstanceCompleted(processInstance.getId());
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskCleanUpProcessEventListener(org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener) InitialContext(javax.naming.InitialContext) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 43 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class CallActivitiesWithUserTasksProcessTest method testCallActivitiesWithUserTasks.

@Test
public void testCallActivitiesWithUserTasks() throws Exception {
    TaskCleanUpProcessEventListener taskListener = new TaskCleanUpProcessEventListener(null);
    addWorkItemHandler("Sysout", new SystemOutWorkItemHandler());
    addProcessEventListener(taskListener);
    InitialContext context = new InitialContext();
    UserTransaction ut = (UserTransaction) context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
    RuntimeManager manager = createRuntimeManager(strategy, (String) null, "org/jbpm/test/functional/subprocess/CallActivityWithTask-Main.bpmn2", "org/jbpm/test/functional/subprocess/CallActivityWithTask-Sub.bpmn2");
    RuntimeEngine runtimeEngine;
    if (Strategy.SINGLETON.equals(strategy)) {
        runtimeEngine = getRuntimeEngine();
    } else if (Strategy.PROCESS_INSTANCE.equals(strategy)) {
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
    } else {
        throw new IllegalStateException("Not possible!");
    }
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    // set created task service on listener
    taskListener.setTaskService((InternalTaskService) taskService);
    if (userManagedTx) {
        ut.begin();
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("pActorId", "john");
    ProcessInstance processInstance = ksession.startProcess("PolicyValueAnalysis", params);
    if (userManagedTx) {
        ut.commit();
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
        ut.begin();
    } else {
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
    }
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    Long taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    if (userManagedTx) {
        ut.commit();
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
        ut.begin();
    } else {
        manager.disposeRuntimeEngine(runtimeEngine);
        runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
        ksession = runtimeEngine.getKieSession();
        taskService = runtimeEngine.getTaskService();
        taskListener.setTaskService((InternalTaskService) taskService);
    }
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    if (userManagedTx) {
        ut.commit();
        ut.begin();
    }
    assertProcessInstanceCompleted(processInstance.getId());
    if (userManagedTx) {
        ut.commit();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskCleanUpProcessEventListener(org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener) InitialContext(javax.naming.InitialContext) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 44 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class WorkingMemoryDbLoggerWithStatefulSessionTest method startProcess.

@Override
public ProcessInstance startProcess(String processId) {
    if (session == null) {
        // load the process
        KieBase kbase = createKnowledgeBase();
        // create a new session
        Properties properties = new Properties();
        properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
        properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
        SessionConfiguration config = SessionConfiguration.newInstance(properties);
        session = kbase.newKieSession(config, createEnvironment(context));
        new JPAWorkingMemoryDbLogger(session);
        session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    }
    return session.startProcess(processId);
}
Also used : KieBase(org.kie.api.KieBase) SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler) Properties(java.util.Properties) SessionConfiguration(org.drools.core.SessionConfiguration)

Example 45 with SystemOutWorkItemHandler

use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.

the class AbstractAuditLogServiceTest method runTestLogger2.

public static void runTestLogger2(KieSession session, AuditLogService auditLogService) {
    session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
    // record the initial count to compare to later
    List<ProcessInstanceLog> processInstances = auditLogService.findProcessInstances("com.sample.ruleflow");
    int initialProcessInstanceSize = processInstances.size();
    // start process instance
    session.startProcess("com.sample.ruleflow");
    session.startProcess("com.sample.ruleflow");
    logger.debug("Checking process instances for process 'com.sample.ruleflow'");
    processInstances = auditLogService.findProcessInstances("com.sample.ruleflow");
    Assertions.assertThat(processInstances.size()).isEqualTo(initialProcessInstanceSize + 2);
    for (ProcessInstanceLog processInstance : processInstances) {
        logger.debug("{} -> {} - {}", processInstance.toString(), processInstance.getStart(), processInstance.getEnd());
        List<NodeInstanceLog> nodeInstances = auditLogService.findNodeInstances(processInstance.getProcessInstanceId());
        for (NodeInstanceLog nodeInstance : nodeInstances) {
            logger.debug("{} -> {}", nodeInstance.toString(), nodeInstance.getDate());
        }
        Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
    }
    auditLogService.clear();
}
Also used : SystemOutWorkItemHandler(org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)

Aggregations

SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)87 Test (org.junit.Test)77 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)75 KieBase (org.kie.api.KieBase)59 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)45 HashMap (java.util.HashMap)39 KieSession (org.kie.api.runtime.KieSession)38 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)16 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)15 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)14 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)14 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)14 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)13 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)13 ArrayList (java.util.ArrayList)10 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)6 Document (org.w3c.dom.Document)5 Map (java.util.Map)4 PersistenceUtil.createEnvironment (org.jbpm.persistence.util.PersistenceUtil.createEnvironment)4