use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class AuditCommandsTest method testFindProcessInstanceCommands.
@Test
public void testFindProcessInstanceCommands() throws Exception {
String processId = "IntermediateCatchEvent";
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchEventSignal.bpmn2");
KieSession ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
ProcessInstance processInstance = ksession.startProcess(processId);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
Command<?> cmd = new FindProcessInstancesCommand();
Object result = ksession.execute(cmd);
assertNotNull("Command result is empty!", result);
assertTrue(result instanceof List);
List<ProcessInstanceLog> logList = (List<ProcessInstanceLog>) result;
assertEquals("Log list size is incorrect.", 1, logList.size());
ProcessInstanceLog log = logList.get(0);
assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId());
assertEquals(log.getProcessId(), processInstance.getProcessId());
cmd = new FindActiveProcessInstancesCommand(processId);
result = ksession.execute(cmd);
assertNotNull("Command result is empty!", result);
assertTrue(result instanceof List);
logList = (List<ProcessInstanceLog>) result;
assertEquals("Log list size is incorrect.", 1, logList.size());
log = logList.get(0);
assertEquals("Process instance id", log.getProcessInstanceId().longValue(), processInstance.getId());
assertEquals("Process id", log.getProcessId(), processInstance.getProcessId());
assertEquals("Status", log.getStatus().intValue(), ProcessInstance.STATE_ACTIVE);
cmd = new FindProcessInstanceCommand(processInstance.getId());
result = ksession.execute(cmd);
assertNotNull("Command result is empty!", result);
assertTrue(result instanceof ProcessInstanceLog);
log = (ProcessInstanceLog) result;
assertEquals(log.getProcessInstanceId().longValue(), processInstance.getId());
assertEquals(log.getProcessId(), processInstance.getProcessId());
// now signal process instance
ksession = restoreSession(ksession, true);
ksession.signalEvent("MyMessage", "SomeValue", processInstance.getId());
assertProcessInstanceCompleted(processInstance.getId(), ksession);
cmd = new ClearHistoryLogsCommand();
result = ksession.execute(cmd);
assertEquals("There should be no more logs", 0, logService.findProcessInstances().size());
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class CallActivitiesWithUserTasksProcessTest method testCallActivitiesWith2ndUserTaskInSub.
@Test
public void testCallActivitiesWith2ndUserTaskInSub() throws Exception {
TaskCleanUpProcessEventListener taskListener = new TaskCleanUpProcessEventListener(null);
addWorkItemHandler("Sysout", new SystemOutWorkItemHandler());
addProcessEventListener(taskListener);
InitialContext context = new InitialContext();
UserTransaction ut = (UserTransaction) context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
RuntimeManager manager = createRuntimeManager(strategy, (String) null, "org/jbpm/test/functional/subprocess/CallActivityWithTaskInSub-Main.bpmn2", "org/jbpm/test/functional/subprocess/CallActivityWithTaskInSub-Sub.bpmn2");
RuntimeEngine runtimeEngine;
if (Strategy.SINGLETON.equals(strategy)) {
runtimeEngine = getRuntimeEngine();
} else if (Strategy.PROCESS_INSTANCE.equals(strategy)) {
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
} else {
throw new IllegalStateException("Not possible!");
}
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
// set created task service on listener
taskListener.setTaskService((InternalTaskService) taskService);
if (userManagedTx) {
ut.begin();
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("pActorId", "john");
ProcessInstance processInstance = ksession.startProcess("PolicyValueAnalysis", params);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
Long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
// sub process task
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
// sub process task
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
// since we are checking in same transaction it will already see it as completed
assertProcessInstanceCompleted(processInstance.getId());
ut.commit();
}
assertProcessInstanceCompleted(processInstance.getId());
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class CallActivitiesWithUserTasksProcessTest method testCallActivitiesWithUserTasks.
@Test
public void testCallActivitiesWithUserTasks() throws Exception {
TaskCleanUpProcessEventListener taskListener = new TaskCleanUpProcessEventListener(null);
addWorkItemHandler("Sysout", new SystemOutWorkItemHandler());
addProcessEventListener(taskListener);
InitialContext context = new InitialContext();
UserTransaction ut = (UserTransaction) context.lookup(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME);
RuntimeManager manager = createRuntimeManager(strategy, (String) null, "org/jbpm/test/functional/subprocess/CallActivityWithTask-Main.bpmn2", "org/jbpm/test/functional/subprocess/CallActivityWithTask-Sub.bpmn2");
RuntimeEngine runtimeEngine;
if (Strategy.SINGLETON.equals(strategy)) {
runtimeEngine = getRuntimeEngine();
} else if (Strategy.PROCESS_INSTANCE.equals(strategy)) {
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get());
} else {
throw new IllegalStateException("Not possible!");
}
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
// set created task service on listener
taskListener.setTaskService((InternalTaskService) taskService);
if (userManagedTx) {
ut.begin();
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("pActorId", "john");
ProcessInstance processInstance = ksession.startProcess("PolicyValueAnalysis", params);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
Long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
ut.begin();
} else {
manager.disposeRuntimeEngine(runtimeEngine);
runtimeEngine = getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
taskListener.setTaskService((InternalTaskService) taskService);
}
tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
if (userManagedTx) {
ut.commit();
ut.begin();
}
assertProcessInstanceCompleted(processInstance.getId());
if (userManagedTx) {
ut.commit();
}
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class WorkingMemoryDbLoggerWithStatefulSessionTest method startProcess.
@Override
public ProcessInstance startProcess(String processId) {
if (session == null) {
// load the process
KieBase kbase = createKnowledgeBase();
// create a new session
Properties properties = new Properties();
properties.put("drools.processInstanceManagerFactory", "org.jbpm.process.instance.impl.DefaultProcessInstanceManagerFactory");
properties.put("drools.processSignalManagerFactory", "org.jbpm.process.instance.event.DefaultSignalManagerFactory");
SessionConfiguration config = SessionConfiguration.newInstance(properties);
session = kbase.newKieSession(config, createEnvironment(context));
new JPAWorkingMemoryDbLogger(session);
session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
}
return session.startProcess(processId);
}
use of org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler in project jbpm by kiegroup.
the class AbstractAuditLogServiceTest method runTestLogger2.
public static void runTestLogger2(KieSession session, AuditLogService auditLogService) {
session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler());
// record the initial count to compare to later
List<ProcessInstanceLog> processInstances = auditLogService.findProcessInstances("com.sample.ruleflow");
int initialProcessInstanceSize = processInstances.size();
// start process instance
session.startProcess("com.sample.ruleflow");
session.startProcess("com.sample.ruleflow");
logger.debug("Checking process instances for process 'com.sample.ruleflow'");
processInstances = auditLogService.findProcessInstances("com.sample.ruleflow");
Assertions.assertThat(processInstances.size()).isEqualTo(initialProcessInstanceSize + 2);
for (ProcessInstanceLog processInstance : processInstances) {
logger.debug("{} -> {} - {}", processInstance.toString(), processInstance.getStart(), processInstance.getEnd());
List<NodeInstanceLog> nodeInstances = auditLogService.findNodeInstances(processInstance.getProcessInstanceId());
for (NodeInstanceLog nodeInstance : nodeInstances) {
logger.debug("{} -> {}", nodeInstance.toString(), nodeInstance.getDate());
}
Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
}
auditLogService.clear();
}
Aggregations