Search in sources :

Example 76 with CaseInstance

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

the class StageCompletionConditionTest method testNoActiveTasksCondition.

@Test
public void testNoActiveTasksCondition() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_COUNT);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId);
    assertThat(caseInstance).isNotNull();
    Long processInstanceId = ((CaseInstanceImpl) caseInstance).getProcessInstanceId();
    processService.setProcessVariable(processInstanceId, "taskCount", 0);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    userTaskService.completeAutoProgress(tasks.get(0).getId(), USER, null);
    assertCaseInstanceNotActive(caseId);
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 77 with CaseInstance

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

the class StageCompletionConditionTest method testCaseFileVariableWithProcessVariable.

@Test
public void testCaseFileVariableWithProcessVariable() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_AND_PROCESS_VARIABLE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_AND_PROCESS_VARIABLE, caseFile);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId);
    assertThat(caseInstance).isNotNull();
    Long processInstanceId = ((CaseInstanceImpl) caseInstance).getProcessInstanceId();
    processService.setProcessVariable(processInstanceId, "continue", true);
    assertCaseInstanceActive(caseId);
    List<TaskSummary> 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);
    assertCaseInstanceActive(caseId);
    caseService.addDataToCaseFile(caseId, "continue", true);
    assertCaseInstanceActive(caseId);
    caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
    caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary dynamicTask = tasks.get(0);
    assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
    assertCaseInstanceNotActive(caseId);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) QueryFilter(org.kie.internal.query.QueryFilter) CaseInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseInstanceImpl) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 78 with CaseInstance

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

the class StageCompletionConditionTest method testAutoCompleteDynamicTask.

@Test
public void testAutoCompleteDynamicTask() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_AUTOCOMPLETE);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary insideTask = tasks.get(0);
    assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
    caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
    userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
    assertCaseInstanceActive(caseId);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary dynamicTask = tasks.get(0);
    assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
    assertCaseInstanceNotActive(caseId);
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 79 with CaseInstance

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

the class StageCompletionConditionTest method testCaseFileVariable.

@Test
public void testCaseFileVariable() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE, caseFile);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    List<TaskSummary> 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);
    assertCaseInstanceActive(caseId);
    caseService.addDataToCaseFile(caseId, "continue", true);
    assertCaseInstanceActive(caseId);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    TaskSpecification dynamicTaskSpecification = caseService.newHumanTaskSpec(DYNAMIC_TASK, "", USER, null, Collections.emptyMap());
    caseService.addDynamicTaskToStage(caseId, stageId, dynamicTaskSpecification);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary dynamicTask = tasks.get(0);
    assertThat(dynamicTask.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
    assertCaseInstanceNotActive(caseId);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 80 with CaseInstance

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

the class SubCaseServiceImplTest method testStartCaseWithDynamicSubCaseAbortMainCase.

@Test
public void testStartCaseWithDynamicSubCaseAbortMainCase() {
    Map<String, Object> data = new HashMap<>();
    data.put("name", "John Doe");
    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());
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("CaseDefinitionId", "UserTaskCase");
        parameters.put("DeploymentId", deploymentUnit.getIdentifier());
        parameters.put("UserRole_owner", "john");
        parameters.put("Data_s", "#{name}");
        parameters.put("Independent", "false");
        TaskSpecification taskSpecification = caseService.newTaskSpec("StartCaseInstance", "Sub Case", parameters);
        caseService.addDynamicTask(caseId, taskSpecification);
        Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
        assertNotNull(caseInstances);
        assertEquals(2, caseInstances.size());
        Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
        assertTrue(byCaseId.containsKey(FIRST_CASE_ID));
        assertTrue(byCaseId.containsKey(HR_CASE_ID));
        caseService.cancelCase(caseId);
        caseId = null;
        caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
        assertNotNull(caseInstances);
        assertEquals(0, caseInstances.size());
        caseInstances = caseRuntimeDataService.getCaseInstances(Arrays.asList(CaseStatus.CANCELLED), new QueryContext());
        assertNotNull(caseInstances);
        assertEquals(2, caseInstances.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 : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) UserImpl(org.jbpm.services.task.impl.model.UserImpl) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) QueryFilter(org.kie.internal.query.QueryFilter) ArrayList(java.util.ArrayList) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) Collectors.toMap(java.util.stream.Collectors.toMap) ProcessInstance(org.jbpm.process.instance.ProcessInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) QueryContext(org.kie.api.runtime.query.QueryContext) Consumer(java.util.function.Consumer) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) Assert.assertNull(org.junit.Assert.assertNull) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) Assert.assertEquals(org.junit.Assert.assertEquals) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) TaskSpecification(org.jbpm.casemgmt.api.dynamic.TaskSpecification) HashMap(java.util.HashMap) QueryContext(org.kie.api.runtime.query.QueryContext) 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