use of org.kie.api.task.model.OrganizationalEntity in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseRolesWithDynamicTask.
@Test
public void testCaseRolesWithDynamicTask() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("s", "description");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID);
assertNotNull(caseDef);
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
assertEquals(3, caseDef.getAdHocFragments().size());
Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseDef.getAdHocFragments());
assertTrue(mappedFragments.containsKey("Hello2"));
assertEquals("HumanTaskNode", mappedFragments.get("Hello2").getType());
assertTrue(mappedFragments.containsKey("Milestone1"));
assertEquals("MilestoneNode", mappedFragments.get("Milestone1").getType());
assertTrue(mappedFragments.containsKey("Milestone2"));
assertEquals("MilestoneNode", mappedFragments.get("Milestone2").getType());
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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
caseService.assignToCaseRole(HR_CASE_ID, "contact", new UserImpl("mary"));
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertTask(tasks.get(0), "john", "Hello1", Status.Reserved);
caseService.addDynamicTask(HR_CASE_ID, caseService.newHumanTaskSpec("Second task", "another test", "contact", null, new HashMap<>()));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertTask(tasks.get(0), "mary", "Second task", Status.Reserved);
// now let's another user to contact role
caseService.assignToCaseRole(HR_CASE_ID, "contact", new UserImpl("john"));
caseService.addDynamicTask(HR_CASE_ID, caseService.newHumanTaskSpec("Third task", "another test", "contact", null, new HashMap<>()));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertNotNull(tasks);
assertEquals(2, tasks.size());
assertTask(tasks.get(0), null, "Third task", Status.Ready);
assertTask(tasks.get(1), "mary", "Second task", Status.Reserved);
} 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.kie.api.task.model.OrganizationalEntity 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.kie.api.task.model.OrganizationalEntity 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.kie.api.task.model.OrganizationalEntity 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.kie.api.task.model.OrganizationalEntity 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);
}
}
}
Aggregations