Search in sources :

Example 31 with TaskService

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

the class MigrationManagerTest method testRemoveActiveTask.

@Test
public void testRemoveActiveTask() {
    String activeNodeId = "_ECEDD1CE-7380-418C-B7A6-AF8ECB90B820";
    String nextNodeId = "_9EF3CAE0-D978-4E96-9C00-8A80082EB68E";
    createRuntimeManagers("migration/v1/RemoveActiveTask-v1.bpmn2", "migration/v2/RemoveActiveTask-v2.bpmn2");
    assertNotNull(managerV1);
    assertNotNull(managerV2);
    RuntimeEngine runtime = managerV1.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance pi1 = ksession.startProcess(REMOVEACTIVETASK_ID_V1);
    assertNotNull(pi1);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    managerV1.disposeRuntimeEngine(runtime);
    MigrationSpec migrationSpec = new MigrationSpec(DEPLOYMENT_ID_V1, pi1.getId(), DEPLOYMENT_ID_V2, REMOVEACTIVETASK_ID_V2);
    MigrationManager migrationManager = new MigrationManager(migrationSpec);
    MigrationReport report = migrationManager.migrate(Collections.singletonMap(activeNodeId, nextNodeId));
    assertNotNull(report);
    assertTrue(report.isSuccessful());
    assertMigratedProcessInstance(REMOVEACTIVETASK_ID_V2, pi1.getId(), ProcessInstance.STATE_ACTIVE);
    runtime = managerV2.getRuntimeEngine(EmptyContext.get());
    TaskService taskService = runtime.getTaskService();
    assertMigratedTaskAndComplete(taskService, REMOVEACTIVETASK_ID_V2, pi1.getId(), "Mapped Task");
    assertMigratedProcessInstance(REMOVEACTIVETASK_ID_V2, pi1.getId(), ProcessInstance.STATE_COMPLETED);
    managerV2.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 32 with TaskService

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

the class ParentChildMarshallingJpaTest method testProcess.

@Test
public void testProcess() throws Exception {
    emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.parent-child");
    addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "manager", "org/jbpm/test/functional/jpa/parent-child.bpmn");
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    Application application = new Application();
    application.setType("A");
    params.put("application", application);
    ProcessInstance pi = ksession.startProcess("com.sample.bpmn.hello", params);
    System.out.println("A process instance started : pid = " + pi.getId());
    TaskService taskService = runtime.getTaskService();
    assertTrue(taskService instanceof CommandBasedTaskService);
    assertTrue(((CommandBasedTaskService) taskService).getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) != null);
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    for (TaskSummary taskSummary : list) {
        System.out.println("john starts a task : taskId = " + taskSummary.getId());
        Task task = taskService.getTaskById(taskSummary.getId());
        long documentContentId = task.getTaskData().getDocumentContentId();
        Content content = taskService.getContentById(documentContentId);
        HashMap<String, Object> contents = (HashMap<String, Object>) ContentMarshallerHelper.unmarshall(content.getContent(), ksession.getEnvironment());
        Application outputApplication = (Application) contents.get("input1_application");
        Person person = new Person();
        person.setFullName("John Doe");
        outputApplication.setPerson(person);
        Map<String, Object> results = new LinkedHashMap<String, Object>();
        results.put("output1_application", outputApplication);
        taskService.start(taskSummary.getId(), "john");
        taskService.complete(taskSummary.getId(), "john", results);
    }
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    for (TaskSummary taskSummary : list) {
        System.out.println("mary starts a task : taskId = " + taskSummary.getId());
        taskService.start(taskSummary.getId(), "mary");
        taskService.complete(taskSummary.getId(), "mary", null);
    }
    manager.disposeRuntimeEngine(runtime);
    // Check!
    EntityManager em = emfDomain.createEntityManager();
    int size = em.createQuery("select i from Person i").getResultList().size();
    assertEquals(1, size);
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) JPAPlaceholderResolverStrategy(org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TaskService(org.kie.api.task.TaskService) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) LinkedHashMap(java.util.LinkedHashMap) EntityManager(javax.persistence.EntityManager) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Application(org.jbpm.test.entity.Application) Person(org.jbpm.test.entity.Person) Test(org.junit.Test)

Example 33 with TaskService

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

the class PatientVariablePersistenceStrategyTest method simplePatientMedicalRecordTest.

@Test
public void simplePatientMedicalRecordTest() throws Exception {
    Patient salaboy = new Patient("salaboy");
    MedicalRecord medicalRecord = new MedicalRecord("Last Three Years Medical Hisotry", salaboy);
    emfDomain = Persistence.createEntityManagerFactory("org.jbpm.persistence.patient.example");
    addEnvironmentEntry(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES, new ObjectMarshallingStrategy[] { new JPAPlaceholderResolverStrategy(emfDomain), new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT) });
    EntityManager em = emfDomain.createEntityManager();
    createRuntimeManager("org/jbpm/test/functional/jpa/patient-appointment.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    logger.info("### Starting process ###");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("medicalRecord", medicalRecord);
    ProcessInstance process = ksession.startProcess("org.jbpm.PatientAppointment", parameters);
    long processInstanceId = process.getId();
    // The process is in the first Human Task waiting for its completion
    Assert.assertEquals(ProcessInstance.STATE_ACTIVE, process.getState());
    List<? extends VariableInstanceLog> varLogs = runtimeEngine.getAuditService().findVariableInstances(processInstanceId, "medicalRecord");
    assertNotNull(varLogs);
    assertEquals(1, varLogs.size());
    // gets frontDesk's tasks
    List<TaskSummary> frontDeskTasks = taskService.getTasksAssignedAsPotentialOwner("frontDesk", "en-UK");
    Assert.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");
    // frontDesk completes its task
    MedicalRecord taskMedicalRecord = getTaskContent(runtimeEngine, frontDeskTasks.get(0));
    assertNotNull(taskMedicalRecord.getId());
    taskMedicalRecord.setDescription("Initial Description of the Medical Record");
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("output1", taskMedicalRecord);
    taskService.complete(frontDeskTasks.get(0).getId(), "frontDesk", output);
    varLogs = runtimeEngine.getAuditService().findVariableInstances(processInstanceId, "medicalRecord");
    assertNotNull(varLogs);
    assertEquals(2, varLogs.size());
    assertTrue(varLogs.get(0).getValue().contains("Last Three Years Medical Hisotry"));
    assertTrue(varLogs.get(1).getValue().contains("Initial Description of the Medical Record"));
    // Now doctor has 1 task
    doctorTasks = taskService.getTasksAssignedAsPotentialOwner("doctor", "en-UK");
    Assert.assertEquals(1, doctorTasks.size());
    // No tasks for manager yet
    managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertTrue(managerTasks.isEmpty());
    // modify the entity from outside
    taskMedicalRecord.setDescription("Initial Description of the Medical Record - Updated");
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    try {
        ut.begin();
        em.merge(taskMedicalRecord);
        ut.commit();
    } catch (Exception ex) {
        ut.rollback();
        throw ex;
    }
    taskMedicalRecord = getTaskContent(runtimeEngine, doctorTasks.get(0));
    assertNotNull(taskMedicalRecord.getId());
    taskMedicalRecord.setDescription("Initial Description of the Medical Record - Updated");
    taskService.start(doctorTasks.get(0).getId(), "doctor");
    // Check that we have the Modified Document
    taskMedicalRecord = em.find(MedicalRecord.class, taskMedicalRecord.getId());
    Assert.assertEquals("Initial Description of the Medical Record - Updated", taskMedicalRecord.getDescription());
    taskMedicalRecord.setDescription("Medical Record Validated by Doctor");
    List<RecordRow> rows = new ArrayList<RecordRow>();
    RecordRow recordRow = new RecordRow("CODE-999", "Just a regular Cold");
    recordRow.setMedicalRecord(medicalRecord);
    rows.add(recordRow);
    taskMedicalRecord.setRows(rows);
    taskMedicalRecord.setPriority(1);
    output = new HashMap<String, Object>();
    output.put("output2", taskMedicalRecord);
    taskService.complete(doctorTasks.get(0).getId(), "doctor", output);
    // tasks for manager
    managerTasks = taskService.getTasksAssignedAsPotentialOwner("manager", "en-UK");
    Assert.assertEquals(1, managerTasks.size());
    taskService.start(managerTasks.get(0).getId(), "manager");
    Patient patient = taskMedicalRecord.getPatient();
    patient.setNextAppointment(new Date());
    output = new HashMap<String, Object>();
    output.put("output3", taskMedicalRecord);
    // ksession.getWorkItemManager().registerWorkItemHandler("Human Task", htHandler);
    taskService.complete(managerTasks.get(0).getId(), "manager", output);
    // since persisted process instance is completed it should be null
    process = ksession.getProcessInstance(process.getId());
    Assert.assertNull(process);
}
Also used : SerializablePlaceholderResolverStrategy(org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy) UserTransaction(javax.transaction.UserTransaction) JPAPlaceholderResolverStrategy(org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RecordRow(org.jbpm.test.entity.RecordRow) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) Patient(org.jbpm.test.entity.Patient) MedicalRecord(org.jbpm.test.entity.MedicalRecord) IOException(java.io.IOException) Date(java.util.Date) 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 34 with TaskService

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

the class TaskLogCleanTest method testDeleteLogsByProcessName.

@Test
public void testDeleteLogsByProcessName() {
    kieSession = createKSession(HUMAN_TASK);
    processInstanceList = startProcess(kieSession, HUMAN_TASK_ID, 3);
    abortProcess(kieSession, processInstanceList);
    int resultCount = taskAuditService.auditTaskDelete().processInstanceId(processInstanceList.get(0).getId(), processInstanceList.get(1).getId()).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(2);
    TaskService taskService = getRuntimeEngine().getTaskService();
    List<Long> taskIdList = taskService.getTasksByProcessInstanceId(processInstanceList.get(2).getId());
    Assertions.assertThat(taskIdList).hasSize(1);
}
Also used : TaskService(org.kie.api.task.TaskService) Test(org.junit.Test)

Example 35 with TaskService

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

the class TaskLogCleanTest method testDeleteTaskEventByDate.

@Test
public void testDeleteTaskEventByDate() {
    kieSession = createKSession(HUMAN_TASK_MULTIACTORS);
    Date startDate = new Date();
    processInstanceList = startProcess(kieSession, HUMAN_TASK_MULTIACTORS_ID, 1);
    // Get the task
    TaskService taskService = getRuntimeEngine().getTaskService();
    Task task = taskService.getTaskById(taskService.getTasksByProcessInstanceId(processInstanceList.get(0).getId()).get(0));
    Assertions.assertThat(task).isNotNull();
    Assertions.assertThat(task.getTaskData().getStatus()).isEqualTo(Status.Ready);
    // Perform 2 operation on the task
    taskService.claim(task.getId(), "krisv");
    taskService.start(task.getId(), "krisv");
    taskService.complete(task.getId(), "krisv", null);
    // Remove the instance from the running list as it has ended already.
    processInstanceList.clear();
    // Delete all task operation between dates
    int resultCount = taskAuditService.taskEventInstanceLogDelete().dateRangeStart(startDate).dateRangeEnd(new Date()).build().execute();
    // Changes are as follows (see https://docs.jboss.org/jbpm/v6.1/userguide/jBPMTaskService.html#jBPMTaskLifecycle):
    // 1) Created -> Ready (automatic change because there are multiple actors)
    // 2) Ready -> Reserved (by claim)
    // 3) Reserved -> In Progress (by start)
    // 4) In Progress -> Completed (by complete)
    Assertions.assertThat(resultCount).isEqualTo(4);
}
Also used : Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) TaskService(org.kie.api.task.TaskService) Date(java.util.Date) Test(org.junit.Test)

Aggregations

TaskService (org.kie.api.task.TaskService)129 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)111 KieSession (org.kie.api.runtime.KieSession)79 Test (org.junit.Test)73 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)70 TaskSummary (org.kie.api.task.model.TaskSummary)66 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)53 InternalTaskService (org.kie.internal.task.api.InternalTaskService)52 HashMap (java.util.HashMap)41 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)39 UserTaskService (org.jbpm.services.api.UserTaskService)38 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34 ArrayList (java.util.ArrayList)17 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)17 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15 Task (org.kie.api.task.model.Task)14 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)12 BZ (qa.tools.ikeeper.annotation.BZ)10 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)9