use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartScriptRoleAssignmentCase.
@Test
public void testStartScriptRoleAssignmentCase() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), "ScriptRoleAssignmentCase");
assertNotNull(caseId);
assertEquals(HR_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("User Task 1", task.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.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class CaseServiceImplTest method testTriggerTaskAndMilestoneInCase.
@Test
public void testTriggerTaskAndMilestoneInCase() {
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"));
assertTrue(mappedFragments.containsKey("Milestone1"));
assertTrue(mappedFragments.containsKey("Milestone2"));
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());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertNotNull(task);
assertEquals("Hello1", task.getName());
assertEquals("john", task.getActualOwnerId());
assertEquals(Status.Reserved, task.getStatus());
// now let's trigger one (human task) fragment
Map<String, Object> taskData = new HashMap<>();
taskData.put("test", "value");
taskData.put("fromVar", "#{s}");
caseService.triggerAdHocFragment(HR_CASE_ID, "Hello2", taskData);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(2, tasks.size());
task = tasks.get(0);
assertNotNull(task);
assertEquals("Hello2", task.getName());
assertEquals("john", task.getActualOwnerId());
assertEquals(Status.Reserved, task.getStatus());
Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(task.getId());
assertNotNull(taskInputs);
assertTrue(taskInputs.containsKey("test"));
assertTrue(taskInputs.containsKey("fromVar"));
assertEquals("value", taskInputs.get("test"));
assertEquals("description", taskInputs.get("fromVar"));
task = tasks.get(1);
assertNotNull(task);
assertEquals("Hello1", task.getName());
assertEquals("john", task.getActualOwnerId());
assertEquals(Status.Reserved, task.getStatus());
Collection<CaseMilestoneInstance> milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(0, milestones.size());
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, false, new QueryContext());
assertNotNull(milestones);
assertEquals(2, milestones.size());
List<String> expectedMilestones = Arrays.asList("Milestone1", "Milestone2");
for (CaseMilestoneInstance mi : milestones) {
assertTrue("Expected mile stopne not found", expectedMilestones.contains(mi.getName()));
assertEquals("Wrong milestone status", MilestoneStatus.Available, mi.getStatus());
assertFalse("Should not be achieved", mi.isAchieved());
assertNull("Achieved date should be null", mi.getAchievedAt());
}
// trigger milestone node
caseService.triggerAdHocFragment(HR_CASE_ID, "Milestone1", null);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(1, milestones.size());
CaseMilestoneInstance msInstance = milestones.iterator().next();
assertNotNull(msInstance);
assertEquals("Milestone1", msInstance.getName());
assertEquals(true, msInstance.isAchieved());
assertNotNull(msInstance.getAchievedAt());
// trigger another milestone node that has condition so it should not be achieved
caseService.triggerAdHocFragment(HR_CASE_ID, "Milestone2", null);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(1, milestones.size());
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, false, new QueryContext());
assertNotNull(milestones);
assertEquals(2, milestones.size());
// add dataComplete to case file to achieve milestone
caseService.addDataToCaseFile(HR_CASE_ID, "dataComplete", true);
milestones = caseRuntimeDataService.getCaseInstanceMilestones(HR_CASE_ID, true, new QueryContext());
assertNotNull(milestones);
assertEquals(2, milestones.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.internal.query.QueryFilter in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartCaseWithStageAndAdHocFragments.
@Test
public void testStartCaseWithStageAndAdHocFragments() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_ADHOC_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_ADHOC_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
assertCaseInstance(caseId, "my first case");
Collection<AdHocFragment> availableFragments = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
assertEquals(2, availableFragments.size());
Map<String, AdHocFragment> mapped = mapAdHocFragments(availableFragments);
assertEquals("HumanTaskNode", mapped.get("Adhoc 1").getType());
assertEquals("HumanTaskNode", mapped.get("Adhoc 2").getType());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertTask(tasks.get(0), "john", "Initial step", Status.Reserved);
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
availableFragments = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
assertEquals(4, availableFragments.size());
mapped = mapAdHocFragments(availableFragments);
assertEquals("HumanTaskNode", mapped.get("Adhoc 1").getType());
assertEquals("HumanTaskNode", mapped.get("Adhoc 2").getType());
assertEquals("HumanTaskNode", mapped.get("First").getType());
assertEquals("HumanTaskNode", mapped.get("Second").getType());
} 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.internal.query.QueryFilter in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddUserTaskToCaseWithStage.
@Test
public void testAddUserTaskToCaseWithStage() {
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());
CaseStage stage = caseDef.getCaseStages().iterator().next();
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicTaskToStage(FIRST_CASE_ID, stage.getId(), caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertTask(task, "john", "First task", Status.Reserved);
assertEquals("test", task.getDescription());
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(1, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
caseService.addDynamicTaskToStage(casePI.getId(), stage.getId(), caseService.newHumanTaskSpec("Second task", "another test", "mary", null, parameters));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertTask(task, "mary", "Second task", Status.Reserved);
assertEquals("another test", task.getDescription());
} 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.internal.query.QueryFilter 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());
}
}
Aggregations