Search in sources :

Example 1 with CaseMigrationReportInstance

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

the class CaseInstanceMigrationIntegrationTest method testCarInsuranceClaimCaseMigrationWithSubprocess.

@Test
public void testCarInsuranceClaimCaseMigrationWithSubprocess() throws Exception {
    // start case with users assigned to roles
    String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN);
    // let's verify case is created
    assertCaseInstance(caseId);
    caseClient.addDynamicSubProcess(CONTAINER_ID, caseId, PROCESS_DEF_ID, null);
    List<ProcessInstance> processInstances = caseClient.getProcessInstances(CONTAINER_ID, caseId, Arrays.asList(1), 0, 10);
    assertThat(processInstances).isNotNull();
    assertThat(processInstances).hasSize(2);
    for (ProcessInstance pi : processInstances) {
        assertThat(pi.getContainerId()).isEqualTo(CONTAINER_ID);
    }
    Map<String, String> processMapping = new HashMap<>();
    processMapping.put(CLAIM_CASE_DEF_ID, CLAIM_CASE_DEF_ID_2);
    processMapping.put(PROCESS_DEF_ID, PROCESS_DEF_ID_2);
    CaseMigrationReportInstance report = caseAdminClient.migrateCaseInstance(CONTAINER_ID, caseId, CONTAINER_ID_2, processMapping);
    assertThat(report).isNotNull();
    assertThat(report.isSuccessful()).isTrue();
    assertMigratedCaseInstance(caseId);
    processInstances = caseClient.getProcessInstances(CONTAINER_ID_2, caseId, Arrays.asList(1), 0, 10);
    assertThat(processInstances).isNotNull();
    assertThat(processInstances).hasSize(2);
    for (ProcessInstance pi : processInstances) {
        assertThat(pi.getContainerId()).isEqualTo(CONTAINER_ID_2);
    }
}
Also used : HashMap(java.util.HashMap) CaseMigrationReportInstance(org.kie.server.api.model.cases.CaseMigrationReportInstance) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Example 2 with CaseMigrationReportInstance

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

the class CaseAdminResource method migrateCaseInstance.

@ApiOperation(value = "Migrates a specified case instance to another KIE container and case definition.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Case instance or Container Id not found"), @ApiResponse(code = 201, response = CaseMigrationReportInstance.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = CASE_MIGRATION_REPORT_JSON) })) })
@PUT
@Path(MIGRATE_CASE_INST_PUT_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response migrateCaseInstance(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that case instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of case instance to be migrated", required = true, example = "CASE-000000001") @PathParam("caseId") String caseId, @ApiParam(value = "container id that new case definition should be migrated to to", required = true) @QueryParam("targetContainerId") String targetContainerId, @ApiParam(value = "process and node mapping - unique ids of old definition to new definition given as Map of Maps - ProcessMapping should provide map of process definitions (mandatory), NodeMapping should provide map of node mappings (optional)", required = false, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = CASE_MIGRATION_MAP_JSON), @ExampleProperty(mediaType = XML, value = CASE_MIGRATION_MAP_XML) })) String payload) {
    return invokeCaseOperation(headers, "", null, (Variant v, String type, Header... customHeaders) -> {
        CaseMigrationReportInstance responseObject = caseAdminServiceBase.migrateCaseInstance(containerId, caseId, targetContainerId, payload, type);
        logger.debug("Returning CREATED response with content '{}'", responseObject);
        return createCorrectVariant(responseObject, headers, Response.Status.CREATED, 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) CaseMigrationReportInstance(org.kie.server.api.model.cases.CaseMigrationReportInstance) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 3 with CaseMigrationReportInstance

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

the class CaseAdminServicesClientImpl method migrateCaseInstance.

@Override
public CaseMigrationReportInstance migrateCaseInstance(String containerId, String caseId, String targetContainerId, Map<String, String> processMapping, Map<String, String> nodeMapping) {
    CaseMigrationReportInstance report = null;
    Map<String, Object> mappings = new HashMap<>();
    mappings.put("ProcessMapping", processMapping);
    mappings.put("NodeMapping", nodeMapping);
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        valuesMap.put(CASE_ID, caseId);
        String queryString = "?targetContainerId=" + targetContainerId;
        report = makeHttpPutRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), ADMIN_CASE_URI + "/" + MIGRATE_CASE_INST_PUT_URI, valuesMap) + queryString, serialize(mappings), CaseMigrationReportInstance.class, new HashMap<>());
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseAdminService", "migrateCaseInstance", serialize(safeMap(mappings)), marshaller.getFormat().getType(), new Object[] { containerId, caseId, targetContainerId })));
        ServiceResponse<CaseMigrationReportInstance> response = (ServiceResponse<CaseMigrationReportInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        report = response.getResult();
    }
    return report;
}
Also used : DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) CaseMigrationReportInstance(org.kie.server.api.model.cases.CaseMigrationReportInstance) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 4 with CaseMigrationReportInstance

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

the class CaseInstanceMigrationIntegrationTest method testCarInsuranceClaimCaseMigration.

@Test
public void testCarInsuranceClaimCaseMigration() throws Exception {
    // start case with users assigned to roles
    String caseId = startCarInsuranceClaimCase(USER_YODA, USER_JOHN);
    // let's verify case is created
    assertCaseInstance(caseId);
    Map<String, String> processMapping = new HashMap<>();
    processMapping.put(CLAIM_CASE_DEF_ID, CLAIM_CASE_DEF_ID_2);
    CaseMigrationReportInstance report = caseAdminClient.migrateCaseInstance(CONTAINER_ID, caseId, CONTAINER_ID_2, processMapping);
    assertThat(report).isNotNull();
    assertThat(report.isSuccessful()).isTrue();
    assertMigratedCaseInstance(caseId);
}
Also used : HashMap(java.util.HashMap) CaseMigrationReportInstance(org.kie.server.api.model.cases.CaseMigrationReportInstance) Test(org.junit.Test) JbpmKieServerBaseIntegrationTest(org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)

Aggregations

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