use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class AdminAPIsWithListenerTest method automaticCleanUpForSubProcessWithPerProcessInstanceStrategy.
@Test
public void automaticCleanUpForSubProcessWithPerProcessInstanceStrategy() throws Exception {
TaskCleanUpProcessEventListener taskCleanUpProcessEventListener = new TaskCleanUpProcessEventListener(null);
this.addProcessEventListener(taskCleanUpProcessEventListener);
RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "com.mycompany.sample", "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();
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class AdminAPIsWithListenerTest method automaticCleanUpWitCallActivityTest.
@Test
public void automaticCleanUpWitCallActivityTest() throws Exception {
createRuntimeManager("org/jbpm/test/functional/task/CallActivity.bpmn2", "org/jbpm/test/functional/task/CallActivity2.bpmn2", "org/jbpm/test/functional/task/CallActivitySubProcess.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
ksession.addEventListener(new TaskCleanUpProcessEventListener(taskService));
ProcessInstance processInstance = ksession.startProcess("ParentProcessCA");
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
assertProcessInstanceCompleted(processInstance.getId());
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();
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class ParalellLoopTest method complete.
private void complete(String user, String outcome) {
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(user, "en-UK");
TaskSummary task = list.get(0);
logger.debug("complete task");
logger.debug("- {} is executing task {}", user, task.getName());
taskService.start(task.getId(), user);
Map<String, Object> map = new HashMap<String, Object>();
map.put("OUTCOME", outcome);
taskService.complete(task.getId(), user, map);
logger.debug("- {} executed task {}", user, task.getName());
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class InclusiveGatewayWithHumanTasksProcessTest method testInclusiveGatewayWithLoopAndUserTasks.
@Test
public void testInclusiveGatewayWithLoopAndUserTasks() {
createRuntimeManager("org/jbpm/test/functional/gateway/InclusiveGatewayWithHumanTasksProcess.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
String userId = "john";
// start a new process instance
Map<String, Object> params = new HashMap<String, Object>();
params.put("firstXor", true);
params.put("secondXor", true);
params.put("thirdXor", true);
ProcessInstance pi = ksession.startProcess("InclusiveWithAdvancedLoop", params);
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
// completing first task
taskService.start(tasks.get(0).getId(), userId);
taskService.complete(tasks.get(0).getId(), userId, new HashMap<String, Object>());
// completing second task
tasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
assertNotNull(tasks);
assertEquals(2, tasks.size());
for (TaskSummary task : tasks) {
if (task.getName().equals("HT Form2")) {
taskService.start(task.getId(), userId);
taskService.complete(task.getId(), userId, new HashMap<String, Object>());
break;
}
}
List<TaskSummary> johntasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
assertNotNull(johntasks);
assertEquals(1, johntasks.size());
taskService.start(johntasks.get(0).getId(), userId);
taskService.complete(johntasks.get(0).getId(), userId, new HashMap<String, Object>());
johntasks = taskService.getTasksAssignedAsPotentialOwner(userId, "en-UK");
assertNotNull(johntasks);
assertEquals(1, johntasks.size());
taskService.start(johntasks.get(0).getId(), userId);
taskService.complete(johntasks.get(0).getId(), userId, new HashMap<String, Object>());
assertProcessInstanceCompleted(pi.getId());
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class AbstractStartProcessWithCorrelationKeyTest method testProcessesWithSameBusinessKeyNotInParallel.
@Test
public void testProcessesWithSameBusinessKeyNotInParallel() {
createRuntimeManager("org/jbpm/test/functional/correlation/humantask.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
ProcessInstance processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
assertProcessInstanceActive(processInstance.getId(), ksession);
assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
// let john execute Task 1
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
TaskSummary task = list.get(0);
logger.info("John is executing task {}", task.getName());
taskService.start(task.getId(), "john");
taskService.complete(task.getId(), "john", null);
assertNodeTriggered(processInstance.getId(), "Task 2");
ProcessInstance processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
assertNotNull(processInstanceCopy);
assertEquals(processInstance.getId(), processInstanceCopy.getId());
// let mary execute Task 2
list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
task = list.get(0);
logger.info("Mary is executing task {}", task.getName());
taskService.start(task.getId(), "mary");
taskService.complete(task.getId(), "mary", null);
assertNodeTriggered(processInstance.getId(), "End");
assertProcessInstanceNotActive(processInstance.getId(), ksession);
processInstance = ((CorrelationAwareProcessRuntime) ksession).startProcess("com.sample.bpmn.hello", getCorrelationKey(), null);
assertProcessInstanceActive(processInstance.getId(), ksession);
assertNodeTriggered(processInstance.getId(), "Start", "Task 1");
// let john execute Task 1
list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
task = list.get(0);
logger.info("John is executing task {}", task.getName());
taskService.start(task.getId(), "john");
taskService.complete(task.getId(), "john", null);
assertNodeTriggered(processInstance.getId(), "Task 2");
processInstanceCopy = ((CorrelationAwareProcessRuntime) ksession).getProcessInstance(getCorrelationKey());
assertNotNull(processInstanceCopy);
assertEquals(processInstance.getId(), processInstanceCopy.getId());
// let mary execute Task 2
list = taskService.getTasksAssignedAsPotentialOwner("mary", "en-UK");
task = list.get(0);
logger.info("Mary is executing task {}", task.getName());
taskService.start(task.getId(), "mary");
taskService.complete(task.getId(), "mary", null);
assertNodeTriggered(processInstance.getId(), "End");
assertProcessInstanceNotActive(processInstance.getId(), ksession);
}
Aggregations