Search in sources :

Example 21 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class StageCompletionConditionTest method testProcessVariable.

@Test
public void testProcessVariable() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_PROCESS_VARIABLE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_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", false);
    caseService.addDataToCaseFile(caseId, "continue", true);
    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);
    processService.setProcessVariable(processInstanceId, "continue", true);
    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 22 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class SubCaseServiceImplTest method testStartProcessWithSubCaseDestroySubCase.

@Test
public void testStartProcessWithSubCaseDestroySubCase() {
    Long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), PROCESS_TO_CASE_P_ID);
    assertNotNull(processInstanceId);
    try {
        // check if case was created from within the process
        CaseInstance cInstance = caseService.getCaseInstance(HR_CASE_ID);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Map<String, Object> processVariables = processService.getProcessInstanceVariables(processInstanceId);
        assertNull(processVariables.get("CaseId"));
        assertNull(processVariables.get("outcome"));
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertEquals("Hello1", tasks.get(0).getName());
        caseService.destroyCase(HR_CASE_ID);
        processVariables = processService.getProcessInstanceVariables(processInstanceId);
        assertEquals(HR_CASE_ID, processVariables.get("CaseId"));
        assertEquals("process2case", processVariables.get("outcome"));
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertEquals("Verify case results", tasks.get(0).getName());
        Map<String, Object> taskInputs = userTaskService.getTaskInputContentByTaskId(tasks.get(0).getId());
        assertEquals(HR_CASE_ID, taskInputs.get("CaseId"));
        assertEquals("process2case", taskInputs.get("outcome"));
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
        ProcessInstanceDesc piLog = runtimeDataService.getProcessInstanceById(processInstanceId);
        assertNotNull(piLog);
        assertEquals(ProcessInstance.STATE_COMPLETED, piLog.getState().intValue());
        processInstanceId = null;
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (processInstanceId != null) {
            processService.abortProcessInstance(processInstanceId);
        }
    }
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 23 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method attachAndAssertPoliceReport.

protected void attachAndAssertPoliceReport() {
    caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Submit police report", null);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertNotNull(tasks);
    assertEquals(2, tasks.size());
    assertTask(tasks.get(0), null, "Submit police report", Status.Ready);
    assertTask(tasks.get(1), null, "File property damage claim", Status.Ready);
    byte[] docContent = "police report content".getBytes();
    DocumentImpl document = new DocumentImpl(UUID.randomUUID().toString(), "car-accident-police-report.txt", docContent.length, new Date());
    document.setContent(docContent);
    Map<String, Object> params = new HashMap<>();
    params.put("policeReport_", document);
    userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
    // police report should be stored in case file data
    CaseFileInstance caseFile = caseService.getCaseFileInstance(CAR_INS_CASE_ID);
    assertNotNull(caseFile);
    Document policeReport = (Document) caseFile.getData("policeReport");
    assertNotNull(policeReport);
    assertEquals("car-accident-police-report.txt", policeReport.getName());
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date)

Example 24 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method assertTasksForBothRoles.

protected long assertTasksForBothRoles(String taskName, String actor1, String actor2, Status status) {
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(actor1, new QueryFilter());
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    assertTask(tasks.get(0), null, taskName, status);
    // the same task can be claimed by insuranceRepresentative in case claim is reported over phone
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(actor2, new QueryFilter());
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    assertTask(tasks.get(0), null, taskName, status);
    return tasks.get(0).getId();
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary)

Example 25 with QueryFilter

use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method assertAndProvideAdditionalDetails.

protected void assertAndProvideAdditionalDetails() {
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    assertTask(tasks.get(0), "john", "Please provide additional details", Status.Reserved);
    long taskId = tasks.get(0).getId();
    Map<String, Object> inputs = userTaskService.getTaskInputContentByTaskId(taskId);
    assertNotNull(inputs);
    assertEquals("How did it happen?", inputs.get("reason"));
    Map<String, Object> params = new HashMap<>();
    params.put("caseFile_answer", "It just happened in a split second, don't remember anything else");
    userTaskService.completeAutoProgress(taskId, "john", params);
    CaseFileInstance caseFile = caseService.getCaseFileInstance(CAR_INS_CASE_ID);
    assertNotNull(caseFile);
    String answer = (String) caseFile.getData("answer");
    assertNotNull(answer);
    assertEquals("It just happened in a split second, don't remember anything else", answer);
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary)

Aggregations

QueryFilter (org.kie.internal.query.QueryFilter)149 Test (org.junit.Test)127 TaskSummary (org.kie.api.task.model.TaskSummary)122 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)52 HashMap (java.util.HashMap)47 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)31 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)26 AuditTask (org.kie.internal.task.api.AuditTask)25 ArrayList (java.util.ArrayList)24 QueryContext (org.kie.api.runtime.query.QueryContext)24 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)23 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)21 Task (org.kie.api.task.model.Task)19 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)18 TaskFluent (org.jbpm.services.task.utils.TaskFluent)17 TaskEvent (org.kie.internal.task.api.model.TaskEvent)17 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)14 Status (org.kie.api.task.model.Status)13 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)11 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)10