use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testUserTaskCaseSearchByInitialCaseFileData.
@Test
public void testUserTaskCaseSearchByInitialCaseFileData() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("dataComplete", true);
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<CaseInstance> byCaseData = caseRuntimeDataService.getCaseInstancesByDateItem("dataComplete", Arrays.asList(CaseStatus.OPEN), new QueryContext());
assertNotNull(byCaseData);
assertEquals(1, byCaseData.size());
byCaseData = caseRuntimeDataService.getCaseInstancesByDateItemAndValue("dataComplete", "false", Arrays.asList(CaseStatus.OPEN), new QueryContext());
assertNotNull(byCaseData);
assertEquals(0, byCaseData.size());
byCaseData = caseRuntimeDataService.getCaseInstancesByDateItemAndValue("dataComplete", "true", Arrays.asList(CaseStatus.OPEN), new QueryContext());
assertNotNull(byCaseData);
assertEquals(1, byCaseData.size());
identityProvider.setName("mary");
byCaseData = caseRuntimeDataService.getCaseInstancesByDateItem("dataComplete", Arrays.asList(CaseStatus.OPEN), new QueryContext());
assertNotNull(byCaseData);
// mary is not part of the case instance
assertEquals(0, byCaseData.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.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testUserTaskToCaseWithStageComplete.
@Test
public void testUserTaskToCaseWithStageComplete() {
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());
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID);
assertNotNull(caseDef);
assertEquals(1, caseDef.getCaseStages().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
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());
} 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.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartThenReopenDestroyedCase.
@Test
public void testStartThenReopenDestroyedCase() {
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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("my first case", cInstance.getCaseDescription());
caseService.destroyCase(caseId);
try {
caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
fail("Not allowed to reopen destroyed case");
} catch (CaseNotFoundException e) {
// expected
}
caseId = null;
} 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.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartEmptyCaseWithCaseFile.
@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"));
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<VariableDesc> vars = runtimeDataService.getVariablesCurrentState(((CaseInstanceImpl) cInstance).getProcessInstanceId());
assertNotNull(vars);
assertEquals(3, vars.size());
Map<String, Object> mappedVars = vars.stream().collect(toMap(v -> v.getVariableId(), v -> v.getNewValue()));
assertEquals("my first case", mappedVars.get("caseFile_name"));
assertEquals(FIRST_CASE_ID, mappedVars.get("CaseId"));
assertEquals("john", mappedVars.get("initiator"));
caseService.cancelCase(caseId);
CaseInstance instance = caseService.getCaseInstance(caseId);
Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
caseId = null;
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations