Search in sources :

Example 1 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesWithConditionsInCase.

@Test
public void testTransitionBetweenStagesWithConditionsInCase() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    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> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        assertEquals("Stage One", stage.iterator().next().getName());
        assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
        Collection<AdHocFragment> adhocTasks = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
        assertNotNull(adhocTasks);
        assertEquals(1, adhocTasks.size());
        assertEquals("Task 1", adhocTasks.iterator().next().getName());
        caseService.triggerAdHocFragment(caseId, "Task 1", null);
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertTask(tasks.get(0), "john", "Task 1", Status.Reserved);
        Map<String, Object> params = new HashMap<>();
        params.put("myData", "nextStage");
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        assertEquals("Stage Two", stage.iterator().next().getName());
        assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
        adhocTasks = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
        assertNotNull(adhocTasks);
        assertEquals(1, adhocTasks.size());
        assertEquals("Task 2", adhocTasks.iterator().next().getName());
        caseService.triggerAdHocFragment(caseId, "Task 2", null);
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertTask(tasks.get(0), "john", "Task 2", Status.Reserved);
        params = new HashMap<>();
        params.put("myData", "none");
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CLOSED.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);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) 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)

Example 2 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImplTest method testUserTasksInCaseAdBusinessAdmin.

@Test
public void testUserTasksInCaseAdBusinessAdmin() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId2 = null;
    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());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsBusinessAdmin(caseId, "Administrator", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(0, tasks.size());
        Map<String, Object> taskInput = new HashMap<>();
        taskInput.put("ActorId", "john");
        caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsBusinessAdmin(caseId, "Administrator", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        caseId2 = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
        assertNotNull(caseId2);
        assertEquals("CASE-0000000002", caseId2);
        caseService.triggerAdHocFragment(caseId2, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsBusinessAdmin(caseId2, "Administrator", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsBusinessAdmin(caseId, "Administrator", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
        if (caseId2 != null) {
            caseService.cancelCase(caseId2);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) 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 3 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImplTest method testUserTasksInCaseAdStakeholder.

@Test
public void testUserTasksInCaseAdStakeholder() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
    String caseId2 = null;
    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());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsStakeholder(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(0, tasks.size());
        Map<String, Object> taskInput = new HashMap<>();
        taskInput.put("ActorId", "mary");
        taskInput.put("TaskStakeholderId", "john");
        caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsStakeholder(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        caseId2 = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
        assertNotNull(caseId2);
        assertEquals("CASE-0000000002", caseId2);
        caseService.triggerAdHocFragment(caseId2, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsStakeholder(caseId2, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsStakeholder(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
        if (caseId2 != null) {
            caseService.cancelCase(caseId2);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) 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 4 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImplTest method testTransitionBetweenStagesInCase.

@Test
public void testTransitionBetweenStagesInCase() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl(USER));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    try {
        Collection<CaseStageInstance> stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        assertEquals("Stage One", stage.iterator().next().getName());
        assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
        Collection<AdHocFragment> adhocTasks = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
        assertNotNull(adhocTasks);
        assertEquals(1, adhocTasks.size());
        assertEquals("Task 1", adhocTasks.iterator().next().getName());
        Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        assertEquals("Stage One", activeNodes.iterator().next().getName());
        Collection<NodeInstanceDesc> completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(0, completedNodes.size());
        caseService.addDataToCaseFile(caseId, "customData", "nextStagePlease");
        stage = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext(0, 1));
        assertNotNull(stage);
        assertEquals(1, stage.size());
        assertEquals("Stage Two", stage.iterator().next().getName());
        assertEquals(StageStatus.Active, stage.iterator().next().getStatus());
        adhocTasks = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
        assertNotNull(adhocTasks);
        assertEquals(1, adhocTasks.size());
        assertEquals("Task 2", adhocTasks.iterator().next().getName());
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        assertEquals("Stage Two", activeNodes.iterator().next().getName());
        completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(1, completedNodes.size());
        assertEquals("Stage One", completedNodes.iterator().next().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 : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 5 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseSLAComplianceTest method testStartCaseWithSLANotification.

@Test
public void testStartCaseWithSLANotification() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("admin", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "Case with SLA");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_SLA_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(HR_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_PENDING, cInstance.getSlaCompliance().intValue());
        Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext());
        assertThat(activeNodes).hasSize(1);
        Iterator<NodeInstanceDesc> it = activeNodes.iterator();
        NodeInstanceDesc active = it.next();
        assertThat(active.getName()).isEqualTo("Hello1");
        CountDownListenerFactory.getExisting("slaCompliance").waitTillCompleted();
        cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals(ProcessInstance.SLA_VIOLATED, cInstance.getSlaCompliance().intValue());
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext());
        assertThat(activeNodes).hasSize(2);
        it = activeNodes.iterator();
        active = it.next();
        assertThat(active.getName()).isEqualTo("Hello1");
        active = it.next();
        assertThat(active.getName()).isEqualTo("[Dynamic] SLA Violation for case " + caseId);
        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);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) UserImpl(org.jbpm.services.task.impl.model.UserImpl) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

UserImpl (org.jbpm.services.task.impl.model.UserImpl)57 Test (org.junit.Test)52 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)51 HashMap (java.util.HashMap)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)49 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)42 QueryContext (org.kie.api.runtime.query.QueryContext)33 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)25 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)25 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)25 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)25 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)25 TaskSummary (org.kie.api.task.model.TaskSummary)21 QueryFilter (org.kie.internal.query.QueryFilter)10 ArrayList (java.util.ArrayList)9 GroupImpl (org.jbpm.services.task.impl.model.GroupImpl)9 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)7 CaseAssignment (org.kie.api.runtime.process.CaseAssignment)7