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);
}
}
}
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);
}
}
}
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);
}
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);
}
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;
}
Aggregations