Search in sources :

Example 1 with CaseDefinition

use of org.kie.server.api.model.cases.CaseDefinition in project droolsjbpm-integration by kiegroup.

the class CaseResource method getCaseDefinitionsByDefinition.

@ApiOperation(value = "Returns information about a specified case definition.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = CaseDefinition.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = CASE_DEFINITION_JSON) })) })
@GET
@Path(CASE_DEFINITIONS_BY_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getCaseDefinitionsByDefinition(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that should be used to filter case definitions", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "case definition id that should be loaded", required = true, example = "CASE-00000000001") @PathParam(CASE_DEF_ID) String caseDefId) {
    return invokeCaseOperation(headers, containerId, null, (Variant v, String type, Header... customHeaders) -> {
        logger.debug("About to look for case definition with id {} in container {}", caseDefId, containerId);
        try {
            CaseDefinition responseObject = this.caseManagementRuntimeDataServiceBase.getCaseDefinition(containerId, caseDefId);
            logger.debug("Returning OK response with content '{}'", responseObject);
            return createCorrectVariant(responseObject, headers, Response.Status.OK, customHeaders);
        } catch (IllegalStateException e) {
            return notFound(MessageFormat.format(CASE_DEFINITION_NOT_FOUND, caseDefId, containerId), v, customHeaders);
        }
    });
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with CaseDefinition

use of org.kie.server.api.model.cases.CaseDefinition in project droolsjbpm-integration by kiegroup.

the class CaseRuntimeDataServiceIntegrationTest method testGetCaseDefinition.

@Test
public void testGetCaseDefinition() {
    CaseDefinition hrCase = caseClient.getCaseDefinition(CONTAINER_ID, CASE_HR_DEF_ID);
    assertHrCaseDefinition(hrCase);
}
Also used : CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest) Test(org.junit.Test)

Example 3 with CaseDefinition

use of org.kie.server.api.model.cases.CaseDefinition in project droolsjbpm-integration by kiegroup.

the class CarInsuranceClaimCaseIntegrationTest method carInsuranceClaimCaseTriggerInStage.

private void carInsuranceClaimCaseTriggerInStage(boolean useExistingStageId, boolean useExistingAdHocName) throws Exception {
    // start case with users assigned to roles
    String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN);
    // let's verify case is created
    assertCaseInstance(caseId);
    // let's look at what stages are active
    assertBuildClaimReportStage(caseId);
    // 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(USER_YODA, USER_JOHN);
    // let's provide claim report with initial data
    // claim report should be stored in case file data
    provideAndAssertClaimReport(caseId, taskId, USER_YODA);
    // now we have another task for insured to provide property damage report
    taskId = assertPropertyDamageReportAvailableForBothRoles(USER_YODA, USER_JOHN);
    // let's provide the property damage report
    provideAndAssertPropertyDamageReport(caseId, taskId, USER_YODA);
    // let's complete the stage by explicitly stating that claimReport is done
    caseClient.putCaseInstanceData(CONTAINER_ID, caseId, "claimReportDone", Boolean.TRUE);
    // we should be in another stage - Claim assessment
    assertClaimAssesmentStage(caseId);
    // let's trigger claim offer calculation
    CaseDefinition definition = caseClient.getCaseDefinition(CONTAINER_ID, CLAIM_CASE_DEF_ID);
    CaseStageDefinition stage = definition.getCaseStages().stream().filter(s -> s.getName().equals("Claim assesment")).findFirst().get();
    List<Integer> activeStatusList = Collections.singletonList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
    if (!useExistingStageId) {
        String stageId = "non existing stage id";
        Assertions.assertThatExceptionOfType(KieServicesException.class).isThrownBy(() -> caseClient.triggerAdHocFragmentInStage(CONTAINER_ID, caseId, stageId, "Calculate claim", null)).withMessageContaining("No stage found with id " + stageId);
        // there should be still process instances for the case
        Collection<ProcessInstance> caseProcesInstances = caseClient.getProcessInstances(CONTAINER_ID, caseId, activeStatusList, 0, 10);
        assertEquals(1, caseProcesInstances.size());
    } else if (!useExistingAdHocName) {
        String adHocName = "non existing ad hoc fragment";
        Assertions.assertThatExceptionOfType(KieServicesException.class).isThrownBy(() -> caseClient.triggerAdHocFragmentInStage(CONTAINER_ID, caseId, stage.getIdentifier(), adHocName, null)).withMessageContaining("AdHoc fragment '" + adHocName + "' not found in case " + caseId + " and stage " + stage.getIdentifier());
        // there should be still process instances for the case
        Collection<ProcessInstance> caseProcesInstances = caseClient.getProcessInstances(CONTAINER_ID, caseId, activeStatusList, 0, 10);
        assertEquals(1, caseProcesInstances.size());
    } else {
        caseClient.triggerAdHocFragmentInStage(CONTAINER_ID, caseId, stage.getIdentifier(), "Calculate claim", null);
        // now we have another task for insured as claim was calculated
        // let's accept the calculated claim
        assertAndAcceptClaimOffer(USER_YODA);
        // there should be no process instances for the case
        Collection<ProcessInstance> caseProcesInstances = caseClient.getProcessInstances(CONTAINER_ID, caseId, activeStatusList, 0, 10);
        assertEquals(0, caseProcesInstances.size());
    }
}
Also used : CaseStageDefinition(org.kie.server.api.model.cases.CaseStageDefinition) CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) Collection(java.util.Collection) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieServicesException(org.kie.server.api.exception.KieServicesException)

Example 4 with CaseDefinition

use of org.kie.server.api.model.cases.CaseDefinition in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getCaseDefinition.

@Override
public CaseDefinition getCaseDefinition(String containerId, String caseDefinitionId) {
    CaseDefinition result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_DEF_ID, caseDefinitionId);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_DEFINITIONS_BY_ID_GET_URI, valuesMap), CaseDefinition.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getCaseDefinition", new Object[] { containerId, caseDefinitionId })));
        ServiceResponse<CaseDefinition> response = (ServiceResponse<CaseDefinition>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    return result;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CaseDefinition(org.kie.server.api.model.cases.CaseDefinition) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

CaseDefinition (org.kie.server.api.model.cases.CaseDefinition)4 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 Test (org.junit.Test)1 CommandScript (org.kie.server.api.commands.CommandScript)1 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)1 KieServicesException (org.kie.server.api.exception.KieServicesException)1 KieServerCommand (org.kie.server.api.model.KieServerCommand)1 ServiceResponse (org.kie.server.api.model.ServiceResponse)1 CaseStageDefinition (org.kie.server.api.model.cases.CaseStageDefinition)1 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)1 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)1 Header (org.kie.server.remote.rest.common.Header)1 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)1