Search in sources :

Example 6 with CaseStage

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

the class CaseDynamicNodesTest method testAddDynamicTaskToNotActiveStage.

@Test
public void testAddDynamicTaskToNotActiveStage() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseDefinition caseDefinition = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), TWO_STAGES_CASE_P_ID);
    assertThat(caseDefinition).isNotNull();
    assertThat(caseDefinition.getCaseStages()).hasSize(2);
    Iterator<CaseStage> caseStageIterator = caseDefinition.getCaseStages().iterator();
    caseStageIterator.next();
    String stageId = caseStageIterator.next().getId();
    assertThatThrownBy(() -> caseService.addDynamicTaskToStage(caseId, stageId, createUserTask())).isInstanceOf(StageNotFoundException.class);
}
Also used : CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 7 with CaseStage

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

the class CaseRuntimeDataServiceDefinitionImplTest method testGetCaseDefinitionById.

@Test
public void testGetCaseDefinitionById() {
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), "UserTaskWithStageCase");
    // UserTaskWithStageCase asserts
    assertNotNull(caseDef);
    assertEquals("UserTaskWithStageCase", caseDef.getId());
    assertEquals("UserTaskWithStageCase", caseDef.getName());
    assertEquals("1.0", caseDef.getVersion());
    assertEquals(CaseDefinition.DEFAULT_PREFIX, caseDef.getIdentifierPrefix());
    assertNotNull(caseDef.getCaseMilestones());
    assertEquals(0, caseDef.getCaseMilestones().size());
    assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
    assertNotNull(caseDef.getCaseStages());
    assertEquals(1, caseDef.getCaseStages().size());
    Map<String, CaseStage> mappedStages = mapStages(caseDef.getCaseStages());
    assertTrue(mappedStages.containsKey("Collect input"));
    CaseStage caseStage = mappedStages.get("Collect input");
    assertNotNull(caseStage);
    assertEquals("Collect input", caseStage.getName());
    assertEquals(2, caseStage.getAdHocFragments().size());
    Map<String, AdHocFragment> mappedFragments = mapAdHocFragments(caseStage.getAdHocFragments());
    assertTrue(mappedFragments.containsKey("Missing data"));
    assertEquals("HumanTaskNode", mappedFragments.get("Missing data").getType());
    assertTrue(mappedFragments.containsKey("Verification of data"));
    assertEquals("SubProcessNode", mappedFragments.get("Verification of data").getType());
    assertNotNull(caseDef.getCaseRoles());
    assertEquals(3, caseDef.getCaseRoles().size());
    Map<String, CaseRole> mappedRoles = mapRoles(caseDef.getCaseRoles());
    assertTrue(mappedRoles.containsKey("owner"));
    assertTrue(mappedRoles.containsKey("contact"));
    assertTrue(mappedRoles.containsKey("participant"));
    assertEquals(1, mappedRoles.get("owner").getCardinality().intValue());
    assertEquals(2, mappedRoles.get("contact").getCardinality().intValue());
    assertEquals(-1, mappedRoles.get("participant").getCardinality().intValue());
}
Also used : CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 8 with CaseStage

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

the class CaseServiceImplTest method testAddSubprocessToCaseWithStage.

@Test
public void testAddSubprocessToCaseWithStage() {
    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.addDynamicSubprocessToStage(FIRST_CASE_ID, stage.getId(), SUBPROCESS_P_ID, parameters);
        // second task add by process instance id
        Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(2, caseProcessInstances.size());
        ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
        assertNotNull(casePI);
        assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
        caseService.addDynamicSubprocessToStage(casePI.getId(), stage.getId(), SUBPROCESS_P_ID, parameters);
        // let's verify that there are three process instances related to this case
        caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertNotNull(caseProcessInstances);
        assertEquals(3, caseProcessInstances.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) 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) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) UserImpl(org.jbpm.services.task.impl.model.UserImpl) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 9 with CaseStage

use of org.jbpm.casemgmt.api.model.CaseStage 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 10 with CaseStage

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

the class StageCompletionConditionTest method testAutoCompleteNoAutoStartTaskAdHocInStage.

@Test
public void testAutoCompleteNoAutoStartTaskAdHocInStage() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
    CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
    Collection<CaseStage> stages = caseDef.getCaseStages();
    assertThat(stages).hasSize(1);
    String stageId = stages.iterator().next().getId();
    caseService.triggerAdHocFragment(caseId, stageId, INSIDE_TASK, null);
    assertCaseInstanceActive(caseId);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary insideTask = tasks.get(0);
    assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
    userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
    assertCaseInstanceNotActive(caseId);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseStage (org.jbpm.casemgmt.api.model.CaseStage)11 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)10 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)8 Test (org.junit.Test)8 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)5 QueryContext (org.kie.api.runtime.query.QueryContext)5 HashMap (java.util.HashMap)4 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)4 CaseRole (org.jbpm.casemgmt.api.model.CaseRole)4 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)4 ArrayList (java.util.ArrayList)3 CaseMilestone (org.jbpm.casemgmt.api.model.CaseMilestone)3 CaseStageImpl (org.jbpm.casemgmt.impl.model.CaseStageImpl)3 BoundaryEventNode (org.jbpm.workflow.core.node.BoundaryEventNode)3 DynamicNode (org.jbpm.workflow.core.node.DynamicNode)3 MilestoneNode (org.jbpm.workflow.core.node.MilestoneNode)3 StartNode (org.jbpm.workflow.core.node.StartNode)3 Node (org.kie.api.definition.process.Node)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 QueryFilter (org.kie.internal.query.QueryFilter)3