ProcessInstanceMigrationServiceImpl implements ProcessInstanceMigrationService { @Override public MigrationReport migrate(String sourceDeploymentId, Long processInstanceId, String targetDeploymentId, String targetProcessId) { MigrationSpec migrationSpec = new MigrationSpec(sourceDeploymentId, processInstanceId, targetDeploymentId, targetProcessId); MigrationManager migrationManager = new MigrationManager(migrationSpec); org.jbpm.runtime.manager.impl.migration.MigrationReport report = null; try { report = migrationManager.migrate(); } catch (MigrationException e) { report = e.getReport(); } return convert(report); } ProcessInstanceMigrationServiceImpl(); @Override MigrationReport migrate(String sourceDeploymentId, Long processInstanceId, String targetDeploymentId, String targetProcessId); @Override MigrationReport migrate(String sourceDeploymentId, Long processInstanceId, String targetDeploymentId, String targetProcessId, Map<String, String> nodeMapping); @Override List<MigrationReport> migrate(String sourceDeploymentId, List<Long> processInstanceIds, String targetDeploymentId, String targetProcessId); @Override List<MigrationReport> migrate(String sourceDeploymentId, List<Long> processInstanceIds, String targetDeploymentId, String targetProcessId, Map<String, String> nodeMapping);  }
@Test public void testMigrateSingleProcessInstance() { long processInstanceId = processService.startProcess(deploymentUnitV1.getIdentifier(), ADDTASKAFTERACTIVE_ID_V1); assertNotNull(processInstanceId); MigrationReport report = migrationService.migrate(deploymentUnitV1.getIdentifier(), processInstanceId, deploymentUnitV2.getIdentifier(), ADDTASKAFTERACTIVE_ID_V2); assertNotNull(report); assertTrue(report.isSuccessful()); assertMigratedProcessInstance(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, ProcessInstance.STATE_ACTIVE); assertMigratedTaskAndComplete(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, "Active Task"); assertMigratedTaskAndComplete(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, "Added Task"); assertMigratedProcessInstance(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, ProcessInstance.STATE_COMPLETED); }
@Test public void testMigrateMultipleProcessInstances() { List<Long> ids = new ArrayList<Long>(); for (int i = 0; i < 5; i++) { long processInstanceId = processService.startProcess(deploymentUnitV1.getIdentifier(), ADDTASKAFTERACTIVE_ID_V1); assertNotNull(processInstanceId); ids.add(processInstanceId); } List<MigrationReport> reports = migrationService.migrate(deploymentUnitV1.getIdentifier(), ids, deploymentUnitV2.getIdentifier(), ADDTASKAFTERACTIVE_ID_V2); assertNotNull(reports); Iterator<MigrationReport> reportsIt = reports.iterator(); for (Long processInstanceId : ids) { MigrationReport report = reportsIt.next(); assertTrue(report.isSuccessful()); assertMigratedProcessInstance(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, ProcessInstance.STATE_ACTIVE); assertMigratedTaskAndComplete(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, "Active Task"); assertMigratedTaskAndComplete(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, "Added Task"); assertMigratedProcessInstance(ADDTASKAFTERACTIVE_ID_V2, processInstanceId, ProcessInstance.STATE_COMPLETED); } }
@Test public void testMigrateSingleProcessInstanceWithNodeMapping() { String activeNodeId = "_ECEDD1CE-7380-418C-B7A6-AF8ECB90B820"; String nextNodeId = "_9EF3CAE0-D978-4E96-9C00-8A80082EB68E"; Map<String, String> nodeMapping = new HashMap<String, String>(); nodeMapping.put(activeNodeId, nextNodeId); long processInstanceId = processService.startProcess(deploymentUnitV1.getIdentifier(), REMOVEACTIVETASK_ID_V1); assertNotNull(processInstanceId); MigrationReport report = migrationService.migrate(deploymentUnitV1.getIdentifier(), processInstanceId, deploymentUnitV2.getIdentifier(), REMOVEACTIVETASK_ID_V2, nodeMapping); assertNotNull(report); assertTrue(report.isSuccessful()); assertMigratedProcessInstance(REMOVEACTIVETASK_ID_V2, processInstanceId, ProcessInstance.STATE_ACTIVE); assertMigratedTaskAndComplete(REMOVEACTIVETASK_ID_V2, processInstanceId, "Mapped Task"); assertMigratedProcessInstance(REMOVEACTIVETASK_ID_V2, processInstanceId, ProcessInstance.STATE_COMPLETED); }
@Test public void testMigrateMultipleProcessInstancesWithNodeMapping() { List<Long> ids = new ArrayList<Long>(); for (int i = 0; i < 5; i++) { long processInstanceId = processService.startProcess(deploymentUnitV1.getIdentifier(), REMOVEACTIVETASK_ID_V1); assertNotNull(processInstanceId); ids.add(processInstanceId); } String activeNodeId = "_ECEDD1CE-7380-418C-B7A6-AF8ECB90B820"; String nextNodeId = "_9EF3CAE0-D978-4E96-9C00-8A80082EB68E"; Map<String, String> nodeMapping = new HashMap<String, String>(); nodeMapping.put(activeNodeId, nextNodeId); List<MigrationReport> reports = migrationService.migrate(deploymentUnitV1.getIdentifier(), ids, deploymentUnitV2.getIdentifier(), REMOVEACTIVETASK_ID_V2, nodeMapping); assertNotNull(reports); Iterator<MigrationReport> reportsIt = reports.iterator(); for (Long processInstanceId : ids) { MigrationReport report = reportsIt.next(); assertTrue(report.isSuccessful()); assertMigratedProcessInstance(REMOVEACTIVETASK_ID_V2, processInstanceId, ProcessInstance.STATE_ACTIVE); assertMigratedTaskAndComplete(REMOVEACTIVETASK_ID_V2, processInstanceId, "Mapped Task"); assertMigratedProcessInstance(REMOVEACTIVETASK_ID_V2, processInstanceId, ProcessInstance.STATE_COMPLETED); } }
@Test public void testMigrateSingleProcessInstanceWithoutNodeMappingWithNodeOrderChange() { long processInstanceId = processService.startProcess(deploymentUnitV1.getIdentifier(), RECREATEACTIVETASK_ID_V1); assertNotNull(processInstanceId); MigrationReport report = migrationService.migrate(deploymentUnitV1.getIdentifier(), processInstanceId, deploymentUnitV2.getIdentifier(), RECREATEACTIVETASK_ID_V2); assertNotNull(report); assertFalse(report.isSuccessful()); MigrationEntry error = report.getEntries().stream().filter(e -> e.getType().equals("ERROR")).findFirst().get(); assertNotNull(error); assertEquals("Node with id _54C7BD3A-0BE4-4C87-9689-C492B8469D2D was not found in new process definition", error.getMessage()); }