Search in sources :

Example 26 with InternalTaskService

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

the class TaskCleanUpProcessEventListener method afterProcessCompleted.

@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Error);
    statuses.add(Status.Failed);
    statuses.add(Status.Obsolete);
    statuses.add(Status.Suspended);
    statuses.add(Status.Completed);
    statuses.add(Status.Exited);
    List<TaskSummary> completedTasksByProcessId = ((InternalTaskService) taskService).execute(new GetTasksForProcessCommand(event.getProcessInstance().getId(), statuses, "en-UK"));
    // archive and remove
    taskService.archiveTasks(completedTasksByProcessId);
    taskService.removeTasks(completedTasksByProcessId);
}
Also used : Status(org.kie.api.task.model.Status) GetTasksForProcessCommand(org.jbpm.services.task.commands.GetTasksForProcessCommand) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) InternalTaskService(org.kie.internal.task.api.InternalTaskService)

Example 27 with InternalTaskService

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

the class AuditTaskDeleteTest method produceTaskInstances.

private void produceTaskInstances() {
    InternalTaskService taskService = (InternalTaskService) HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(emf).listener(new JPATaskLifeCycleEventListener(true)).listener(new BAMTaskEventListener(true)).getTaskService();
    Calendar cal = randomCal();
    String processId = "process";
    taskTestData = new Task[10];
    List<ProcessInstanceLog> pLogs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Task task = new TaskFluent().setName("This is my task name").addPotentialGroup("Knights Templer").setAdminUser("Administrator").setProcessId(processId + i).setProcessInstanceId(i).setCreatedOn(cal.getTime()).getTask();
        taskService.addTask(task, new HashMap<String, Object>());
        taskTestData[i] = task;
        ProcessInstanceLog plog = buildCompletedProcessInstance(i);
        pLogs.add(plog);
    }
    StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
    EntityManager em = jtaHelper.getEntityManager();
    Object tx = jtaHelper.joinTransaction(em);
    pLogs.forEach(pl -> {
        em.persist(pl);
    });
    jtaHelper.leaveTransaction(em, tx);
}
Also used : StandaloneJtaStrategy(org.jbpm.process.audit.strategy.StandaloneJtaStrategy) Task(org.kie.api.task.model.Task) AuditTask(org.kie.internal.task.api.AuditTask) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) TaskFluent(org.jbpm.services.task.utils.TaskFluent) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ArrayList(java.util.ArrayList) InternalTaskService(org.kie.internal.task.api.InternalTaskService) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) EntityManager(javax.persistence.EntityManager) ProcessInstanceLog(org.jbpm.process.audit.ProcessInstanceLog)

Example 28 with InternalTaskService

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

the class DefaultChecklistManager method updateTaskPriority.

public void updateTaskPriority(long taskId, int priority) {
    RuntimeEngine runtime = getRuntime();
    ((InternalTaskService) runtime.getTaskService()).setPriority(taskId, priority);
    manager.disposeRuntimeEngine(runtime);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalTaskService(org.kie.internal.task.api.InternalTaskService)

Example 29 with InternalTaskService

use of org.kie.internal.task.api.InternalTaskService 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 30 with InternalTaskService

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

the class SupportProcessTest method simpleSupportProcessTest.

@Test
public void simpleSupportProcessTest() {
    createRuntimeManager("org/jbpm/test/functional/jpa/support.bpmn");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("customer", "salaboy");
    ProcessInstance processInstance = ksession.startProcess("support.process", params);
    assertProcessInstanceActive(processInstance.getId());
    assertProcessVarExists(processInstance, "customer");
    // Configure Release
    List<TaskSummary> tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertNodeTriggered(processInstance.getId(), "Create Support");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Create Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary createSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(createSupportTask.getId(), "salaboy");
    Map<String, Object> taskContent = ((InternalTaskService) taskService).getTaskContent(createSupportTask.getId());
    assertEquals("salaboy", taskContent.get("input_customer"));
    Map<String, Object> output = new HashMap<String, Object>();
    output.put("output_customer", "salaboy/redhat");
    taskService.complete(createSupportTask.getId(), "salaboy", output);
    assertNodeTriggered(processInstance.getId(), "Resolve Support");
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Resolve Support", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary resolveSupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(resolveSupportTask.getId(), "salaboy");
    taskService.complete(resolveSupportTask.getId(), "salaboy", null);
    assertNodeTriggered(processInstance.getId(), "Notify Customer");
    tasksAssignedToSalaboy = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasksAssignedToSalaboy.size());
    assertEquals("Notify Customer", tasksAssignedToSalaboy.get(0).getName());
    TaskSummary notifySupportTask = tasksAssignedToSalaboy.get(0);
    taskService.start(notifySupportTask.getId(), "salaboy");
    output = new HashMap<String, Object>();
    output.put("output_solution", "solved today");
    taskService.complete(notifySupportTask.getId(), "salaboy", output);
    assertProcessInstanceCompleted(processInstance.getId());
}
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) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalTaskService(org.kie.internal.task.api.InternalTaskService) Test(org.junit.Test)

Aggregations

InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)35 TaskService (org.kie.api.task.TaskService)27 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)25 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)20 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)18 UserTaskService (org.jbpm.services.api.UserTaskService)17 TaskSummary (org.kie.api.task.model.TaskSummary)13 Test (org.junit.Test)12 KieSession (org.kie.api.runtime.KieSession)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)9 Task (org.kie.api.task.model.Task)5 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)4 AuditService (org.kie.api.runtime.manager.audit.AuditService)4 I18NText (org.kie.api.task.model.I18NText)4 Date (java.util.Date)3 EntityManager (javax.persistence.EntityManager)3 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)3