use of org.jbpm.casemgmt.api.dynamic.TaskSpecification in project jbpm by kiegroup.
the class StageCompletionConditionTest method testCaseFileVariable.
@Test
public void testCaseFileVariable() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
caseService.addDataToCaseFile(caseId, "continue", true);
assertCaseInstanceActive(caseId);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary dynamicTask = tasks.get(0);
assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
use of org.jbpm.casemgmt.api.dynamic.TaskSpecification in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithDynamicSubCaseAbortMainCase.
@Test
public void testStartCaseWithDynamicSubCaseAbortMainCase() {
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", "false");
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));
caseService.cancelCase(caseId);
caseId = null;
caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(0, caseInstances.size());
caseInstances = caseRuntimeDataService.getCaseInstances(Arrays.asList(CaseStatus.CANCELLED), new QueryContext());
assertNotNull(caseInstances);
assertEquals(2, caseInstances.size());
} 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.casemgmt.api.dynamic.TaskSpecification in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithIndependentDynamicSubCaseAbortMainCase.
@Test
public void testStartCaseWithIndependentDynamicSubCaseAbortMainCase() {
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", "true");
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));
caseService.cancelCase(caseId);
caseId = HR_CASE_ID;
caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(1, caseInstances.size());
caseInstances = caseRuntimeDataService.getCaseInstances(Arrays.asList(CaseStatus.CANCELLED), new QueryContext());
assertNotNull(caseInstances);
assertEquals(1, caseInstances.size());
} 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.casemgmt.api.dynamic.TaskSpecification in project jbpm by kiegroup.
the class EscalateToAdminSLAViolationListener method afterSLAViolated.
@Override
public void afterSLAViolated(SLAViolatedEvent event) {
CaseFileInstance caseFile = getCaseFile((KieSession) event.getKieRuntime());
if (caseFile != null) {
String caseId = ((WorkflowProcessInstanceImpl) event.getProcessInstance()).getCorrelationKey();
if (caseFile.getCaseId().equals(caseId)) {
try {
Collection<OrganizationalEntity> adminAssignments = ((CaseAssignment) caseFile).getAssignments("admin");
String users = adminAssignments.stream().filter(oe -> oe instanceof User).map(oe -> oe.getId()).collect(Collectors.joining(","));
String groups = adminAssignments.stream().filter(oe -> oe instanceof Group).map(oe -> oe.getId()).collect(Collectors.joining(","));
String taskName = "SLA violation for case " + caseId;
String taskDescription = "Service Level Agreement has been violated for case " + caseId;
if (event.getNodeInstance() != null) {
taskName += "Task (" + event.getNodeInstance().getNodeName() + ") SLA violation for case " + caseId;
taskDescription += " on task " + event.getNodeInstance().getNodeName();
}
logger.debug("Case instance {} has SLA violation, escalating to administrator", caseId);
CaseService caseService = (CaseService) ServiceRegistry.get().service(ServiceRegistry.CASE_SERVICE);
TaskSpecification taskSpec = caseService.newHumanTaskSpec(taskName, taskDescription, users, groups, null);
caseService.addDynamicTask(caseId, taskSpec);
} catch (IllegalArgumentException e) {
logger.debug("There is no admin role defined in case instance {}, unable to escalate SLA violation", caseId);
}
}
}
}
use of org.jbpm.casemgmt.api.dynamic.TaskSpecification in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithDynamicSubCase.
private void testStartCaseWithDynamicSubCase(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);
assertNull(mainCaseFile.getData("CaseId"));
assertNull(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);
}
}
}
Aggregations