Search in sources :

Example 16 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseServiceImplTest method testCaseWithStageAutoStartNodes.

@Test
public void testCaseWithStageAutoStartNodes() {
    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_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_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 = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(2, tasks.size());
        assertTask(tasks.get(0), "john", "Ask for input", Status.Reserved);
        assertTask(tasks.get(1), "john", "Missing data", Status.Reserved);
    } 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) 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) 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 17 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CaseServiceImplTest method testCaseWithDefinedDataRestrictionsSetViaUserTask.

@Test
public void testCaseWithDefinedDataRestrictionsSetViaUserTask() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("participant", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("contactInfo", "main street 10, NYC");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_DATA_RESTRICTIONS_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_DATA_RESTRICTIONS_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(FIRST_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        Map<String, Object> caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(1, caseData.size());
        assertEquals("main street 10, NYC", caseData.get("contactInfo"));
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        Map<String, Object> params = new HashMap<>();
        params.put("reply_", "John sets the reply via process");
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(1, caseData.size());
        assertEquals("main street 10, NYC", caseData.get("contactInfo"));
        identityProvider.setName("mary");
        cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
        assertNotNull(cInstance);
        caseData = cInstance.getCaseFile().getData();
        assertNotNull(caseData);
        assertEquals(1, caseData.size());
        assertEquals("John sets the reply via process", caseData.get("reply"));
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            identityProvider.setName("john");
            caseService.cancelCase(caseId);
        }
    }
}
Also used : OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) 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) 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 18 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class SubCaseServiceImplTest method testStartCaseWithSubCaseDestroySubCase.

@Test
public void testStartCaseWithSubCaseDestroySubCase() {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("owner", new UserImpl("john"));
    roleAssignments.put("manager", new UserImpl("mary"));
    Map<String, Object> data = new HashMap<>();
    data.put("name", "John Doe");
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), BASIC_SUB_CASE_P_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(SUB_CASE_ID, caseId);
    try {
        CaseInstance cInstance = caseService.getCaseInstance(caseId);
        assertNotNull(cInstance);
        assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
        caseService.triggerAdHocFragment(caseId, "Sub Case", null);
        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(SUB_CASE_ID));
        assertTrue(byCaseId.containsKey(HR_CASE_ID));
        List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertEquals("Hello1", tasks.get(0).getName());
        CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
        assertNotNull(mainCaseFile);
        assertNull(mainCaseFile.getData("subCaseId"));
        caseService.destroyCase(HR_CASE_ID);
        mainCaseFile = caseService.getCaseFileInstance(caseId);
        assertNotNull(mainCaseFile);
        assertEquals(HR_CASE_ID, mainCaseFile.getData("subCaseId"));
        assertEquals("John Doe", mainCaseFile.getData("outcome"));
    } 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) 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 19 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseWithAssessorInvolved.

@Test
public void testCarInsuranceClaimCaseWithAssessorInvolved() {
    // let's assign users to roles so they can be participants in the case
    String caseId = startAndAssertCaseInstance(deploymentUnit.getIdentifier(), "john", "mary");
    try {
        // let's verify case is created
        assertCaseInstance(deploymentUnit.getIdentifier(), CAR_INS_CASE_ID);
        // let's look at what stages are active
        assertBuildClaimReportStage();
        // let's now add assessor to the case as we will need his/her opinion
        caseService.assignToCaseRole(CAR_INS_CASE_ID, "assessor", new UserImpl("krisv"));
        // since the first task assigned to insured is with auto start it should be already active
        // the same task can be claimed by insuranceRepresentative in case claim is reported over phone
        long taskId = assertBuildClaimReportAvailableForBothRoles();
        // let's provide claim report with initial data
        // claim report should be stored in case file data
        provideAndAssertClaimReport(taskId);
        // now we have another task for insured to provide property damage report
        taskId = assertPropertyDamageReportAvailableForBothRoles();
        // let's provide the property damage report
        provideAndAssertPropertyDamageReport(taskId);
        // let's complete the stage by explicitly stating that claimReport is done
        caseService.addDataToCaseFile(CAR_INS_CASE_ID, "claimReportDone", true);
        // we should be in another stage - Claim assessment
        assertClaimAssesmentStage();
        // now krisv should have a task assigned as assessor
        assertAndRunClaimAssessment();
        // now we have another task for insured as claim was calculated
        // let's accept the calculated claim
        assertAndAcceptClaimOffer();
        // there should be no process instances for the case
        Collection<ProcessInstanceDesc> caseProcesInstances = caseRuntimeDataService.getProcessInstancesForCase(CAR_INS_CASE_ID, Arrays.asList(ProcessInstance.STATE_ACTIVE), new QueryContext());
        assertEquals(0, caseProcesInstances.size());
        caseId = null;
    } catch (Exception e) {
        logger.error("Unexpected error {}", e.getMessage(), e);
        fail("Unexpected exception " + e.getMessage());
    } finally {
        if (caseId != null) {
            caseService.cancelCase(caseId);
        }
    }
}
Also used : UserImpl(org.jbpm.services.task.impl.model.UserImpl) 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 20 with UserImpl

use of org.jbpm.services.task.impl.model.UserImpl in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method startAndAssertCaseInstance.

protected String startAndAssertCaseInstance(String deploymentId, String insured, String insuranceRepresentative) {
    Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
    roleAssignments.put("insured", new UserImpl(insured));
    roleAssignments.put("insuranceRepresentative", new UserImpl(insuranceRepresentative));
    roleAssignments.put("assessor", new UserImpl("krisv"));
    // start new instance of a case with data and role assignment
    Map<String, Object> data = new HashMap<>();
    CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentId, CAR_INSURANCE_CLAIM_PROC_ID, data, roleAssignments);
    String caseId = caseService.startCase(deploymentId, CAR_INSURANCE_CLAIM_PROC_ID, caseFile);
    assertNotNull(caseId);
    assertEquals(CAR_INS_CASE_ID, caseId);
    return caseId;
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) OrganizationalEntity(org.kie.api.task.model.OrganizationalEntity) HashMap(java.util.HashMap) UserImpl(org.jbpm.services.task.impl.model.UserImpl)

Aggregations

UserImpl (org.jbpm.services.task.impl.model.UserImpl)57 Test (org.junit.Test)52 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)51 HashMap (java.util.HashMap)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)49 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)49 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)42 QueryContext (org.kie.api.runtime.query.QueryContext)33 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)25 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)25 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)25 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)25 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)25 TaskSummary (org.kie.api.task.model.TaskSummary)21 QueryFilter (org.kie.internal.query.QueryFilter)10 ArrayList (java.util.ArrayList)9 GroupImpl (org.jbpm.services.task.impl.model.GroupImpl)9 CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)8 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)7 CaseAssignment (org.kie.api.runtime.process.CaseAssignment)7