[jboss-user] [jBPM] - Manual reroute in Jbpm 4.3

Martin Pradny do-not-reply at jboss.com
Fri Jun 11 12:42:36 EDT 2010


Martin Pradny [http://community.jboss.org/people/mpradny] replied to the discussion

"Manual reroute in Jbpm 4.3"

To view the discussion, visit: http://community.jboss.org/message/547600#547600

--------------------------------------------------------------
THANK YOU  :)  This works.

In case anyone is looking for something similar, here si the code.

import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.cmd.Environment;
import org.jbpm.api.model.Event;
import org.jbpm.pvm.internal.client.ClientExecution;
import org.jbpm.pvm.internal.cmd.AbstractCommand;
import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.model.TransitionImpl;
import org.jbpm.pvm.internal.model.op.AtomicOperation;
import org.jbpm.pvm.internal.processengine.ProcessEngineImpl;
import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.task.TaskImpl;

public class RerouteCmd extends AbstractCommand<ProcessInstance> {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private static final String REROUTE = "#reroute#";
    private String executionId;
    private String newActivityName;
    private String taskId;
    
    public RerouteCmd(String executionId, String newActivityName, String taskId){
         this.executionId=executionId;
         this.newActivityName=newActivityName;
         this.taskId=taskId;
    }
    
    @Override
    public ProcessInstance execute(Environment environment) throws Exception {
        ExecutionImpl execution = null;
        
        DbSession dbSession = environment.get(DbSession.class);
        execution = (ExecutionImpl) dbSession.findExecutionById(executionId);

           ProcessDefinitionImpl pd=execution.getProcessDefinition();
           
        ActivityImpl endActivity=pd.getActivity(newActivityName);
        ActivityImpl startActivity=execution.getActivity();
        TransitionImpl trans=startActivity.createOutgoingTransition();
        trans.setDestination(endActivity);
        trans.setName(REROUTE);
        
        if (taskId==null){
            execution.signal(REROUTE);
        }else{
            TaskImpl task=dbSession.get(TaskImpl.class, Long.parseLong(taskId));
            if (task!=null){
                task.complete(REROUTE);
                dbSession.delete(task);
            }
        }
        startActivity.removeOutgoingTransition(trans);
        
        return null;
    }

}


I have tried to casue minimal damage to existing logic. May be the signal and complete operations could be done again using commands, but I wasn't able to get processEngine (and didn't bother too much, since this works).

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/547600#547600]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100611/fd601b2f/attachment.html 


More information about the jboss-user mailing list