from = getNodeId(((WorkflowProcess) processFrom).getNodes(), entry.getKey(), true); } else if (processFrom instanceof RuleFlowProcess) { from = getNodeId(((RuleFlowProcess) processFrom).getNodes(), entry.getKey(), true); } else if (processFrom != null) { throw new IllegalArgumentException("Suported processes are WorkflowProcess and RuleFlowProcess, it was:" + processFrom.getClass()); to = Long.valueOf(getNodeId(((WorkflowProcess) processTo).getNodes(), entry.getValue(), false)); } else if (processTo instanceof RuleFlowProcess) { to = Long.valueOf(getNodeId(((RuleFlowProcess) processTo).getNodes(), entry.getValue(), false)); } else if (processTo != null) { throw new IllegalArgumentException("Suported processes are WorkflowProcess and RuleFlowProcess, it was:" + processTo.getClass()); upgradeProcessInstance(kruntime, fromProcessId, toProcessId, nodeIdMapping);
processInstance.disconnect(); processInstance.setProcess(oldProcess); updateNodeInstances(processInstance, nodeMapping); processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) kruntime); processInstance.setProcess(process);
mapping.put("2", 102L); WorkflowProcessInstanceUpgrader.upgradeProcessInstance( session, processInstance.getId(), "org.test.ruleflow2", mapping); assertEquals("org.test.ruleflow2", processInstance.getProcessId());
kbase.addPackages( builder.getKnowledgePackages() ); WorkflowProcessInstanceUpgrader.upgradeProcessInstance( session, processInstance.getId(), "org.test.ruleflow2", new HashMap<String, Long>()); assertEquals("org.test.ruleflow2", processInstance.getProcessId());
from = getNodeId(((WorkflowProcess) processFrom).getNodes(), entry.getKey(), true); } else if (processFrom instanceof RuleFlowProcess) { from = getNodeId(((RuleFlowProcess) processFrom).getNodes(), entry.getKey(), true); } else if (processFrom != null) { throw new IllegalArgumentException("Suported processes are WorkflowProcess and RuleFlowProcess, it was:" + processFrom.getClass()); to = Long.valueOf(getNodeId(((WorkflowProcess) processTo).getNodes(), entry.getValue(), false)); } else if (processTo instanceof RuleFlowProcess) { to = Long.valueOf(getNodeId(((RuleFlowProcess) processTo).getNodes(), entry.getValue(), false)); } else if (processTo != null) { throw new IllegalArgumentException("Suported processes are WorkflowProcess and RuleFlowProcess, it was:" + processTo.getClass()); upgradeProcessInstance(kruntime, fromProcessId, toProcessId, nodeIdMapping);
mapping.put("2:1", 101L); WorkflowProcessInstanceUpgrader.upgradeProcessInstance( session, processInstance.getId(), "org.test.ruleflow2", mapping); assertEquals("org.test.ruleflow2", processInstance.getProcessId());
private static void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) { for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) { String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId(); Long newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { newNodeId = nodeInstance.getNodeId(); } // clean up iteration levels for removed (old) nodes Map<String, Integer> iterLevels = ((WorkflowProcessInstanceImpl) nodeInstance.getProcessInstance()).getIterationLevels(); String uniqueId = (String) ((NodeImpl) nodeInstance.getNode()).getMetaData("UniqueId"); iterLevels.remove(uniqueId); // and now set to new node id ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId); if (nodeInstance instanceof NodeInstanceContainer) { updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping); } } }
processInstance.disconnect(); processInstance.setProcess(oldProcess); updateNodeInstances(processInstance, nodeMapping); processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) kruntime); processInstance.setProcess(process);
private static void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, Long> nodeMapping) { for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) { String oldNodeId = ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getUniqueId(); Long newNodeId = nodeMapping.get(oldNodeId); if (newNodeId == null) { newNodeId = nodeInstance.getNodeId(); } // clean up iteration levels for removed (old) nodes Map<String, Integer> iterLevels = ((WorkflowProcessInstanceImpl) nodeInstance.getProcessInstance()).getIterationLevels(); String uniqueId = (String) ((NodeImpl) nodeInstance.getNode()).getMetaData("UniqueId"); iterLevels.remove(uniqueId); // and now set to new node id ((NodeInstanceImpl) nodeInstance).setNodeId(newNodeId); if (nodeInstance instanceof NodeInstanceContainer) { updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping); } } }