Search in sources :

Example 86 with QueryFilter

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);
        }
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 87 with QueryFilter

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);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 88 with QueryFilter

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);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 89 with QueryFilter

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);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 90 with QueryFilter

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());
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AdHocFragmentNotFoundException(org.jbpm.casemgmt.api.AdHocFragmentNotFoundException) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) UserImpl(org.jbpm.services.task.impl.model.UserImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

QueryFilter (org.kie.internal.query.QueryFilter)149 Test (org.junit.Test)127 TaskSummary (org.kie.api.task.model.TaskSummary)122 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)52 HashMap (java.util.HashMap)47 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)31 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)26 AuditTask (org.kie.internal.task.api.AuditTask)25 ArrayList (java.util.ArrayList)24 QueryContext (org.kie.api.runtime.query.QueryContext)24 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)23 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)21 Task (org.kie.api.task.model.Task)19 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)18 TaskFluent (org.jbpm.services.task.utils.TaskFluent)17 TaskEvent (org.kie.internal.task.api.model.TaskEvent)17 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)14 Status (org.kie.api.task.model.Status)13 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)10