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());
}
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");
}
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);
}
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);
}
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();
}
Aggregations