use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class ProcessServiceEJBIntegrationTest method testStartProcessAndCompleteWorkItem.
@Test
public void testStartProcessAndCompleteWorkItem() {
assertNotNull(deploymentService);
KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
deploymentService.deploy(deploymentUnit);
units.add(deploymentUnit);
boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
assertTrue(isDeployed);
assertNotNull(processService);
long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
ProcessInstance pi = processService.getProcessInstance(processInstanceId);
assertNotNull(pi);
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Write a Document", activeNodes.iterator().next().getName());
Map<String, Object> outcome = new HashMap<String, Object>();
outcome.put("Result", "here is my first document");
processService.completeWorkItem(activeNodes.iterator().next().getWorkItemId(), outcome);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
assertNotNull(activeNodes);
assertEquals(2, activeNodes.size());
Object variableValue = processService.getProcessInstanceVariable(processInstanceId, "approval_document");
assertNotNull(variableValue);
assertTrue(variableValue instanceof String);
assertEquals("here is my first document", variableValue);
processService.abortProcessInstance(processInstanceId);
pi = processService.getProcessInstance(processInstanceId);
assertNull(pi);
}
use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class HumanResourcesHiringTest method testHiringProcess.
@SuppressWarnings("unchecked")
private void testHiringProcess(RuntimeManager manager, Context<?> context) {
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieSession ksession = runtime.getKieSession();
TaskService taskService = runtime.getTaskService();
assertNotNull(runtime);
assertNotNull(ksession);
ksession.getWorkItemManager().registerWorkItemHandler("EmailService", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
ksession.getWorkItemManager().registerWorkItemHandler("TwitterService", new WorkItemHandler() {
@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
manager.completeWorkItem(workItem.getId(), null);
}
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
ProcessInstance processInstance = ksession.startProcess("hiring");
Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
Collection<NodeInstanceDesc> completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(1, completedNodes.size());
List<TaskSummary> tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("HR");
TaskSummary HRInterview = tasks.get(0);
taskService.claim(HRInterview.getId(), "katy");
taskService.start(HRInterview.getId(), "katy");
Map<String, Object> hrOutput = new HashMap<String, Object>();
hrOutput.put("out_name", "salaboy");
hrOutput.put("out_age", 29);
hrOutput.put("out_mail", "salaboy@gmail.com");
hrOutput.put("out_score", 8);
taskService.complete(HRInterview.getId(), "katy", hrOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(2, completedNodes.size());
assertNotNull(processInstance);
assertNotNull(tasks);
assertEquals(1, tasks.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("IT");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary techInterview = tasks.get(0);
Task techInterviewTask = taskService.getTaskById(techInterview.getId());
Content contentById = taskService.getContentById(techInterviewTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
Map<String, Object> taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(7, taskContent.size());
assertEquals("salaboy@gmail.com", taskContent.get("in_mail"));
assertEquals(29, taskContent.get("in_age"));
assertEquals("salaboy", taskContent.get("in_name"));
taskService.claim(techInterview.getId(), "salaboy");
taskService.start(techInterview.getId(), "salaboy");
Map<String, Object> techOutput = new HashMap<String, Object>();
techOutput.put("out_skills", "java, jbpm, drools");
techOutput.put("out_twitter", "@salaboy");
techOutput.put("out_score", 8);
taskService.complete(techInterview.getId(), "salaboy", techOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(3, completedNodes.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("Accounting");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary createProposal = tasks.get(0);
Task createProposalTask = taskService.getTaskById(createProposal.getId());
contentById = taskService.getContentById(createProposalTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(6, taskContent.size());
assertEquals(8, taskContent.get("in_tech_score"));
assertEquals(8, taskContent.get("in_hr_score"));
taskService.claim(createProposal.getId(), "john");
taskService.start(createProposal.getId(), "john");
Map<String, Object> proposalOutput = new HashMap<String, Object>();
proposalOutput.put("out_offering", 10000);
taskService.complete(createProposal.getId(), "john", proposalOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(5, completedNodes.size());
tasks = ((InternalTaskService) taskService).getTasksAssignedByGroup("HR");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary signContract = tasks.get(0);
Task signContractTask = taskService.getTaskById(signContract.getId());
contentById = taskService.getContentById(signContractTask.getTaskData().getDocumentContentId());
assertNotNull(contentById);
taskContent = (Map<String, Object>) ContentMarshallerHelper.unmarshall(contentById.getContent(), null);
assertEquals(6, taskContent.size());
assertEquals(10000, taskContent.get("in_offering"));
assertEquals("salaboy", taskContent.get("in_name"));
taskService.claim(signContract.getId(), "katy");
taskService.start(signContract.getId(), "katy");
Map<String, Object> signOutput = new HashMap<String, Object>();
signOutput.put("out_signed", true);
taskService.complete(signContract.getId(), "katy", signOutput);
activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstance.getId(), new QueryContext());
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
completedNodes = runtimeDataService.getProcessInstanceHistoryCompleted(processInstance.getId(), new QueryContext());
assertNotNull(completedNodes);
assertEquals(8, completedNodes.size());
int removeAllTasks = ((InternalTaskService) taskService).removeAllTasks();
logger.debug(">>> Removed Tasks > {}", removeAllTasks);
}
use of org.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testAddSubprocessToEmptyCaseCheckCaseNodes.
@Test
public void testAddSubprocessToEmptyCaseCheckCaseNodes() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
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(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
Collection<NodeInstanceDesc> completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(0, completedNodes.size());
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocess(caseId, "UserTask", parameters);
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(2, activeNodes.size());
Map<String, NodeInstanceDesc> mappedNodes = mapNodeInstances(activeNodes);
assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(0, completedNodes.size());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertEquals(1, tasks.size());
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(2, completedNodes.size());
assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
} 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.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCaseWithActiveElements.
@Test
public void testTransitionBetweenStagesInCaseWithActiveElements() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
assertNotNull(caseId);
try {
Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
CaseStageInstance stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
Collection<NodeInstanceDesc> activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 1", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage One", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 1", activeNodes.iterator().next().getName());
caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
assertEquals("Stage Two", stage.iterator().next().getName());
assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
caseService.triggerAdHocFragment(caseId, "Task 2", data);
stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
assertNotNull(stage);
assertEquals(1, stage.size());
stageInstance = stage.iterator().next();
assertEquals("Stage Two", stageInstance.getName());
assertEquals(StageStatus.Active, stageInstance.getStatus());
activeNodes = stageInstance.getActiveNodes();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertEquals("Task 2", activeNodes.iterator().next().getName());
} 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.jbpm.services.api.model.NodeInstanceDesc in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testStartEmptyCaseWithCaseFile.
/*
* Case instance queries
*/
@Test
public void testStartEmptyCaseWithCaseFile() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
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, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertNotNull(cInstance.getCaseFile());
assertEquals("my first case", cInstance.getCaseFile().getData("name"));
Collection<CaseInstance> instances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
CaseInstance instance = instances.iterator().next();
assertNotNull(instance);
assertEquals(FIRST_CASE_ID, instance.getCaseId());
assertEquals(EMPTY_CASE_P_ID, instance.getCaseDefinitionId());
assertEquals("my first case", instance.getCaseDescription());
assertEquals(USER, instance.getOwner());
assertEquals(ProcessInstance.STATE_ACTIVE, instance.getStatus().intValue());
assertEquals(deploymentUnit.getIdentifier(), instance.getDeploymentId());
assertNotNull(instance.getStartedAt());
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicTask(FIRST_CASE_ID, caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(FIRST_CASE_ID, new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstanceDesc activeNode = activeNodes.iterator().next();
assertNotNull(activeNodes);
assertEquals("[Dynamic] First task", activeNode.getName());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("First task", task.getName());
assertEquals("test", task.getDescription());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations