Search in sources :

Example 1 with CaseMigrationReport

use of org.jbpm.casemgmt.api.admin.CaseMigrationReport in project jbpm by kiegroup.

the class CaseInstanceMigrationServiceImplTest method testMigrateSingleCaseInstanceWithDynamicSubprocessRevert.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testMigrateSingleCaseInstanceWithDynamicSubprocessRevert() {
    String caseId = createCaseInstanceV1();
    try {
        assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1);
        caseService.addDynamicSubprocess(caseId, PROCESS_DEF_ID_V1, null);
        Collection<ProcessInstanceDesc> pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertEquals(2, pInstances.size());
        for (ProcessInstanceDesc instance : pInstances) {
            assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId());
        }
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
        assertNotNull(tasks);
        assertThat(tasks).hasSize(2);
        Map<String, TaskSummary> mappedTasks = mapTaskSummaries(tasks);
        assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1");
        Map<String, String> processMapping = new HashMap<>();
        processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2);
        processMapping.put(PROCESS_DEF_ID_V1, PROCESS_DEF_ID_V3);
        // explicitly without generic to cause error (class cast) in migration process to test revert of case instance migration
        Map erronousMapping = Collections.singletonMap("_22", 2);
        CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping, erronousMapping);
        assertNotNull(report);
        assertThat(report.isSuccessful()).isFalse();
        assertThat(report.getReports()).hasSize(2);
        assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1);
        pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertEquals(2, pInstances.size());
        for (ProcessInstanceDesc instance : pInstances) {
            assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId());
        }
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
        assertNotNull(tasks);
        assertThat(tasks).hasSize(2);
        mappedTasks = mapTaskSummaries(tasks);
        assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1");
        userTaskService.completeAutoProgress(mappedTasks.get("Hello_V1").getId(), USER, null);
        caseService.destroyCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        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 : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseMigrationReport(org.jbpm.casemgmt.api.admin.CaseMigrationReport) TaskSummary(org.kie.api.task.model.TaskSummary) HashMap(java.util.HashMap) Map(java.util.Map) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 2 with CaseMigrationReport

use of org.jbpm.casemgmt.api.admin.CaseMigrationReport in project jbpm by kiegroup.

the class CaseInstanceMigrationServiceImplTest method testMigrateSingleCaseInstanceWithDynamicSubprocessNodeMapping.

@Test
public void testMigrateSingleCaseInstanceWithDynamicSubprocessNodeMapping() {
    String caseId = createCaseInstanceV1();
    try {
        assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1);
        caseService.addDynamicSubprocess(caseId, PROCESS_DEF_ID_V1, null);
        Collection<ProcessInstanceDesc> pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertEquals(2, pInstances.size());
        for (ProcessInstanceDesc instance : pInstances) {
            assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId());
        }
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
        assertNotNull(tasks);
        assertThat(tasks).hasSize(2);
        Map<String, TaskSummary> mappedTasks = mapTaskSummaries(tasks);
        assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1");
        Map<String, String> processMapping = new HashMap<>();
        processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2);
        processMapping.put(PROCESS_DEF_ID_V1, PROCESS_DEF_ID_V3);
        Map<String, String> nodeMapping = new HashMap<>();
        nodeMapping.put("_22", "_33");
        CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping, nodeMapping);
        assertNotNull(report);
        assertThat(report.isSuccessful()).isTrue();
        assertThat(report.getReports()).hasSize(2);
        assertCaseInstance(caseId, deploymentUnitV2.getIdentifier(), CASE_DEF_ID_V2);
        pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertEquals(2, pInstances.size());
        for (ProcessInstanceDesc instance : pInstances) {
            assertEquals(deploymentUnitV2.getIdentifier(), instance.getDeploymentId());
        }
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
        assertNotNull(tasks);
        assertThat(tasks).hasSize(2);
        mappedTasks = mapTaskSummaries(tasks);
        assertThat(mappedTasks).containsKeys("Hello1", "Hello_V3");
        userTaskService.completeAutoProgress(mappedTasks.get("Hello_V3").getId(), USER, null);
        caseService.destroyCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        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 : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseMigrationReport(org.jbpm.casemgmt.api.admin.CaseMigrationReport) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 3 with CaseMigrationReport

use of org.jbpm.casemgmt.api.admin.CaseMigrationReport in project droolsjbpm-integration by kiegroup.

the class CaseAdminServiceBase method migrateCaseInstance.

public CaseMigrationReportInstance migrateCaseInstance(String containerId, String caseId, String targetContainerId, String payload, String marshallingType) {
    Map<String, Object> mapping = Collections.emptyMap();
    if (payload != null) {
        logger.debug("About to unmarshal mapping from payload: '{}' using container {} marshaller", payload, containerId);
        mapping = marshallerHelper.unmarshal(containerId, payload, marshallingType, Map.class);
    }
    if (mapping == null || !mapping.containsKey("ProcessMapping")) {
        throw new IllegalArgumentException("Case instance migration requires ProcessMapping to be provided");
    }
    Map<String, String> processMapping = (Map<String, String>) mapping.get("ProcessMapping");
    Map<String, String> nodeMapping = (Map<String, String>) mapping.getOrDefault("NodeMapping", Collections.emptyMap());
    logger.debug("About to migrate case instance with id {} from container '{}' to container '{}' with process mapping '{}' and with node mapping {}", caseId, containerId, targetContainerId, processMapping, nodeMapping);
    CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, targetContainerId, processMapping, nodeMapping);
    logger.debug("Migration of case instance {} finished with report {}", caseId, report);
    return ConvertUtils.convertCaseMigrationReport(caseId, report);
}
Also used : CaseMigrationReport(org.jbpm.casemgmt.api.admin.CaseMigrationReport) Map(java.util.Map)

Example 4 with CaseMigrationReport

use of org.jbpm.casemgmt.api.admin.CaseMigrationReport in project jbpm by kiegroup.

the class CaseInstanceMigrationServiceImplTest method testMigrateSingleCaseInstanceWithDynamicSubprocess.

@Test
public void testMigrateSingleCaseInstanceWithDynamicSubprocess() {
    String caseId = createCaseInstanceV1();
    try {
        assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1);
        caseService.addDynamicSubprocess(caseId, PROCESS_DEF_ID_V1, null);
        Collection<ProcessInstanceDesc> pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertEquals(2, pInstances.size());
        for (ProcessInstanceDesc instance : pInstances) {
            assertEquals(deploymentUnitV1.getIdentifier(), instance.getDeploymentId());
        }
        List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
        assertNotNull(tasks);
        assertThat(tasks).hasSize(2);
        Map<String, TaskSummary> mappedTasks = mapTaskSummaries(tasks);
        assertThat(mappedTasks).containsKeys("Hello1", "Hello_V1");
        Map<String, String> processMapping = new HashMap<>();
        processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2);
        processMapping.put(PROCESS_DEF_ID_V1, PROCESS_DEF_ID_V2);
        CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping);
        assertNotNull(report);
        assertThat(report.isSuccessful()).isTrue();
        assertThat(report.getReports()).hasSize(2);
        assertCaseInstance(caseId, deploymentUnitV2.getIdentifier(), CASE_DEF_ID_V2);
        pInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
        assertEquals(2, pInstances.size());
        for (ProcessInstanceDesc instance : pInstances) {
            assertEquals(deploymentUnitV2.getIdentifier(), instance.getDeploymentId());
        }
        tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
        assertNotNull(tasks);
        assertThat(tasks).hasSize(2);
        mappedTasks = mapTaskSummaries(tasks);
        assertThat(mappedTasks).containsKeys("Hello1", "Hello_V2");
        userTaskService.completeAutoProgress(mappedTasks.get("Hello_V2").getId(), USER, null);
        caseService.destroyCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        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 : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) QueryFilter(org.kie.internal.query.QueryFilter) CaseMigrationReport(org.jbpm.casemgmt.api.admin.CaseMigrationReport) TaskSummary(org.kie.api.task.model.TaskSummary) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Example 5 with CaseMigrationReport

use of org.jbpm.casemgmt.api.admin.CaseMigrationReport in project jbpm by kiegroup.

the class CaseInstanceMigrationServiceImplTest method testMigrateSingleCaseInstance.

@Test
public void testMigrateSingleCaseInstance() {
    String caseId = createCaseInstanceV1();
    try {
        assertCaseInstance(caseId, deploymentUnitV1.getIdentifier(), CASE_DEF_ID_V1);
        Map<String, String> processMapping = new HashMap<>();
        processMapping.put(CASE_DEF_ID_V1, CASE_DEF_ID_V2);
        CaseMigrationReport report = caseInstanceMigrationService.migrate(caseId, deploymentUnitV2.getIdentifier(), processMapping);
        assertNotNull(report);
        assertThat(report.isSuccessful()).isTrue();
        assertThat(report.getReports()).hasSize(1);
        assertCaseInstance(caseId, deploymentUnitV2.getIdentifier(), CASE_DEF_ID_V2);
        caseService.destroyCase(caseId);
        CaseInstance instance = caseService.getCaseInstance(caseId);
        Assertions.assertThat(instance.getStatus()).isEqualTo(CaseStatus.CANCELLED.getId());
        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 : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) HashMap(java.util.HashMap) CaseMigrationReport(org.jbpm.casemgmt.api.admin.CaseMigrationReport) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) AbstractCaseServicesBaseTest(org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest) Test(org.junit.Test)

Aggregations

CaseMigrationReport (org.jbpm.casemgmt.api.admin.CaseMigrationReport)6 HashMap (java.util.HashMap)5 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)5 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)4 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)4 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)4 Test (org.junit.Test)4 QueryContext (org.kie.api.runtime.query.QueryContext)4 Map (java.util.Map)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 QueryFilter (org.kie.internal.query.QueryFilter)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 UpdateCaseFileInstanceCommand (org.jbpm.casemgmt.impl.command.UpdateCaseFileInstanceCommand)1 MigrationReport (org.jbpm.services.api.admin.MigrationReport)1 CompositeCommand (org.jbpm.shared.services.impl.commands.CompositeCommand)1 UpdateStringCommand (org.jbpm.shared.services.impl.commands.UpdateStringCommand)1