Search in sources :

Example 91 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class AdminAPIsWithListenerTest method automaticCleanUpForSubProcessWithPerProcessInstanceStrategy.

@Test
public void automaticCleanUpForSubProcessWithPerProcessInstanceStrategy() throws Exception {
    TaskCleanUpProcessEventListener taskCleanUpProcessEventListener = new TaskCleanUpProcessEventListener(null);
    this.addProcessEventListener(taskCleanUpProcessEventListener);
    RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "com.mycompany.sample", "org/jbpm/test/functional/task/ht-main.bpmn", "org/jbpm/test/functional/task/ht-sub.bpmn");
    RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get());
    taskCleanUpProcessEventListener.setTaskService((InternalTaskService) runtime.getTaskService());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance pi = ksession.startProcess("com.mycompany.sample", params);
    // obtain the task service
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks1 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertFalse(tasks1.isEmpty());
    TaskSummary task1 = tasks1.get(0);
    System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
    taskService.start(task1.getId(), "john");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("comment", "Agreed, existing laptop needs replacing");
    results.put("outcome", "Accept");
    // complete the human task of the main process
    taskService.complete(task1.getId(), "john", results);
    // abort the process instance
    ksession.abortProcessInstance(pi.getId());
    // main process instance shall be aborted
    assertProcessInstanceAborted(pi.getId());
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findProcessInstances("com.mycompany.sample");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
    logs = logService.findProcessInstances("com.mycompany.sample.subprocess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
    manager.close();
    final EntityManager em = emfTasks.createEntityManager();
    assertEquals(0, em.createQuery("select t from TaskImpl t").getResultList().size());
    assertEquals(0, em.createQuery("select i from I18NTextImpl i").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_BAs").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_ExclOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_PotOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Recipients").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Stakeholders").getResultList().size());
    assertEquals(0, em.createQuery("select c from ContentImpl c").getResultList().size());
    em.close();
}
Also used : 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) EntityManager(javax.persistence.EntityManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) Test(org.junit.Test)

Example 92 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class AdminAPIsWithListenerTest method automaticCleanUpWitCallActivityTest.

@Test
public void automaticCleanUpWitCallActivityTest() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/CallActivity.bpmn2", "org/jbpm/test/functional/task/CallActivity2.bpmn2", "org/jbpm/test/functional/task/CallActivitySubProcess.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ksession.addEventListener(new TaskCleanUpProcessEventListener(taskService));
    ProcessInstance processInstance = ksession.startProcess("ParentProcessCA");
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    assertProcessInstanceCompleted(processInstance.getId());
    final EntityManager em = emfTasks.createEntityManager();
    assertEquals(0, em.createQuery("select t from TaskImpl t").getResultList().size());
    assertEquals(0, em.createQuery("select i from I18NTextImpl i").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_BAs").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_ExclOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_PotOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Recipients").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Stakeholders").getResultList().size());
    assertEquals(0, em.createQuery("select c from ContentImpl c").getResultList().size());
    em.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) EntityManager(javax.persistence.EntityManager) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) TaskCleanUpProcessEventListener(org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 93 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class ParalellLoopTest method complete.

private void complete(String user, String outcome) {
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(user, "en-UK");
    TaskSummary task = list.get(0);
    logger.debug("complete task");
    logger.debug("- {} is executing task {}", user, task.getName());
    taskService.start(task.getId(), user);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("OUTCOME", outcome);
    taskService.complete(task.getId(), user, map);
    logger.debug("- {} executed task {}", user, task.getName());
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary)

Example 94 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class InclusiveGatewayWithHumanTasksProcessTest method testInclusiveGatewayWithLoopAndUserTasks.

@Test
public void testInclusiveGatewayWithLoopAndUserTasks() {
    createRuntimeManager("org/jbpm/test/functional/gateway/InclusiveGatewayWithHumanTasksProcess.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    String userId = "john";
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("firstXor", true);
    params.put("secondXor", true);
    params.put("thirdXor", true);
    ProcessInstance pi = ksession.startProcess("InclusiveWithAdvancedLoop", params);
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    // completing first task
    taskService.start(tasks.get(0).getId(), userId);
    taskService.complete(tasks.get(0).getId(), userId, new HashMap<String, Object>());
    // completing second task
    tasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
    assertNotNull(tasks);
    assertEquals(2, tasks.size());
    for (TaskSummary task : tasks) {
        if (task.getName().equals("HT Form2")) {
            taskService.start(task.getId(), userId);
            taskService.complete(task.getId(), userId, new HashMap<String, Object>());
            break;
        }
    }
    List<TaskSummary> johntasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
    assertNotNull(johntasks);
    assertEquals(1, johntasks.size());
    taskService.start(johntasks.get(0).getId(), userId);
    taskService.complete(johntasks.get(0).getId(), userId, new HashMap<String, Object>());
    johntasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
    assertNotNull(johntasks);
    assertEquals(1, johntasks.size());
    taskService.start(johntasks.get(0).getId(), userId);
    taskService.complete(johntasks.get(0).getId(), userId, new HashMap<String, Object>());
    assertProcessInstanceCompleted(pi.getId());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) 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 95 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class AbstractStartProcessWithCorrelationKeyTest method testProcessesWithSameBusinessKeyNotInParallel.

@Test
public void testProcessesWithSameBusinessKeyNotInParallel() {
    createRuntimeManager("org/jbpm/test/functional/correlation/humantask.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // let john execute Task 1
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
    assertNotNull(processInstanceCopy);
    assertEquals(processInstance.getId(), processInstanceCopy.getId());
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
    processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
    assertProcessInstanceActive(processInstance.getId(), ksession);
    assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
    // let john execute Task 1
    list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    task = list.get(0);
    logger.info("John is executing task {}", task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    assertNodeTriggered(processInstance.getId(), "Task 2");
    processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
    assertNotNull(processInstanceCopy);
    assertEquals(processInstance.getId(), processInstanceCopy.getId());
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    logger.info("Mary is executing task {}", task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    assertNodeTriggered(processInstance.getId(), "End");
    assertProcessInstanceNotActive(processInstance.getId(), ksession);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) TaskService(org.kie.api.task.TaskService) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.api.task.model.TaskSummary)371 Test (org.junit.Test)327 HashMap (java.util.HashMap)132 QueryFilter (org.kie.internal.query.QueryFilter)126 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)100 Task (org.kie.api.task.model.Task)91 ArrayList (java.util.ArrayList)87 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)86 KieSession (org.kie.api.runtime.KieSession)84 TaskService (org.kie.api.task.TaskService)66 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)58 StringReader (java.io.StringReader)55 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 Status (org.kie.api.task.model.Status)47 InternalTask (org.kie.internal.task.api.model.InternalTask)47 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)41 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)38 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)36 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)28