MohammadMu99 commented on code in PR #7259:
URL: https://github.com/apache/incubator-kie/pull/7259#discussion_r4534663916


##########
kogito-jbpm/jbpm-flow-migration/src/main/java/org/jbpm/flow/migration/MigrationPlanService.java:
##########
@@ -69,11 +73,39 @@ public void migrateProcessElement(Processes processes, 
KogitoWorkflowProcessInst
             RuleFlowProcessInstance ruleFlowProcessInstance = 
(RuleFlowProcessInstance) processInstance;
             
ruleFlowProcessInstance.setProcessId(plan.getProcessMigrationPlan().getTargetProcessDefinition().getProcessId());
             
ruleFlowProcessInstance.setProcessVersion(plan.getProcessMigrationPlan().getTargetProcessDefinition().getProcessVersion());
+            migrateVariables(ruleFlowProcessInstance, 
plan.getProcessMigrationPlan().getVariableMigrationPlan());
         } else {
             LOGGER.debug("Process instance {} won't be migrated", 
processInstance);
         }
     }
 
+    private void migrateVariables(RuleFlowProcessInstance processInstance, 
List<VariableMigrationPlan> variableMigrationPlans) {
+        if (variableMigrationPlans.isEmpty()) {
+            return;
+        }
+        VariableScopeInstance variableScope = (VariableScopeInstance) 
processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
+        for (VariableMigrationPlan variablePlan : variableMigrationPlans) {
+            LOGGER.debug("Applying {} to process instance {}", variablePlan, 
processInstance.getStringId());
+            switch (variablePlan.getAction()) {
+                case RENAME:
+                    Object value = 
variableScope.getVariables().get(variablePlan.getFrom());
+                    if (value != null) {
+                        
variableScope.internalSetVariable(variablePlan.getTo(), value);
+                        
variableScope.internalSetVariable(variablePlan.getFrom(), null);
+                    }
+                    break;
+                case DEFAULT:
+                    if 
(variableScope.getVariables().get(variablePlan.getName()) == null) {
+                        
variableScope.internalSetVariable(variablePlan.getName(), 
variablePlan.getValue());
+                    }
+                    break;
+                case REMOVE:
+                    variableScope.internalSetVariable(variablePlan.getName(), 
null);

Review Comment:
   Documented on both VariableMigrationPlan and the new VariableMigrator class: 
rename and remove set the old variable to null, and the name stays in the 
instance variables, since there’s no API to remove an entry.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to