use of org.jbpm.casemgmt.api.model.instance.CaseStageInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testUserTaskToCaseWithStageCompleteCaseDataItem.
@Test
public void testUserTaskToCaseWithStageCompleteCaseDataItem() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_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<CaseFileItem> caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
assertNotNull(caseFileItems);
assertEquals(0, caseFileItems.size());
Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
assertNotNull(activeStages);
assertEquals(1, activeStages.size());
caseService.addDataToCaseFile(caseId, "dataComplete", true);
activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
assertNotNull(activeStages);
assertEquals(0, activeStages.size());
caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
assertNotNull(caseFileItems);
assertEquals(1, caseFileItems.size());
CaseFileItem dataItem = caseFileItems.iterator().next();
assertNotNull(dataItem);
assertEquals(caseId, dataItem.getCaseId());
assertEquals("dataComplete", dataItem.getName());
assertEquals("true", dataItem.getValue());
assertEquals(Boolean.class.getName(), dataItem.getType());
assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
assertNotNull(dataItem.getLastModified());
caseService.addDataToCaseFile(caseId, "anotherDataItem", "first version");
caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
assertNotNull(caseFileItems);
assertEquals(2, caseFileItems.size());
dataItem = caseFileItems.iterator().next();
assertNotNull(dataItem);
assertEquals(caseId, dataItem.getCaseId());
assertEquals("anotherDataItem", dataItem.getName());
assertEquals("first version", dataItem.getValue());
assertEquals(String.class.getName(), dataItem.getType());
assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
assertNotNull(dataItem.getLastModified());
caseService.addDataToCaseFile(caseId, "anotherDataItem", "second version");
caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
assertNotNull(caseFileItems);
assertEquals(2, caseFileItems.size());
dataItem = caseFileItems.iterator().next();
assertNotNull(dataItem);
assertEquals(caseId, dataItem.getCaseId());
assertEquals("anotherDataItem", dataItem.getName());
assertEquals("second version", dataItem.getValue());
assertEquals(String.class.getName(), dataItem.getType());
assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
assertNotNull(dataItem.getLastModified());
caseService.removeDataFromCaseFile(caseId, "anotherDataItem");
caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
assertNotNull(caseFileItems);
assertEquals(1, caseFileItems.size());
identityProvider.setName("mary");
caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
assertNotNull(caseFileItems);
// mary is not involved in case isntance
assertEquals(0, caseFileItems.size());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
identityProvider.setName("john");
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseStageInstance in project jbpm by kiegroup.
the class CarInsuranceClaimCaseTest method assertBuildClaimReportStage.
protected void assertBuildClaimReportStage() {
Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(CAR_INS_CASE_ID, true, new QueryContext());
assertEquals(1, activeStages.size());
CaseStageInstance stage = activeStages.iterator().next();
assertEquals("Build claim report", stage.getName());
}
use of org.jbpm.casemgmt.api.model.instance.CaseStageInstance 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.casemgmt.api.model.instance.CaseStageInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testTriggerAdHocTasksFromCurrentAndNextStage.
@Test
public void testTriggerAdHocTasksFromCurrentAndNextStage() {
identityProvider.setName("john");
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("customData", "none");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CONDITIONS_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CONDITIONS_CASE_P_ID, caseFile);
assertNotNull(caseId);
try {
Collection<CaseStageInstance> stages = caseRuntimeDataService.getCaseInstanceStages(caseId, false, null);
assertThat(stages).isNotNull().hasSize(2);
Iterator<CaseStageInstance> iterator = stages.iterator();
CaseStageInstance stage1 = iterator.next();
assertThat(stage1.getName()).isEqualTo("Stage One");
assertThat(stage1.getStatus()).isEqualTo(StageStatus.Active);
CaseStageInstance stage2 = iterator.next();
assertThat(stage2.getName()).isEqualTo("Stage Two");
assertThat(stage2.getStatus()).isEqualTo(StageStatus.Available);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().isEmpty();
caseService.triggerAdHocFragment(caseId, "Task 1", null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 1", Status.Reserved);
caseService.triggerAdHocFragment(caseId, "Task 2", null);
// the task from the next stage should not be triggered
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 1", Status.Reserved);
Map<String, Object> params = Collections.singletonMap("myData", "nextStage");
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
stages = caseRuntimeDataService.getCaseInstanceStages(caseId, false, null);
assertThat(stages).isNotNull().hasSize(2);
iterator = stages.iterator();
stage1 = iterator.next();
assertThat(stage1.getName()).isEqualTo("Stage One");
assertThat(stage1.getStatus()).isEqualTo(StageStatus.Completed);
stage2 = iterator.next();
assertThat(stage2.getName()).isEqualTo("Stage Two");
assertThat(stage2.getStatus()).isEqualTo(StageStatus.Active);
caseService.triggerAdHocFragment(caseId, "Task 2", null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 2", Status.Reserved);
caseService.triggerAdHocFragment(caseId, "Task 1", null);
// the task from the previous stage should not be triggered
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertThat(tasks).isNotNull().hasSize(1);
assertTask(tasks.get(0), "john", "Task 2", Status.Reserved);
params = Collections.singletonMap("myData", "none");
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
caseService.cancelCase(caseId);
fail("Unexpected exception " + e.getMessage());
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseStageInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testUserTaskCaseDataItemWithRestrictions.
@Test
public void testUserTaskCaseDataItemWithRestrictions() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("participant", new UserImpl("mary"));
Map<String, Object> data = new HashMap<>();
data.put("contactInfo", "main street 10, NYC");
Map<String, List<String>> accessRestrictions = new HashMap<>();
accessRestrictions.put("contactInfo", Arrays.asList("owner"));
CaseFileInstance caseFile = caseService.newCaseFileInstanceWithRestrictions(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments, accessRestrictions);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_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());
Map<String, Object> caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(1, caseData.size());
assertEquals("main street 10, NYC", caseData.get("contactInfo"));
identityProvider.setName("mary");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
// mary should not see any data yet
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(0, caseData.size());
identityProvider.setName("john");
Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
assertNotNull(activeStages);
assertEquals(1, activeStages.size());
caseService.addDataToCaseFile(caseId, "dataComplete", true, "owner", "participant");
activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
assertNotNull(activeStages);
assertEquals(0, activeStages.size());
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(2, caseData.size());
assertEquals("main street 10, NYC", caseData.get("contactInfo"));
assertEquals(true, caseData.get("dataComplete"));
identityProvider.setName("mary");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
// mary should not see contactInfo
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(1, caseData.size());
assertEquals(true, caseData.get("dataComplete"));
identityProvider.setName("john");
caseService.addDataToCaseFile(caseId, "anotherDataItem", "first version");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(3, caseData.size());
assertEquals("main street 10, NYC", caseData.get("contactInfo"));
assertEquals(true, caseData.get("dataComplete"));
assertEquals("first version", caseData.get("anotherDataItem"));
identityProvider.setName("mary");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
// mary should not see contactInfo
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(2, caseData.size());
assertEquals(true, caseData.get("dataComplete"));
assertEquals("first version", caseData.get("anotherDataItem"));
try {
caseService.removeDataFromCaseFile(caseId, "contactInfo");
fail("mary should not be able to remove data that she has not access to");
} catch (SecurityException e) {
// mary is not allowed to removed comments that she has no role to
assertTrue(e.getMessage().contains("User mary does not have access to data"));
}
identityProvider.setName("john");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(3, caseData.size());
assertEquals("main street 10, NYC", caseData.get("contactInfo"));
assertEquals(true, caseData.get("dataComplete"));
assertEquals("first version", caseData.get("anotherDataItem"));
caseService.removeDataFromCaseFile(caseId, "contactInfo");
cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
caseData = cInstance.getCaseFile().getData();
assertNotNull(caseData);
assertEquals(2, caseData.size());
assertEquals(true, caseData.get("dataComplete"));
assertEquals("first version", caseData.get("anotherDataItem"));
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
identityProvider.setName("john");
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations