Search in sources :

Example 6 with TaskCleanUpProcessEventListener

use of org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener 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 7 with TaskCleanUpProcessEventListener

use of org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener in project jbpm by kiegroup.

the class AdminAPIsWithListenerTest method automaticCleanUpForSubProcessWithSingletonStrategy.

@Test
public void automaticCleanUpForSubProcessWithSingletonStrategy() throws Exception {
    TaskCleanUpProcessEventListener taskCleanUpProcessEventListener = new TaskCleanUpProcessEventListener(null);
    this.addProcessEventListener(taskCleanUpProcessEventListener);
    RuntimeManager manager = createRuntimeManager("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 8 with TaskCleanUpProcessEventListener

use of org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener in project jbpm by kiegroup.

the class AdminAPIsWithListenerTest method automaticCleanUpTestAbortProcess.

@Test
public void automaticCleanUpTestAbortProcess() throws Exception {
    createRuntimeManager("org/jbpm/test/functional/task/patient-appointment.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
    ksession.addEventListener(new TaskCleanUpProcessEventListener(taskService));
    logger.info("### Starting process ###");
    Map<String, Object> parameters = new HashMap<String, Object>();
    ProcessInstance process = ksession.startProcess("org.jbpm.PatientAppointment", parameters);
    long processInstanceId = process.getId();
    // The process is in the first Human Task waiting for its completion
    assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());
    // gets frontDesk's tasks
    List<TaskSummary> frontDeskTasks = taskService.getTasksAssignedAsPotentialOwner("frontDesk", "en-UK");
    assertEquals(1, frontDeskTasks.size());
    // doctor doesn't have any task
    List<TaskSummary> doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
    Assert.assertTrue(doctorTasks.isEmpty());
    // manager doesn't have any task
    List<TaskSummary> managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertTrue(managerTasks.isEmpty());
    taskService.start(frontDeskTasks.get(0).getId(), "frontDesk");
    taskService.complete(frontDeskTasks.get(0).getId(), "frontDesk", null);
    // Now doctor has 1 task
    doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
    assertEquals(1, doctorTasks.size());
    // No tasks for manager yet
    managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertTrue(managerTasks.isEmpty());
    taskService.start(doctorTasks.get(0).getId(), "doctor");
    taskService.complete(doctorTasks.get(0).getId(), "doctor", null);
    // abort process instance
    ksession.abortProcessInstance(processInstanceId);
    // since persisted process instance is completed it should be null
    process = ksession.getProcessInstance(process.getId());
    Assert.assertNull(process);
    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) 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) Test(org.junit.Test)

Example 9 with TaskCleanUpProcessEventListener

use of org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener in project jbpm by kiegroup.

the class HumanTaskCleanUpEarlyFlushTest method testSubprocess.

@Test
@BZ({ "1128377", "1177736" })
public void testSubprocess() {
    createRuntimeManager(SUBPROCESS_PARENT, SUBPROCESS_CHILD1, SUBPROCESS_CHILD2);
    RuntimeEngine engine = getRuntimeEngine();
    KieSession ksession = engine.getKieSession();
    TaskService taskService = engine.getTaskService();
    ksession.addEventListener(new TaskCleanUpProcessEventListener(taskService));
    ProcessInstance processInstance = ksession.startProcess(SUBPROCESS_PARENT_ID);
    for (int i = 0; i < 2; ++i) {
        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());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) 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) BZ(qa.tools.ikeeper.annotation.BZ)

Example 10 with TaskCleanUpProcessEventListener

use of org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener in project jbpm by kiegroup.

the class HumanTaskCleanUpEarlyFlushTest method testSignal.

private void testSignal(JbpmJUnitBaseTestCase.Strategy strategy) {
    createRuntimeManager(strategy, null, SIGNAL_SENDER, SIGNAL_RECEIVER);
    RuntimeEngine engine = getRuntimeEngine();
    KieSession ksession = engine.getKieSession();
    TaskService taskService = engine.getTaskService();
    ksession.addEventListener(new TaskCleanUpProcessEventListener(taskService));
    ksession.startProcess(SIGNAL_SENDER_ID);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) TaskCleanUpProcessEventListener(org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener) KieSession(org.kie.api.runtime.KieSession)

Aggregations

TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)10 KieSession (org.kie.api.runtime.KieSession)10 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)10 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)9 TaskService (org.kie.api.task.TaskService)9 Test (org.junit.Test)8 TaskSummary (org.kie.api.task.model.TaskSummary)8 InternalTaskService (org.kie.internal.task.api.InternalTaskService)7 HashMap (java.util.HashMap)6 EntityManager (javax.persistence.EntityManager)5 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)4 InitialContext (javax.naming.InitialContext)2 UserTransaction (javax.transaction.UserTransaction)2 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)2 AuditService (org.kie.api.runtime.manager.audit.AuditService)2 JPAAuditLogService (org.jbpm.process.audit.JPAAuditLogService)1 ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)1 EventService (org.kie.internal.task.api.EventService)1 BZ (qa.tools.ikeeper.annotation.BZ)1