Search in sources :

Example 46 with TaskService

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

the class BoundaryErrorMultiInstanceProcessTest method simpleSupportProcessTest.

@Test
public void simpleSupportProcessTest() {
    createRuntimeManager("org/jbpm/test/functional/event/BoundaryErrorMultiInstanceProcess.bpmn2");
    RuntimeEngine runtimeEngine = getRuntimeEngine();
    KieSession ksession = runtimeEngine.getKieSession();
    TaskService taskService = runtimeEngine.getTaskService();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approvers", new String[] { "salaboy", "mary" });
    ProcessInstance processInstance = ksession.startProcess("boundary-catch-error-event", params);
    assertProcessInstanceActive(processInstance.getId());
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary dataEntryTask = tasks.get(0);
    taskService.start(dataEntryTask.getId(), "john");
    taskService.complete(dataEntryTask.getId(), "john", null);
    tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(1, tasks.size());
    tasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasks.size());
    // signal to terminate subprocess
    ksession.signalEvent("Terminate", null, processInstance.getId());
    tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(0, tasks.size());
    tasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(0, tasks.size());
    // second round ...
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    dataEntryTask = tasks.get(0);
    taskService.start(dataEntryTask.getId(), "john");
    taskService.complete(dataEntryTask.getId(), "john", null);
    tasks = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary maryTask = tasks.get(0);
    taskService.start(maryTask.getId(), "mary");
    taskService.complete(maryTask.getId(), "mary", null);
    tasks = taskService.getTasksAssignedAsPotentialOwner("salaboy", "en-UK");
    assertEquals(1, tasks.size());
    TaskSummary salaboyTask = tasks.get(0);
    taskService.start(salaboyTask.getId(), "salaboy");
    taskService.complete(salaboyTask.getId(), "salaboy", null);
    assertProcessInstanceCompleted(processInstance.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 47 with TaskService

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

the class ConcurrentGlobalTimerServiceTest method testSessionPerProcessInstance.

@Test
public void testSessionPerProcessInstance() throws Exception {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
    long startTimeStamp = System.currentTimeMillis();
    long maxEndTime = startTimeStamp + maxWaitTime;
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    // prepare task service with users and groups
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    TaskService taskService = engine.getTaskService();
    Group grouphr = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) grouphr).setId("HR");
    User mary = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) mary).setId("mary");
    User john = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) john).setId("john");
    ((InternalTaskService) taskService).addGroup(grouphr);
    ((InternalTaskService) taskService).addUser(mary);
    ((InternalTaskService) taskService).addUser(john);
    manager.disposeRuntimeEngine(engine);
    completedStart = 0;
    for (int i = 0; i < nbThreadsProcess; i++) {
        new StartProcessPerProcessInstanceRunnable(manager, i).run();
    }
    completedTask = 0;
    for (int i = 0; i < nbThreadsTask; i++) {
        new Thread(new CompleteTaskPerProcessInstanceRunnable(manager, i)).start();
    }
    while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) {
        Thread.sleep(100);
        if (System.currentTimeMillis() > maxEndTime) {
            fail("Failure, did not finish in time most likely hanging");
        }
    }
    // make sure all process instance were completed
    engine = manager.getRuntimeEngine(EmptyContext.get());
    AuditService logService = engine.getAuditService();
    // active
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
    assertNotNull(logs);
    for (ProcessInstanceLog log : logs) {
        logger.debug("Left over {}", log.getProcessInstanceId());
    }
    assertEquals(0, logs.size());
    // completed
    logs = logService.findProcessInstances("IntermediateCatchEvent");
    assertNotNull(logs);
    assertEquals(nbThreadsProcess, logs.size());
    manager.disposeRuntimeEngine(engine);
    logger.debug("Done");
}
Also used : Group(org.kie.api.task.model.Group) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) User(org.kie.api.task.model.User) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test)

Example 48 with TaskService

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

the class GlobalTimerServiceVolumeTest method testRuntimeManagerStrategyWithTimerService.

@Test(timeout = 30000)
public void testRuntimeManagerStrategyWithTimerService() throws Exception {
    // prepare task service with users and groups
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    TaskService taskService = engine.getTaskService();
    Group grouphr = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) grouphr).setId("HR");
    Group groupadmins = TaskModelProvider.getFactory().newGroup();
    ((InternalOrganizationalEntity) groupadmins).setId("Administrators");
    User mary = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) mary).setId("mary");
    User john = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) john).setId("john");
    User admin = TaskModelProvider.getFactory().newUser();
    ((InternalOrganizationalEntity) admin).setId("Administrator");
    ((InternalTaskService) taskService).addGroup(grouphr);
    ((InternalTaskService) taskService).addGroup(groupadmins);
    ((InternalTaskService) taskService).addUser(mary);
    ((InternalTaskService) taskService).addUser(john);
    ((InternalTaskService) taskService).addUser(admin);
    manager.disposeRuntimeEngine(engine);
    int counter = numberOfProcesses;
    // start processes until oom
    while (counter > 0) {
        new GlobalTimerServiceVolumeTest.StartProcessPerProcessInstanceRunnable(manager).run();
        counter--;
    }
    Collection<TimerJobInstance> timers = null;
    Map<Long, List<GlobalJobHandle>> jobs = null;
    TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
    if (timerService != null) {
        if (timerService instanceof GlobalTimerService) {
            jobs = ((GlobalTimerService) timerService).getTimerJobsPerSession();
            timers = ((GlobalTimerService) timerService).getTimerJobFactoryManager().getTimerJobInstances();
        }
    }
    assertNotNull("Jobs should not be null as number of timers have been created", jobs);
    assertEquals("There should be no jobs in the global timer service", 0, jobs.size());
    assertNotNull("Timer instances should not be null as number of timers have been created", timers);
    assertEquals("There should be no timer instances in the global timer service manager", 0, timers.size());
    RuntimeEngine empty = manager.getRuntimeEngine(EmptyContext.get());
    AuditService logService = empty.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
    assertEquals("Active process instances should be " + numberOfProcesses, numberOfProcesses, logs.size());
    countDownListener.waitTillCompleted();
    List<TaskSummary> tasks = empty.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals("Number of John's tasks should be " + numberOfProcesses, numberOfProcesses, tasks.size());
    for (TaskSummary task : tasks) {
        RuntimeEngine piEngine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
        piEngine.getTaskService().start(task.getId(), "john");
        piEngine.getTaskService().complete(task.getId(), "john", null);
        manager.disposeRuntimeEngine(piEngine);
    }
    logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
    assertEquals("Active process instances should be 0", 0, logs.size());
    logService.dispose();
    manager.disposeRuntimeEngine(empty);
}
Also used : Group(org.kie.api.task.model.Group) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) User(org.kie.api.task.model.User) TimerJobInstance(org.drools.core.time.impl.TimerJobInstance) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) InternalTaskService(org.kie.internal.task.api.InternalTaskService) InternalOrganizationalEntity(org.kie.internal.task.api.model.InternalOrganizationalEntity) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) TimerService(org.drools.core.time.TimerService) TaskSummary(org.kie.api.task.model.TaskSummary) List(java.util.List) ArrayList(java.util.ArrayList) AuditService(org.kie.api.runtime.manager.audit.AuditService) GlobalTimerService(org.jbpm.process.core.timer.impl.GlobalTimerService) Test(org.junit.Test)

Example 49 with TaskService

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

the class ProcessKModuleMain method main.

public static void main(String[] args) {
    RuntimeManager manager = createRuntimeManager();
    RuntimeEngine engine = manager.getRuntimeEngine(null);
    KieSession ksession = engine.getKieSession();
    TaskService taskService = engine.getTaskService();
    ksession.startProcess("com.sample.bpmn.hello");
    // let john execute Task 1
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task = list.get(0);
    System.out.println("John is executing task " + task.getName());
    taskService.start(task.getId(), "john");
    taskService.complete(task.getId(), "john", null);
    // let mary execute Task 2
    list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
    task = list.get(0);
    System.out.println("Mary is executing task " + task.getName());
    taskService.start(task.getId(), "mary");
    taskService.complete(task.getId(), "mary", null);
    manager.disposeRuntimeEngine(engine);
    System.exit(0);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession)

Example 50 with TaskService

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

the class HumanTaskResolver method run.

@Override
public void run() {
    System.out.println(pid + " running tasks");
    // "sales-rep" reviews request
    TaskService taskService1 = getTaskService();
    List<TaskSummary> tasks1 = taskService1.getTasksAssignedAsPotentialOwner("sales", "en-UK");
    TaskSummary task1 = selectTaskForProcessInstance(tasks1);
    System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
    taskService1.claim(task1.getId(), "sales-rep");
    taskService1.start(task1.getId(), "sales-rep");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("comment", "Agreed, existing laptop needs replacing");
    results.put("outcome", "Accept");
    taskService1.complete(task1.getId(), "sales-rep", results);
    TaskService taskService2 = getTaskService();
    // "krisv" approves result
    List<TaskSummary> tasks2 = taskService2.getTasksAssignedAsPotentialOwner("krisv", "en-UK");
    TaskSummary task2 = selectTaskForProcessInstance(tasks2);
    System.out.println("krisv executing task " + task2.getName() + "(" + task2.getId() + ": " + task2.getDescription() + ")");
    taskService2.start(task2.getId(), "krisv");
    results = new HashMap<String, Object>();
    results.put("outcome", "Agree");
    taskService2.complete(task2.getId(), "krisv", results);
    TaskService taskService3 = getTaskService();
    // "john" as manager reviews request
    List<TaskSummary> tasks3 = taskService3.getTasksAssignedAsPotentialOwner("john", "en-UK");
    TaskSummary task3 = selectTaskForProcessInstance(tasks3);
    System.out.println("john executing task " + task3.getName() + "(" + task3.getId() + ": " + task3.getDescription() + ")");
    taskService3.claim(task3.getId(), "john");
    taskService3.start(task3.getId(), "john");
    results = new HashMap<String, Object>();
    results.put("outcome", "Agree");
    taskService3.complete(task3.getId(), "john", results);
    TaskService taskService4 = getTaskService();
    // "sales-rep" gets notification
    List<TaskSummary> tasks4 = taskService4.getTasksAssignedAsPotentialOwner("sales-rep", "en-UK");
    TaskSummary task4 = selectTaskForProcessInstance(tasks4);
    System.out.println("sales-rep executing task " + task4.getName() + "(" + task4.getId() + ": " + task4.getDescription() + ")");
    taskService4.start(task4.getId(), "sales-rep");
    Task task = taskService4.getTaskById(task4.getId());
    Content content = taskService4.getContentById(task.getTaskData().getDocumentContentId());
    Object result = ContentMarshallerHelper.unmarshall(content.getContent(), null);
    Assert.assertNotNull(result);
    taskService4.complete(task4.getId(), "sales-rep", null);
    System.out.println("Process instance completed");
    runtime.close();
    latch.countDown();
}
Also used : Task(org.kie.api.task.model.Task) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) Content(org.kie.api.task.model.Content) TaskSummary(org.kie.api.task.model.TaskSummary)

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