Hi Arshad,
we have implemented some code that can do easy updates to new process definitions (in the
case when the new process has the same node). That code can easly be enhanced to give some
node-map as tom mentioned.
This code will get into a jbpm action soon, but sadly I havn't got time for it the
last weeks...
The current code looks like this:
| jbpmContext = getJbpmContext();
|
| ProcessInstance pi =
jbpmContext.getGraphSession().loadProcessInstance(processId);
|
| changeTokenVersion(jbpmContext, pi.getRootToken(), newVersion);
|
| ProcessDefinition oldDef = pi.getProcessDefinition();
| ProcessDefinition newDef =
jbpmContext.getGraphSession().findProcessDefinition(oldDef.getName(), newVersion);
|
| logger.debug("changes process id " + pi.getId() + " from
version " + pi.getProcessDefinition().getVersion() + " to new version " +
newDef.getVersion());
| // you need tthe right or a patched version for this, see
http://jira.jboss.com/jira/browse/JBPM-585
| pi.setProcessDefinition(newDef);
|
| logger.debug("process id " + pi.getId() + " changed to
version " + pi.getProcessDefinition().getVersion());
|
and
| private void changeTokenVersion(JbpmContext jbpmContext, Token token, int
newVersion) {
| Node oldNode = token.getNode();
|
| ProcessDefinition oldDef = token.getProcessInstance().getProcessDefinition();
|
| ProcessDefinition newDef =
jbpmContext.getGraphSession().findProcessDefinition(oldDef.getName(), newVersion);
| Node newNode = newDef.findNode(oldNode.getName());
|
| if (newNode == null) {
| throw new ConfigurationException("node with name '" +
oldNode.getName() + "' not found in new process definition");
| }
|
| logger.debug("change token id " + token.getId() + " from
version " + oldDef.getVersion() + " to new version " +
newDef.getVersion());
|
| token.setNode(newNode);
|
| // change tasks
| Iterator<TaskInstance> iter = getTasksForToken(token).iterator();
| while (iter.hasNext()) {
| TaskInstance ti = iter.next();
|
| Task oldTask = ti.getTask();
| // find new task
| Query q =
jbpmContext.getSession().createQuery(HibernateQueries.findTaskForNode);
| q.setString("taskName", oldTask.getName());
| q.setLong("taskNodeId", newNode.getId());
| // TODO: q.setLong("processDefinitionId", newDef.getId());
| Task newTask = (Task) q.uniqueResult();
|
| if (newTask == null) {
| throw new ConfigurationException("node '" +
newNode.getName() + "' has no Task configured! Check the new process
definition");
| }
|
| ti.setTask(newTask);
| logger.debug("change dependent task-instance with id " +
oldTask.getId());
| }
|
| // change childs recursive
| Iterator childIter = token.getChildren().values().iterator();
| while (childIter.hasNext()) {
| changeTokenVersion(jbpmContext, (Token) childIter.next(), newVersion);
| }
| }
|
If you can wait for a little bit of time it will go into the jbpm core I think, if you
need it now just enhance that code...
Hope that helps?
Bernd
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3981528#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...