Search in sources :

Example 11 with CaseInstance

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

the class CaseServiceImplTest method testStartCaseWithConditionalEventCompleteCase.

@Test
public void testStartCaseWithConditionalEventCompleteCase() {
    List<String> docs = new ArrayList<>();
    docs.add("First doc");
    Map<String, Object> data = new HashMap<>();
    data.put("Documents", docs);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), COND_CASE_P_ID, data);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), COND_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        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 : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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 12 with CaseInstance

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

the class CaseServiceImplTest method testUserTaskToCaseWithStageCompleteCaseDataItem.

@Test
public void testUserTaskToCaseWithStageCompleteCaseDataItem() {
    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());
        Collection<CaseFileItem> caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(0, caseFileItems.size());
        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());
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(1, caseFileItems.size());
        CaseFileItem dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("dataComplete", dataItem.getName());
        assertEquals("true", dataItem.getValue());
        assertEquals(Boolean.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.addDataToCaseFile(caseId, "anotherDataItem", "first version");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(2, caseFileItems.size());
        dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("anotherDataItem", dataItem.getName());
        assertEquals("first version", dataItem.getValue());
        assertEquals(String.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.addDataToCaseFile(caseId, "anotherDataItem", "second version");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(2, caseFileItems.size());
        dataItem = caseFileItems.iterator().next();
        assertNotNull(dataItem);
        assertEquals(caseId, dataItem.getCaseId());
        assertEquals("anotherDataItem", dataItem.getName());
        assertEquals("second version", dataItem.getValue());
        assertEquals(String.class.getName(), dataItem.getType());
        assertEquals(identityProvider.getName(), dataItem.getLastModifiedBy());
        assertNotNull(dataItem.getLastModified());
        caseService.removeDataFromCaseFile(caseId, "anotherDataItem");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        assertEquals(1, caseFileItems.size());
        identityProvider.setName("mary");
        caseFileItems = caseRuntimeDataService.getCaseInstanceDataItems(caseId, new QueryContext());
        assertNotNull(caseFileItems);
        // mary is not involved in case isntance
        assertEquals(0, caseFileItems.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);
        }
    }
}
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) 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) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 13 with CaseInstance

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

the class CaseServiceImplTest method testCaseAuthorizationImplicitOwner.

@Test
public void testCaseAuthorizationImplicitOwner() {
    String expectedCaseId = "UniqueID-0000000001";
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("patient", new UserImpl("john"));
    Map<String, Object> data = new HashMap<>();
    data.put("s", "description");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", data, roleAssignments);
    identityProvider.setName("mary");
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", caseFile);
    assertNotNull(caseId);
    assertEquals(expectedCaseId, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(expectedCaseId, cInstance.getCaseId());
        assertEquals("mary", cInstance.getOwner());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        identityProvider.setName("john");
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(expectedCaseId, "john", Arrays.asList(Status.Reserved), new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        identityProvider.setName("mary");
        caseService.triggerAdHocFragment(expectedCaseId, "task2", null);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(expectedCaseId, "mary", Arrays.asList(Status.Reserved), new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "mary", null);
        caseService.triggerAdHocFragment(expectedCaseId, "task3", null);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(expectedCaseId, "mary", Arrays.asList(Status.Ready), new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "mary", null);
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            identityProvider.setName("mary");
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) 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) 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 14 with CaseInstance

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

the class CaseServiceImplTest method testUserTaskToCaseSearchByCaseFileData.

@Test
public void testUserTaskToCaseSearchByCaseFileData() {
    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());
        caseService.addDataToCaseFile(caseId, "dataComplete", true);
        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);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) 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) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 15 with CaseInstance

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

the class CaseServiceImplTest method testCaseWithDefinedDataRestrictions.

@Test
public void testCaseWithDefinedDataRestrictions() {
    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");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_DATA_RESTRICTIONS_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_DATA_RESTRICTIONS_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        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);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(0, caseData.size());
        identityProvider.setName("john");
        caseService.addDataToCaseFile(caseId, "request", "does it actually work?");
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(2, caseData.size());
        assertEquals("main street 10, NYC", caseData.get("contactInfo"));
        assertEquals("does it actually work?", caseData.get("request"));
        identityProvider.setName("mary");
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(1, caseData.size());
        assertEquals("does it actually work?", caseData.get("request"));
        identityProvider.setName("john");
        try {
            caseService.addDataToCaseFile(caseId, "reply", "does it actually work?");
            fail("john does not have access to reply data so cannot add it");
        } catch (SecurityException e) {
            assertTrue(e.getMessage().startsWith("User john does not have access to data item named reply"));
        }
        identityProvider.setName("mary");
        caseService.addDataToCaseFile(caseId, "reply", "oh yes, it does!");
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(2, caseData.size());
        assertEquals("oh yes, it does!", caseData.get("reply"));
        assertEquals("does it actually work?", caseData.get("request"));
        identityProvider.setName("john");
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(2, caseData.size());
        assertEquals("main street 10, NYC", caseData.get("contactInfo"));
        assertEquals("does it actually work?", caseData.get("request"));
        identityProvider.setName("mary");
        caseService.addDataToCaseFile(caseId, "reply", "oh yes, it does! make it visible to all", AuthorizationManager.PUBLIC_GROUP);
        identityProvider.setName("john");
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(3, caseData.size());
        assertEquals("main street 10, NYC", caseData.get("contactInfo"));
        assertEquals("does it actually work?", caseData.get("request"));
        assertEquals("oh yes, it does! make it visible to all", caseData.get("reply"));
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            identityProvider.setName("john");
            caseService.cancelCase(caseId);
        }
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl) 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)

Aggregations

CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)92 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)88 Test (org.junit.Test)88 HashMap (java.util.HashMap)73 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)66 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)47 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)47 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)47 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)47 UserImpl (org.jbpm.services.task.impl.model.UserImpl)47 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)46 TaskSummary (org.kie.api.task.model.TaskSummary)42 QueryFilter (org.kie.internal.query.QueryFilter)29 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)23 CaseInstanceImpl (org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl)12 ArrayList (java.util.ArrayList)10 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)10 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)10