Search in sources :

Example 86 with TaskSummary

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

the class ProcessInstanceMigrationTest method testProcessInstanceMigrationExplicit.

@Test
public void testProcessInstanceMigrationExplicit() throws Exception {
    ProcessInstance p = ksession.startProcess("com.sample.bpmn.migration");
    long pid = p.getId();
    assertEquals("com.sample.bpmn.migration", ksession.getProcessInstance(pid).getProcessId());
    List<TaskSummary> list = assertTaskAssignedTo("john");
    assertEquals(ProcessInstance.STATE_ACTIVE, p.getState());
    Map<String, String> mapping = new HashMap<String, String>();
    mapping.put("Task 1", "Task 2");
    // upgrade to version to of the process
    ExplicitUpgradeCommand c = new ExplicitUpgradeCommand(pid, mapping, "com.sample.bpmn.migration2");
    ksession.execute(c);
    completeTask(list.get(0));
    assertDefinitionChanged(pid, "com.sample.bpmn.migration2", true);
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 87 with TaskSummary

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

the class ProcessInstanceMigrationTest method testProcessInstanceMigrationExplicitBack.

@Test
public void testProcessInstanceMigrationExplicitBack() throws Exception {
    ProcessInstance p = ksession.startProcess("com.sample.bpmn.migration.subprocess1");
    long pid = p.getId();
    assertEquals("com.sample.bpmn.migration.subprocess1", ksession.getProcessInstance(pid).getProcessId());
    List<TaskSummary> list = assertTaskAssignedTo("john");
    completeTask(list.get(0));
    Map<String, String> mapping = new HashMap<String, String>();
    mapping.put("ForJohn2", "ForJohn1");
    ExplicitUpgradeCommand c = new ExplicitUpgradeCommand(pid, mapping, "com.sample.bpmn.migration.subprocess2");
    ksession.execute(c);
    list = assertTaskAssignedTo("john");
    completeTask(list.get(0));
    list = assertTaskAssignedTo("mary");
    assertDefinitionChanged(pid, "com.sample.bpmn.migration.subprocess2", false);
}
Also used : HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test)

Example 88 with TaskSummary

use of org.kie.api.task.model.TaskSummary 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 89 with TaskSummary

use of org.kie.api.task.model.TaskSummary 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 90 with TaskSummary

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

the class AdminAPIsWithListenerTest method automaticCleanUpTest.

@SuppressWarnings("unchecked")
@Test
public void automaticCleanUpTest() 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));
    // let check how many listeners we have
    assertEquals(2, ((EventService<TaskLifeCycleEventListener>) taskService).getTaskEventListeners().size());
    assertEquals(2, ((EventService<TaskLifeCycleEventListener>) taskService).getTaskEventListeners().size());
    logger.info("### Starting process ###");
    Map<String, Object> parameters = new HashMap<String, Object>();
    ProcessInstance process = ksession.startProcess("org.jbpm.PatientAppointment", parameters);
    // 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);
    // tasks for manager
    managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    assertEquals(1, managerTasks.size());
    taskService.start(managerTasks.get(0).getId(), "manager");
    taskService.complete(managerTasks.get(0).getId(), "manager", null);
    // 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) EventService(org.kie.internal.task.api.EventService) 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)

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