[jboss-user] [JBoss jBPM] - Re: How to Generate ad-hoc Task, activities & process ??
rogerofyan
do-not-reply at jboss.com
Wed Aug 12 09:34:55 EDT 2009
Sure, this is definitely ok for jBPM4.
faisalgeek, I suppose you means generating task, activities & process at run time, not only at the process definition(jpdl), don't u?
I use to have similar requirement, and I found few documents about the internal jBPM api. So I had to read the source code of jBPM4.
I can share my code of generating task & activity at runtime.
| import java.util.List;
|
| import org.jbpm.api.Execution;
| import org.jbpm.api.ExecutionService;
| import org.jbpm.api.TaskService;
| import org.jbpm.api.listener.EventListener;
| import org.jbpm.api.listener.EventListenerExecution;
| import org.jbpm.jpdl.internal.activity.TaskActivity;
| import org.jbpm.pvm.internal.env.Environment;
| import org.jbpm.pvm.internal.env.SpringContext;
| import org.jbpm.pvm.internal.history.HistoryEvent;
| import org.jbpm.pvm.internal.history.events.TaskActivityStart;
| import org.jbpm.pvm.internal.model.Activity;
| import org.jbpm.pvm.internal.model.ActivityImpl;
| import org.jbpm.pvm.internal.model.ExecutionImpl;
| import org.jbpm.pvm.internal.model.Transition;
| import org.jbpm.pvm.internal.model.TransitionImpl;
| import org.jbpm.pvm.internal.model.ExecutionImpl.Propagation;
| import org.jbpm.pvm.internal.session.DbSession;
| import org.jbpm.pvm.internal.task.TaskImpl;
| import org.jbpm.pvm.internal.util.Clock;
|
| /**
| * èªå¨为åÂÂÃ¥ÂÂå¦å¦é¢åÂÂ建ä¸Â个任å¡ï¼Â为å¦习ä¸Âå¿ÂÃ¥ÂÂ建两个任å¡ãÂÂ
| *
| * @author <a href="mailto:rogerofyan at gmail.com">Roger Yan</a>
| *
| */
| public class ApplicationListener implements EventListener {
| // private GroupManager groupManager;
| @Override
| public void notify(EventListenerExecution execution) throws Exception {
| ExecutionImpl exe = (ExecutionImpl) execution;
| ActivityImpl fork = exe.getActivity();
| //creating two tasks and associated activities
| placeViceMentorTask(exe, "center1");
| placeViceMentorTask(exe, "center2");
| }
|
| private void placeViceMentorTask(ExecutionImpl execution, String assignee) {
| Environment env = Environment.getCurrent();
| TaskService taskService = env.get(TaskService.class);
| DbSession dbSession = env.get(DbSession.class);
|
| // è·åÂÂå½ÂÃ¥ÂÂæ§è¡ÂçÂÂç»Âç¹ç¸åÂ
³ä¿¡æ¯
| ActivityImpl fork = execution.getActivity();
| List<Transition> trans = fork.getOutgoingTransitions();
| TransitionImpl transition = (TransitionImpl) trans.get(0);
| ActivityImpl join = (ActivityImpl) transition.getDestination().getOutgoingTransitions().get(0)
| .getDestination();
|
| // 1. creating an activity
| ActivityImpl newActivity = fork.getProcessDefinition().createActivity("æÂÂ交å¯导å¸Âä¿¡æ¯1");
| TaskActivity ta = new TaskActivity();
| newActivity.setBehaviour(ta);
|
| // 2.creating an outgoing transition
| TransitionImpl outgoing = newActivity.createOutgoingTransition();
| // outgoing.setDestination((ActivityImpl) join);
| outgoing.setName("è³æÂÂå¦æÂÂå¡ä¸Âå¿Â审核");
| join.addIncomingTransition(outgoing);
|
| // 3.creating an execution
| ExecutionImpl newExec = execution.createExecution();
| newExec.setActivity(newActivity);
| newExec.setState(Execution.STATE_ACTIVE_CONCURRENT);
| newExec.setName("viceMentorExecution");
| newExec.setTransition(outgoing);
| newExec.setPropagation(Propagation.UNSPECIFIED);
| newExec.setHistoryActivityStart(Clock.getCurrentTime());
| dbSession.save(newExec);
|
| TaskImpl task = (TaskImpl) taskService.newTask();
| task.setAssignee(assignee);
| task.setName("æÂÂ交å¯导å¸ÂèµÂæÂÂ1");
| task.setExecution(newExec);
| task.setSignalling(true);
| taskService.saveTask(task);
|
| HistoryEvent.fire(new TaskActivityStart(task), newExec);
| newExec.waitForSignal();
| }
| }
|
The code looks ugly, but it just works for me.
Take it as a reference.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4249222#4249222
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4249222
More information about the jboss-user
mailing list