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