Search in sources :

Example 11 with CaseStageInstance

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

the class CaseServiceImplTest method testUserTaskToCaseWithStageComplete.

@Test
public void testUserTaskToCaseWithStageComplete() {
    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());
        Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
        assertNotNull(activeStages);
        assertEquals(1, activeStages.size());
        caseService.addDataToCaseFile(caseId, "dataComplete", true);
        activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
        assertNotNull(activeStages);
        assertEquals(0, activeStages.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) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) 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 12 with CaseStageInstance

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

the class StageActivationConditionTest method testAutoComplete.

@Test
public void testAutoComplete() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_ACTIVATION_COND);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    assertCaseInstanceActive(caseId);
    Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
    assertThat(activeStages).hasSize(0);
    caseService.addDataToCaseFile(caseId, "readyToActivate", true);
    activeStages = caseRuntimeDataService.getCaseInstanceStages(caseId, true, new QueryContext());
    assertThat(activeStages).hasSize(1);
    caseService.addDataToCaseFile(caseId, "readyToComplete", true);
    assertCaseInstanceNotActive(caseId);
}
Also used : CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 13 with CaseStageInstance

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

the class CarInsuranceClaimCaseTest method assertClaimAssesmentStage.

protected void assertClaimAssesmentStage() {
    Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(CAR_INS_CASE_ID, true, new QueryContext());
    assertEquals(1, activeStages.size());
    CaseStageInstance stage = activeStages.iterator().next();
    assertEquals("Claim assesment", stage.getName());
}
Also used : CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext)

Example 14 with CaseStageInstance

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

the class CarInsuranceClaimCaseTest method assertAndNegotiateClaimOffer.

protected void assertAndNegotiateClaimOffer(int numberOfNegotiations) {
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    assertTask(tasks.get(0), "john", "Present calculated claim", Status.Reserved);
    // let's accept the calculated claim
    Map<String, Object> params = new HashMap<>();
    params.put("accepted", false);
    userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
    Collection<CaseStageInstance> activeStages = caseRuntimeDataService.getCaseInstanceStages(CAR_INS_CASE_ID, true, new QueryContext());
    assertEquals(1, activeStages.size());
    CaseStageInstance stage = activeStages.iterator().next();
    assertEquals("Escalate rejected claim", stage.getName());
    while (numberOfNegotiations > 0) {
        params.clear();
        params.put("Offer", 1000);
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Negotiation meeting", params);
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
        assertNotNull(tasks);
        assertEquals(1, tasks.size());
        assertTask(tasks.get(0), null, "Negotiation meeting", Status.Ready);
        boolean accepted = false;
        if (numberOfNegotiations == 1) {
            accepted = true;
        }
        params.put("accepted", accepted);
        userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", params);
        numberOfNegotiations--;
    }
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) HashMap(java.util.HashMap) TaskSummary(org.kie.api.task.model.TaskSummary) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext)

Example 15 with CaseStageInstance

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

the class CaseRuntimeDataServiceImpl method getCaseInstanceStages.

@Override
public Collection<CaseStageInstance> getCaseInstanceStages(String caseId, boolean activeOnly, QueryContext queryContext) {
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceByCorrelationKey(correlationKeyFactory.newCorrelationKey(caseId));
    if (pi == null || !pi.getState().equals(ProcessInstance.STATE_ACTIVE)) {
        throw new CaseNotFoundException("No case instance found with id " + caseId + " or it's not active anymore");
    }
    CaseDefinition caseDef = getCase(pi.getDeploymentId(), pi.getProcessId());
    List<CaseStageInstance> stages = internalGetCaseStages(caseDef, caseId, activeOnly, queryContext);
    return applyPagination(stages, queryContext);
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException)

Aggregations

CaseStageInstance (org.jbpm.casemgmt.api.model.instance.CaseStageInstance)15 QueryContext (org.kie.api.runtime.query.QueryContext)12 HashMap (java.util.HashMap)9 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)8 Test (org.junit.Test)8 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)7 UserImpl (org.jbpm.services.task.impl.model.UserImpl)7 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)7 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)6 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)4 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)4 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)4 AdHocFragment (org.jbpm.casemgmt.api.model.AdHocFragment)4 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)4 TaskSummary (org.kie.api.task.model.TaskSummary)4 ArrayList (java.util.ArrayList)3 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)3 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)3 List (java.util.List)2