Search in sources :

Example 31 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCase.

@Test
public void testCarInsuranceClaimCase() {
    // 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();
        // 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();
        // let's trigger claim offer calculation
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Calculate claim", null);
        // 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 : 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 32 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class CarInsuranceClaimCaseTest method testCarInsuranceClaimCaseWithContactByInsured.

@Test(timeout = 10000)
public void testCarInsuranceClaimCaseWithContactByInsured() {
    // 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();
        // 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);
        // before completing claim report, let's call insurance company with some questions
        // when call is answered insurance representative gets a task
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Contacted by insured", null);
        attachAndAssertPoliceReport(false, null);
        // still not satisfied, let's call insurance company with these questions again and ask for callback in 2 sec
        // when call is answered insurance representative gets a task
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Contacted by insured", null);
        attachAndAssertPoliceReport(true, "2s");
        // 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();
        // let's trigger claim offer calculation
        caseService.triggerAdHocFragment(CAR_INS_CASE_ID, "Calculate claim", null);
        // 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 : 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 33 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class CaseDynamicNodesTest method testAddDynamicTaskToNotExistingStageByProcessInstanceId.

@Test
public void testAddDynamicTaskToNotExistingStageByProcessInstanceId() {
    String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
    assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
    Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
    assertThat(caseProcessInstances).isNotNull().hasSize(1);
    ProcessInstanceDesc processInstance = caseProcessInstances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.getCorrelationKey()).isEqualTo(FIRST_CASE_ID);
    assertThatThrownBy(() -> caseService.addDynamicTaskToStage(processInstance.getId(), NOT_EXISTING_STAGE, createUserTask())).isInstanceOf(StageNotFoundException.class);
}
Also used : 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 34 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc 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)

Example 35 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class CancelCaseCommand method execute.

@Override
public Void execute(Context context) {
    CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
    Collection<ProcessInstanceDesc> caseProcesses = runtimeDataService.getProcessInstancesByCorrelationKey(correlationKey, new QueryContext(0, 1000));
    if (caseProcesses.isEmpty()) {
        throw new CaseNotFoundException("Case with id " + caseId + " was not found");
    }
    List<Long> processInstanceIds = caseProcesses.stream().filter(pi -> pi.getState().equals(ProcessInstance.STATE_ACTIVE)).sorted((ProcessInstanceDesc o1, ProcessInstanceDesc o2) -> {
        return Long.valueOf(o2.getParentId()).compareTo(Long.valueOf(o1.getParentId()));
    }).map(pi -> pi.getId()).collect(toList());
    CaseEventSupport caseEventSupport = getCaseEventSupport(context);
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    CaseFileInstance caseFile = getCaseFile(ksession, caseId);
    caseEventSupport.fireBeforeCaseCancelled(caseId, caseFile, processInstanceIds);
    logger.debug("Case {} consists of following process instances (ids) {}", caseId, processInstanceIds);
    processService.abortProcessInstances(processInstanceIds);
    caseEventSupport.fireAfterCaseCancelled(caseId, caseFile, processInstanceIds);
    if (destroy) {
        RuntimeManager runtimeManager = getRuntimeManager(context);
        if (runtimeManager instanceof PerCaseRuntimeManager) {
            caseEventSupport.fireBeforeCaseDestroyed(caseId, caseFile, processInstanceIds);
            logger.debug("Case {} aborted, destroying case data including per case runtime engine (including working memory)", caseId);
            ((PerCaseRuntimeManager) runtimeManager).destroyCase(CaseContext.get(caseId));
            caseEventSupport.fireAfterCaseDestroyed(caseId, caseFile, processInstanceIds);
        }
    }
    return null;
}
Also used : IdentityProvider(org.kie.internal.identity.IdentityProvider) RegistryContext(org.drools.core.command.impl.RegistryContext) Logger(org.slf4j.Logger) ProcessService(org.jbpm.services.api.ProcessService) CorrelationKey(org.kie.internal.process.CorrelationKey) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) QueryContext(org.kie.api.runtime.query.QueryContext) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Context(org.kie.api.runtime.Context) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) KieSession(org.kie.api.runtime.KieSession) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) CaseContext(org.kie.internal.runtime.manager.context.CaseContext) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) PerCaseRuntimeManager(org.jbpm.runtime.manager.impl.PerCaseRuntimeManager) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) RegistryContext(org.drools.core.command.impl.RegistryContext) QueryContext(org.kie.api.runtime.query.QueryContext) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CorrelationKey(org.kie.internal.process.CorrelationKey) KieSession(org.kie.api.runtime.KieSession)

Aggregations

ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)198 Test (org.junit.Test)147 QueryContext (org.kie.api.runtime.query.QueryContext)123 ArrayList (java.util.ArrayList)75 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)57 HashMap (java.util.HashMap)32 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)25 TaskSummary (org.kie.api.task.model.TaskSummary)25 QueryFilter (org.kie.internal.query.QueryFilter)23 RemoteEjbTest (org.jbpm.remote.ejb.test.RemoteEjbTest)17 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)16 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)16 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)15 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)12 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)12 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)12 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 CorrelationKey (org.kie.internal.process.CorrelationKey)11 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)9 List (java.util.List)7