use of org.jbpm.services.task.impl.model.UserImpl 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.services.task.impl.model.UserImpl 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.services.task.impl.model.UserImpl 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.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseRolesWithQueries.
@Test
public void testCaseRolesWithQueries() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
roleAssignments.put("contact", new GroupImpl("HR"));
Map<String, Object> data = new HashMap<>();
data.put("s", "description");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(HR_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(HR_CASE_ID, cInstance.getCaseId());
assertEquals(CaseStatus.OPEN.getId(), cInstance.getStatus().intValue());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
// only john is now included in case roles
Collection<CaseInstance> instances = caseRuntimeDataService.getCaseInstancesAnyRole(null, new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
List<CaseStatus> status = Arrays.asList(CaseStatus.CANCELLED);
instances = caseRuntimeDataService.getCaseInstancesAnyRole(status, new QueryContext());
assertNotNull(instances);
assertFalse("Opened case was returned when searching for cancelled case instances.", instances.stream().anyMatch(n -> n.getCaseId().equals(caseId)));
status = Arrays.asList(CaseStatus.OPEN);
instances = caseRuntimeDataService.getCaseInstancesAnyRole(status, new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
instances = caseRuntimeDataService.getCaseInstancesByRole(null, status, new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
instances = caseRuntimeDataService.getCaseInstancesByRole("owner", status, new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
identityProvider.setName("mary");
instances = caseRuntimeDataService.getCaseInstancesByRole("owner", status, new QueryContext());
assertNotNull(instances);
assertEquals("Mary shouldn't be owner of any opened case instance.", 0, instances.size());
identityProvider.setRoles(Arrays.asList("HR"));
instances = caseRuntimeDataService.getCaseInstancesByRole("contact", status, new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.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.services.task.impl.model.UserImpl in project jbpm by kiegroup.
the class CaseAssignmentServiceImplTest method testProperRoleAssignedAutoStart.
@Test
public void testProperRoleAssignedAutoStart() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("actorRole", new UserImpl("john"));
roleAssignments.put("groupRole", new GroupImpl("managers"));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), CASE_X_P_ID, data, roleAssignments);
((CaseAssignment) caseFile).assignGroup("generalRole", "managers");
((CaseAssignment) caseFile).assignUser("generalRole", "john");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), CASE_X_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());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations