Search in sources :

Example 41 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class CaseAssignmentServiceImplTest method testProperRoleAssigned.

@Test
public void testProperRoleAssigned() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("actorRole", new UserImpl("mary"));
    roleAssignments.put("groupRole", new GroupImpl("managers"));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), CASE_Y_P_ID, data, roleAssignments);
    ((CaseAssignment) caseFile).assignGroup("generalRole", "managers");
    ((CaseAssignment) caseFile).assignUser("generalRole", "john");
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), CASE_Y_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, "mary", null, new QueryContext());
        assertEquals(5, tasks.size());
        TaskSummary foundTask = tasks.stream().filter(task -> task.getName().equals("Task E")).findFirst().get();
        userTaskService.completeAutoProgress(foundTask.getId(), "mary", new HashMap<>());
        tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertEquals(1, tasks.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) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) 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 42 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class CaseAssignmentServiceImplTest method testRoleAssignedMissingUser.

@Test
public void testRoleAssignedMissingUser() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("actorRole", new UserImpl("mary"));
    roleAssignments.put("groupRole", new GroupImpl("managers"));
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), CASE_Y_P_ID, data, roleAssignments);
    ((CaseAssignment) caseFile).assignUser("generalRole", "john");
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), CASE_Y_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, "mary", null, new QueryContext());
        assertEquals(5, tasks.size());
        TaskSummary foundTask = tasks.stream().filter(task -> task.getName().equals("Task E")).findFirst().get();
        assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> {
            userTaskService.completeAutoProgress(foundTask.getId(), "mary", new HashMap<>());
        }).withMessageContaining("Case role 'generalRole' has no matching assignments");
    } 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) CaseAssignment(org.kie.api.runtime.process.CaseAssignment) QueryContext(org.kie.api.runtime.query.QueryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) GroupImpl(org.jbpm.services.task.impl.model.GroupImpl) 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 43 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddDynamicUserTaskToEmptyStage.

@Test
public void testAddDynamicUserTaskToEmptyStage() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, caseFile);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(1);
    TaskSummary insideTask = tasks.get(0);
    assertThat(insideTask.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) 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 44 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddMultipleDynamicTasksToStage.

@Test
public void testAddMultipleDynamicTasksToStage() {
    Map<String, Object> data = new HashMap<>();
    data.put("continue", false);
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, data, Collections.emptyMap());
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, caseFile);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
    assertThat(caseInstance).isNotNull();
    assertThat(caseInstance.getCaseStages()).hasSize(1);
    String stageId = caseInstance.getCaseStages().iterator().next().getId();
    caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
    caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(2);
    TaskSummary userTask1 = tasks.get(0);
    assertThat(userTask1.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(userTask1.getId(), USER, null);
    TaskSummary userTask2 = tasks.get(1);
    assertThat(userTask2.getName()).isEqualTo(DYNAMIC_TASK);
    userTaskService.completeAutoProgress(userTask2.getId(), USER, null);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) 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 45 with TaskSummary

use of org.kie.api.task.model.TaskSummary in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddMultipleDynamicSubprocessesToCase.

@Test
public void testAddMultipleDynamicSubprocessesToCase() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    Long subprocessId1 = caseService.addDynamicSubprocess(caseId, SUBPROCESS, Collections.emptyMap());
    ProcessInstanceDesc subprocessInstance1 = runtimeDataService.getProcessInstanceById(subprocessId1);
    assertThat(subprocessInstance1).isNotNull();
    assertThat(subprocessInstance1.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Long subprocessId2 = caseService.addDynamicSubprocess(caseId, SUBPROCESS, Collections.emptyMap());
    ProcessInstanceDesc subprocessInstance2 = runtimeDataService.getProcessInstanceById(subprocessId2);
    assertThat(subprocessInstance2).isNotNull();
    assertThat(subprocessInstance2.getState()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).hasSize(2);
    TaskSummary userTask1 = tasks.get(0);
    assertThat(userTask1.getName()).isEqualTo(SUBPROCESS_TASK);
    userTaskService.completeAutoProgress(userTask1.getId(), USER, null);
    TaskSummary userTask2 = tasks.get(1);
    assertThat(userTask2.getName()).isEqualTo(SUBPROCESS_TASK);
    userTaskService.completeAutoProgress(userTask2.getId(), USER, null);
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
    assertThat(tasks).isEmpty();
    subprocessInstance1 = runtimeDataService.getProcessInstanceById(subprocessId1);
    assertThat(subprocessInstance1).isNotNull();
    assertThat(subprocessInstance1.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    subprocessInstance2 = runtimeDataService.getProcessInstanceById(subprocessId2);
    assertThat(subprocessInstance2).isNotNull();
    assertThat(subprocessInstance2.getState()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

TaskSummary (org.kie.api.task.model.TaskSummary)371 Test (org.junit.Test)327 HashMap (java.util.HashMap)132 QueryFilter (org.kie.internal.query.QueryFilter)126 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)100 Task (org.kie.api.task.model.Task)91 ArrayList (java.util.ArrayList)87 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)86 KieSession (org.kie.api.runtime.KieSession)84 TaskService (org.kie.api.task.TaskService)66 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)58 StringReader (java.io.StringReader)55 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 QueryContext (org.kie.api.runtime.query.QueryContext)49 Status (org.kie.api.task.model.Status)47 InternalTask (org.kie.internal.task.api.model.InternalTask)47 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)41 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)38 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)36 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)28