Search in sources :

Example 86 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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)

Example 87 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testStartThenReopenActiveCase.

@Test
public void testStartThenReopenActiveCase() {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "my first case");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        assertEquals("my first case", cInstance.getCaseDescription());
        try {
            caseService.reopenCase(caseId, deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
            fail("Not allowed to reopen active case");
        } catch (CaseActiveException e) {
        // expected
        }
    } 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) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) 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) CaseActiveException(org.jbpm.casemgmt.api.CaseActiveException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 88 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testUpdateNotExistingCaseComment.

@Test
public void testUpdateNotExistingCaseComment() {
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        caseService.updateCaseComment(FIRST_CASE_ID, "not-existing-comment", "poul", "just a tiny comment");
        fail("Updating non-existent case comment should throw CaseCommentNotFoundException.");
    } catch (CaseCommentNotFoundException e) {
    // expected
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) HashMap(java.util.HashMap) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 89 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.

the class CaseServiceImplTest method testRemoveNotExistingCaseComment.

@Test
public void testRemoveNotExistingCaseComment() {
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        caseService.removeCaseComment(FIRST_CASE_ID, "not-existing-comment");
        fail("Removing non-existent case comment should throw CaseCommentNotFoundException.");
    } catch (CaseCommentNotFoundException e) {
    // expected
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) HashMap(java.util.HashMap) CaseCommentNotFoundException(org.jbpm.casemgmt.api.CaseCommentNotFoundException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 90 with CaseFileInstance

use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance 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);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) 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)

Aggregations

CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)121 HashMap (java.util.HashMap)95 Test (org.junit.Test)86 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)81 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)66 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)61 UserImpl (org.jbpm.services.task.impl.model.UserImpl)54 QueryContext (org.kie.api.runtime.query.QueryContext)46 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)44 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)42 TaskSummary (org.kie.api.task.model.TaskSummary)40 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)39 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)39 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)39 QueryFilter (org.kie.internal.query.QueryFilter)26 ArrayList (java.util.ArrayList)21 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)20 Collection (java.util.Collection)17 List (java.util.List)17 Map (java.util.Map)16