use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.
the class CaseServiceImpl method closeCase.
@Override
public void closeCase(String caseId, String comment) throws CaseNotFoundException {
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.CLOSE_CASE);
logger.debug("About to close case {} with comment {}", caseId, comment);
ProcessInstanceDesc pi = verifyCaseIdExists(caseId);
processService.execute(pi.getDeploymentId(), ProcessInstanceIdContext.get(pi.getId()), new CloseCaseCommand(identityProvider, pi.getDeploymentId(), caseId, comment, processService, runtimeDataService));
}
use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.
the class CaseServiceImpl method destroyCase.
@Override
public void destroyCase(String caseId) throws CaseNotFoundException {
authorizationManager.checkOperationAuthorization(caseId, ProtectedOperation.DESTROY_CASE);
logger.debug("About to destroy permanently case {}", caseId);
ProcessInstanceDesc pi = verifyCaseIdExisted(caseId);
processService.execute(pi.getDeploymentId(), ProcessInstanceIdContext.get(pi.getId()), new CancelCaseCommand(identityProvider, caseId, processService, runtimeDataService, true));
}
use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddUserTaskToEmptyCase.
@Test
public void testAddUserTaskToEmptyCase() {
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());
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
parameters.put("variable", "#{name}");
caseService.addDynamicTask(FIRST_CASE_ID, caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertTask(task, "john", "First task", Status.Reserved);
assertEquals("test", task.getDescription());
Map<String, Object> inputs = userTaskService.getTaskInputContentByTaskId(task.getId());
assertNotNull(inputs);
assertEquals("my first case", inputs.get("variable"));
String nameVar = (String) processService.getProcessInstanceVariable(task.getProcessInstanceId(), "name");
assertNotNull(nameVar);
assertEquals("my first case", nameVar);
userTaskService.start(task.getId(), "john");
Map<String, Object> outcome = new HashMap<>();
outcome.put("name", "updated by dynamic task");
userTaskService.complete(task.getId(), "john", outcome);
nameVar = (String) processService.getProcessInstanceVariable(task.getProcessInstanceId(), "name");
assertNotNull(nameVar);
assertEquals("updated by dynamic task", nameVar);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(1, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
caseService.addDynamicTask(casePI.getId(), caseService.newHumanTaskSpec("Second task", "another test", "mary", null, parameters));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertTask(task, "mary", "Second task", Status.Reserved);
assertEquals("another test", task.getDescription());
// User john cannot work with task assigned to mary
try {
userTaskService.start(task.getId(), "john");
} catch (TaskNotFoundException e) {
// expected
}
userTaskService.start(task.getId(), "mary");
userTaskService.complete(task.getId(), "mary", null);
Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
assertNotNull(nodes);
assertEquals(4, nodes.size());
Map<String, String> nodesByName = nodes.stream().collect(toMap(NodeInstanceDesc::getName, NodeInstanceDesc::getNodeType));
assertTrue(nodesByName.containsKey("StartProcess"));
assertTrue(nodesByName.containsKey("EndProcess"));
assertTrue(nodesByName.containsKey("[Dynamic] First task"));
assertTrue(nodesByName.containsKey("[Dynamic] Second task"));
assertEquals("StartNode", nodesByName.get("StartProcess"));
assertEquals("EndNode", nodesByName.get("EndProcess"));
assertEquals("Human Task", nodesByName.get("[Dynamic] First task"));
assertEquals("Human Task", nodesByName.get("[Dynamic] Second task"));
} 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.ProcessInstanceDesc in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddServiceTaskToEmptyCase.
@Test
public void testAddServiceTaskToEmptyCase() {
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<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(1, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
String nameVar = (String) processService.getProcessInstanceVariable(casePI.getId(), "name");
assertNotNull(nameVar);
assertEquals("my first case", nameVar);
// add dynamic service task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
parameters.put("Interface", EchoService.class.getName());
parameters.put("Operation", "echo");
parameters.put("ParameterType", String.class.getName());
parameters.put("Parameter", "testing dynamic service task");
caseService.addDynamicTask(FIRST_CASE_ID, caseService.newTaskSpec("Service Task", "task 1", parameters));
nameVar = (String) processService.getProcessInstanceVariable(casePI.getId(), "name");
assertNotNull(nameVar);
assertEquals("testing dynamic service task echoed by service", nameVar);
// second dynamic service task add by process instance id
parameters.put("Parameter", "testing dynamic service task 2");
caseService.addDynamicTask(casePI.getId(), caseService.newTaskSpec("Service Task", "task 2", parameters));
nameVar = (String) processService.getProcessInstanceVariable(casePI.getId(), "name");
assertNotNull(nameVar);
assertEquals("testing dynamic service task 2 echoed by service", nameVar);
Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
assertNotNull(nodes);
assertEquals(4, nodes.size());
Map<String, String> nodesByName = nodes.stream().collect(toMap(NodeInstanceDesc::getName, NodeInstanceDesc::getNodeType));
assertTrue(nodesByName.containsKey("StartProcess"));
assertTrue(nodesByName.containsKey("EndProcess"));
assertTrue(nodesByName.containsKey("[Dynamic] task 1"));
assertTrue(nodesByName.containsKey("[Dynamic] task 2"));
assertEquals("StartNode", nodesByName.get("StartProcess"));
assertEquals("EndNode", nodesByName.get("EndProcess"));
assertEquals("Service Task", nodesByName.get("[Dynamic] task 1"));
assertEquals("Service Task", nodesByName.get("[Dynamic] task 2"));
} 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.ProcessInstanceDesc in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartProcessWithSubCaseDestroySubCase.
@Test
public void testStartProcessWithSubCaseDestroySubCase() {
Long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), PROCESS_TO_CASE_P_ID);
assertNotNull(processInstanceId);
try {
// check if case was created from within the process
CaseInstance cInstance = caseService.getCaseInstance(HR_CASE_ID);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> processVariables = processService.getProcessInstanceVariables(processInstanceId);
assertNull(processVariables.get("CaseId"));
assertNull(processVariables.get("outcome"));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
caseService.destroyCase(HR_CASE_ID);
processVariables = processService.getProcessInstanceVariables(processInstanceId);
assertEquals(HR_CASE_ID, processVariables.get("CaseId"));
assertEquals("process2case", processVariables.get("outcome"));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Verify case results", tasks.get(0).getName());
Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(tasks.get(0).getId());
assertEquals(HR_CASE_ID, taskInputs.get("CaseId"));
assertEquals("process2case", taskInputs.get("outcome"));
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
ProcessInstanceDesc piLog = runtimeDataService.getProcessInstanceById(processInstanceId);
assertNotNull(piLog);
assertEquals(ProcessInstance.STATE_COMPLETED, piLog.getState().intValue());
processInstanceId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (processInstanceId != null) {
processService.abortProcessInstance(processInstanceId);
}
}
}
Aggregations