Search in sources :

Example 41 with CaseInstance

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

the class AbstractCaseServicesBaseTest method assertCaseInstanceNotActive.

public void assertCaseInstanceNotActive(String caseId) {
    try {
        CaseInstance caseInstance = caseService.getCaseInstance(caseId);
        assertThat(caseInstance).isNotNull();
        assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
    } catch (CaseNotFoundException ex) {
    // in case it does not exist at all
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Example 42 with CaseInstance

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

the class CaseRuntimeDataServiceImplTest method testAddSubprocessToEmptyCaseCheckCaseNodes.

@Test
public void testAddSubprocessToEmptyCaseCheckCaseNodes() {
    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(FIRST_CASE_ID, cInstance.getCaseId());
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        Collection<NodeInstanceDesc> completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(0, completedNodes.size());
        Map<String, Object> parameters = new HashMap<>();
        caseService.addDynamicSubprocess(caseId, "UserTask", parameters);
        Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(2, caseProcessInstances.size());
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(2, activeNodes.size());
        Map<String, NodeInstanceDesc> mappedNodes = mapNodeInstances(activeNodes);
        assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
        assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
        completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(0, completedNodes.size());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertEquals(1, tasks.size());
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(activeNodes);
        assertEquals(0, activeNodes.size());
        completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
        assertNotNull(completedNodes);
        assertEquals(2, completedNodes.size());
        assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
        assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSummary(org.kie.api.task.model.TaskSummary) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 43 with CaseInstance

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

the class CaseRuntimeDataServiceImplTest method testUserTasksInCase.

@Test
public void testUserTasksInCase() {
    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.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(0, tasks.size());
        Map<String, Object> taskInput = new HashMap<>();
        taskInput.put("ActorId", "john");
        taskInput.put("Comment", "Need to provide data");
        caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        assertEquals("Need to provide data", task.getSubject());
        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.getCaseTasksAssignedAsPotentialOwner(caseId2, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(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 44 with CaseInstance

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

the class CaseRuntimeDataServiceImplTest method testStartEmptyCaseWithCaseFile.

/*
     * Case instance queries
     */
@Test
public void testStartEmptyCaseWithCaseFile() {
    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, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
        assertNotNull(cInstance.getCaseFile());
        assertEquals("my first case", cInstance.getCaseFile().getData("name"));
        Collection<CaseInstance> instances = caseRuntimeDataService.getCaseInstances(new QueryContext());
        assertNotNull(instances);
        assertEquals(1, instances.size());
        CaseInstance instance = instances.iterator().next();
        assertNotNull(instance);
        assertEquals(FIRST_CASE_ID, instance.getCaseId());
        assertEquals(EMPTY_CASE_P_ID, instance.getCaseDefinitionId());
        assertEquals("my first case", instance.getCaseDescription());
        assertEquals(USER, instance.getOwner());
        assertEquals(ProcessInstance.STATE_ACTIVE, instance.getStatus().intValue());
        assertEquals(deploymentUnit.getIdentifier(), instance.getDeploymentId());
        assertNotNull(instance.getStartedAt());
        // add dynamic user task to empty case instance - first by case id
        Map<String, Object> parameters = new HashMap<>();
        caseService.addDynamicTask(FIRST_CASE_ID, caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
        Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(FIRST_CASE_ID, new QueryContext());
        assertNotNull(activeNodes);
        assertEquals(1, activeNodes.size());
        NodeInstanceDesc activeNode = activeNodes.iterator().next();
        assertNotNull(activeNodes);
        assertEquals("[Dynamic] First task", activeNode.getName());
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("First task", task.getName());
        assertEquals("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 : 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) TaskSummary(org.kie.api.task.model.TaskSummary) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 45 with CaseInstance

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

the class CaseRuntimeDataServiceImplTest method testUserTasksInCaseWithSubprocess.

@Test
public void testUserTasksInCaseWithSubprocess() {
    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 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.getCaseTasksAssignedAsPotentialOwner(caseId, "john", 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.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        TaskSummary task = tasks.get(0);
        assertEquals("Missing data", task.getName());
        caseService.addDynamicSubprocess(caseId, "UserTask", null);
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(2, tasks.size());
        task = tasks.get(0);
        assertEquals("Hello", task.getName());
        task = tasks.get(1);
        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);
        }
    }
}
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)

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