use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithIndependentDynamicSubCase.
private void testStartCaseWithIndependentDynamicSubCase(String idependent, Consumer<String> finishCase) {
Map<String, Object> data = new HashMap<>();
data.put("name", "John Doe");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> parameters = new HashMap<>();
parameters.put("CaseDefinitionId", "UserTaskCase");
parameters.put("DeploymentId", deploymentUnit.getIdentifier());
parameters.put("UserRole_owner", "john");
parameters.put("Data_s", "#{name}");
parameters.put("Independent", idependent);
TaskSpecification taskSpecification = caseService.newTaskSpec("StartCaseInstance", "Sub Case", parameters);
caseService.addDynamicTask(caseId, taskSpecification);
Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(2, caseInstances.size());
Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
assertTrue(byCaseId.containsKey(FIRST_CASE_ID));
assertTrue(byCaseId.containsKey(HR_CASE_ID));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
assertEquals("John Doe", mainCaseFile.getData("s"));
finishCase.accept(HR_CASE_ID);
mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
assertEquals("John Doe", mainCaseFile.getData("s"));
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class KjarRuntimeEnvironmentTest method testUserTaskFromKjar.
@Test
public void testUserTaskFromKjar() {
KieServices ks = KieServices.Factory.get();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params);
List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
engine.getTaskService().start(taskId, "john");
engine.getTaskService().complete(taskId, "john", null);
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
manager.disposeRuntimeEngine(engine);
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class KjarRuntimeEnvironmentTest method testUserTaskFromKjarPPI.
@Test
public void testUserTaskFromKjarPPI() {
KieServices ks = KieServices.Factory.get();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION)).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
Map<String, Object> params = new HashMap<String, Object>();
ProcessInstance processInstance = engine.getKieSession().startProcess("UserTask", params);
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
List<TaskSummary> tasks = engine.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
engine.getTaskService().start(taskId, "john");
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
engine.getTaskService().complete(taskId, "john", null);
manager.disposeRuntimeEngine(engine);
try {
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
fail("Should fail as process instance is already completed");
} catch (Exception e) {
}
manager.disposeRuntimeEngine(engine);
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class TimerInitFailureRuntimeManagerTest method testPerCaseRuntimeManager.
@Test(timeout = 10000)
@BMScript(value = "byteman-scripts/failOnRuntimeManagerInitRules.btm")
public void testPerCaseRuntimeManager() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Intermediate Catch Event 1", 1);
RuntimeEnvironment environment = createEnvironment(countDownListener);
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<>();
ProcessInstance pi = ksession.startProcess("TimerInitFailure", params);
assertEquals(ProcessInstance.STATE_ACTIVE, pi.getState());
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
// User access
runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
runtime.getKieSession();
TaskService taskService = runtime.getTaskService();
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, list.size());
long taskId = list.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
AuditService auditService = runtime.getAuditService();
ProcessInstanceLog log = auditService.findProcessInstance(pi.getId());
assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
auditService.dispose();
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.
the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.
@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
Map<String, String> resources = new HashMap<String, String>();
String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
String drl = "package org.jbpm; global java.util.List service; " + " rule \"Start Hello1\"" + " when" + " then" + " System.out.println(\"Hello\");" + " end";
resources.put("src/main/resources/simple.drl", drl);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
installKjar(releaseId, kJar1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
assertNotNull(factory);
assertTrue(factory instanceof InternalRegisterableItemsFactory);
assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
assertEquals(1, descriptor.getMarshallingStrategies().size());
// assertEquals(1, descriptor.getConfiguration().size());
assertEquals(1, descriptor.getEnvironmentEntries().size());
assertEquals(1, descriptor.getEventListeners().size());
assertEquals(1, descriptor.getGlobals().size());
assertEquals(1, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(0, descriptor.getRequiredRoles().size());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
KieSession kieSession = engine.getKieSession();
// configuration
assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
assertNotNull(bc);
assertTrue(bc instanceof TestBusinessCalendar);
// globals
Object service = kieSession.getGlobal("service");
assertNotNull(service);
assertTrue(service instanceof ArrayList);
// work item handler
ProcessInstance processInstance = kieSession.startProcess("ManualTask");
long processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
assertNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// process event listener
assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
processEvents.clear();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// task event listener
processInstance = kieSession.startProcess("UserTask");
processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// marshalling strategy
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "marshal");
processInstance = kieSession.startProcess("ParentProcess", params);
processInstanceId = processInstance.getId();
ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
assertNotNull(pi);
String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
manager.disposeRuntimeEngine(engine);
}
Aggregations