Hi.

cancel ProcessInstances and start complete new processes is often impossible 
(because of triggering external systems, sending mails t ocustomers, ...) so we 
have the solution, that we can change one processInstance to a new version if 
the new version has 
- the same states with the same names for active tokens
- the same tasks with the same names for active tasks

This code is embeded in our toolkit for jbpm (which will be open source, we 
plan to release it at the end of january), here it is:


  |         public void changeProcessVersion(long processId, int newVersion) {
  |         checkSession();
  | 
  |         ProcessInstance pi = 
jbpmSession.getGraphSession().loadProcessInstance(processId);
  |         ProcessDefinition oldDef = pi.getProcessDefinition();
  |         Node oldNode = pi.getRootToken().getNode();
  | 
  |         ProcessDefinition newDef = 
jbpmSession.getGraphSession().findProcessDefinition(oldDef.getName(), 
newVersion);
  |         Node newNode = newDef.findNode(oldNode.getName());
  | 
  |         pi.getRootToken().setNode(newNode);
  | 
  |         // do: pi.setProcessDefinition(newDef);
  |         try {
  |             Class clazz = ProcessInstance.class;
  |             Field field = clazz.getDeclaredField("processDefinition");
  |             field.setAccessible(true);
  |             field.set(pi, newDef);
  |             field.setAccessible(false);
  |         }
  |         catch (Exception ex) {
  |             throw new ConfigurationException("can not set processDefinition 
on processInstance with reflection. check nested exception for details.", ex);
  |         }
  | 
  |         Iterator<TaskInstance> iter =  
getTasksForProcesInstance(jbpmSession, pi).iterator();
  |         while (iter.hasNext()) {
  |             TaskInstance ti = iter.next();
  | 
  |             Task oldTask = ti.getTask();
  |             // find new task
  |             Query q = jbpmSession.getSession().createQuery( 
HibernateQueries.findTaskForNode );
  |             q.setString("taskName", oldTask.getName());
  |             q.setLong("taskNodeId", newNode.getId());
  |             Task newTask = (Task) q.uniqueResult();
  | 
  |             ti.setTask(newTask);
  |         }
  | 

We have no problems with that code, if the preconditions are met.

Note, that you can not make complexe changes to processes and migrate old 
versions to the new ones. But it is helpful if you must deploy a bug fix of a 
process (or a Java class, included in the procsess).

Hope that helps, feedback is welcome :-)

Bernd
camunda GmbH

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3916438#3916438

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3916438


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
JBoss-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to