use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class SerializedTimerRollbackTest method testSerizliableTestsWithEngineRollback.
@Test
public void testSerizliableTestsWithEngineRollback() {
try {
createRuntimeManager("org/jbpm/test/functional/timer/HumanTaskWithBoundaryTimer.bpmn");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
logger.debug("Created knowledge session");
TaskService taskService = runtimeEngine.getTaskService();
logger.debug("Task service created");
List<Long> committedProcessInstanceIds = new ArrayList<Long>();
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("test", "john");
logger.debug("Creating process instance: {}", i);
ProcessInstance pi = ksession.startProcess("PROCESS_1", params);
committedProcessInstanceIds.add(pi.getId());
} else {
try {
Map<String, Object> params = new HashMap<String, Object>();
// set test variable to null so engine will rollback
params.put("test", null);
logger.debug("Creating process instance: {}", i);
ksession.startProcess("PROCESS_1", params);
} catch (Exception e) {
logger.debug("Process rolled back");
}
}
}
Connection c = getDs().getConnection();
Statement st = c.createStatement();
ResultSet rs = st.executeQuery("select rulesbytearray from sessioninfo");
rs.next();
Blob b = rs.getBlob("rulesbytearray");
assertNotNull(b);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
ProtobufMarshaller marshaller = new ProtobufMarshaller(builder.newKieBase(), new MarshallingConfigurationImpl());
StatefulKnowledgeSession session = marshaller.unmarshall(b.getBinaryStream());
assertNotNull(session);
TimerManager timerManager = ((InternalProcessRuntime) ((InternalKnowledgeRuntime) session).getProcessRuntime()).getTimerManager();
assertNotNull(timerManager);
Collection<TimerInstance> timers = timerManager.getTimers();
assertNotNull(timers);
assertEquals(5, timers.size());
for (TimerInstance timerInstance : timers) {
assertTrue(committedProcessInstanceIds.contains(timerInstance.getProcessInstanceId()));
ksession.abortProcessInstance(timerInstance.getProcessInstanceId());
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, tasks.size());
} catch (Exception e) {
e.printStackTrace();
fail("Exception thrown");
}
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class RetrySyncWorkItemByJPATest method workItemRecoveryTestByJPA.
@Test
public void workItemRecoveryTestByJPA() {
manager = createRuntimeManager("org/jbpm/test/functional/workitem/retry-workitem-jpa.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
KieSession kieSession = runtimeEngine.getKieSession();
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
workItemManager.registerWorkItemHandler("ExceptionWorkitem", new ExceptionWorkItemHandler());
ProcessInstance pi = kieSession.startProcess(RETRY_WORKITEM_JPA_PROCESS_ID);
TaskService taskService = runtimeEngine.getTaskService();
assertProcessInstanceActive(pi.getId());
assertNodeTriggered(pi.getId(), "lockingNode");
assertNodeActive(pi.getId(), kieSession, "lockingNode");
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
TaskSummary taskSummary = tasks.get(0);
taskService.start(taskSummary.getId(), "john");
taskService.complete(taskSummary.getId(), "john", null);
ProcessInstance processInstance = (org.kie.api.runtime.process.WorkflowProcessInstance) kieSession.getProcessInstance(pi.getId());
Collection<NodeInstance> nis = ((org.kie.api.runtime.process.WorkflowProcessInstance) processInstance).getNodeInstances();
retryWorkItem(workItemManager, nis);
assertProcessInstanceCompleted(processInstance.getId());
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class LogCleanupCommandTest method skipTaskLog.
@Ignore
@Test(timeout = 10000)
public void skipTaskLog() throws Exception {
KieSession kieSession = null;
List<ProcessInstance> processInstanceList = null;
try {
CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
((ExecutorServiceImpl) getExecutorService()).addAsyncJobListener(countDownListener);
// Generate data
kieSession = createKSession(LOG_CLEANUP);
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("assigneeName", "krisv");
processInstanceList = startProcess(kieSession, LOG_CLEANUP_ID, paramMap, 1);
TaskService taskService = getRuntimeEngine().getTaskService();
List<Long> taskIdList = taskService.getTasksByProcessInstanceId(processInstanceList.get(0).getId());
taskService.start(taskIdList.get(0), "krisv");
taskService.complete(taskIdList.get(0), "krisv", null);
// Verify presence of data
Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isPositive();
Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isEqualTo(3);
// Schedule cleanup job
scheduleLogCleanup(false, true, false, getTomorrow(), null, LOG_CLEANUP_ID);
countDownListener.waitTillCompleted();
// Verify absence of data
Assertions.assertThat(getProcessLogSize(LOG_CLEANUP_ID)).isZero();
Assertions.assertThat(getTaskLogSize(LOG_CLEANUP_ID)).isEqualTo(1);
Assertions.assertThat(getNodeInstanceLogSize(LOG_CLEANUP_ID)).isZero();
Assertions.assertThat(getVariableLogSize(LOG_CLEANUP_ID)).isZero();
} finally {
if (processInstanceList != null) {
abortProcess(kieSession, processInstanceList);
}
}
}
use of org.kie.api.task.TaskService 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());
}
use of org.kie.api.task.TaskService in project jbpm by kiegroup.
the class HumanTaskResolver method populateOrgEntity.
@Before
public void populateOrgEntity() {
TaskService taskService = HumanTaskServiceFactory.newTaskServiceConfigurator().entityManagerFactory(getEmf()).getTaskService();
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("krisv"));
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("sales-rep"));
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("john"));
((InternalTaskService) taskService).addUser(TaskModelProvider.getFactory().newUser("Administrator"));
((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("sales"));
((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("PM"));
((InternalTaskService) taskService).addGroup(TaskModelProvider.getFactory().newGroup("Administrators"));
}
Aggregations