AnsweredAssumed Answered

How to execute my command in application ?

Question asked by ggdeveloper on Sep 6, 2011
Latest reply on Sep 8, 2011 by sky1
I have write an WithdrawCommand implements Command<Void>,but what should i do to call it in applicaiton.
We know in jbpm we can use ProcessEngine .execute() to call ,but in activiti we should use which api?

my WithdrawCommand code:

public class WithdrawCommand implements Command<Void> {
   
   private String mstrPid;
   private String mstrWithdrawName;
   private String mstrExecutionId;
   private String mstrActiveTaskId;
   
   @Resource(name = "processEngine")
   private ProcessEngine mobjProcessEngine;
   
   @Resource(name = "runtimeService")
   private RuntimeService mobjRuntimeService;
   
   @Resource(name = "repositoryService")
   private RepositoryService mobjRepositoryService;
   
   @Resource(name = "taskService")
   private TaskService mobjTaskService;
   
   @Resource(name = "historyService")
   private HistoryService mobjHistoryService;
   
   public WithdrawCommand(String pstrPid, String pstrName,String pstrExecutionId,String pstrActiveTaskId) {
      this.mstrPid = pstrPid;
      this.mstrWithdrawName = pstrName;
      this.mstrExecutionId = pstrExecutionId;
      this.mstrActiveTaskId = pstrActiveTaskId;
      
   }
   
   @Override
   public Void execute(CommandContext commandContext) {
      ActivityImpl  activityImpl =commandContext.getExecutionManager().findExecutionById(mstrExecutionId).getActivity();
      TransitionImpl transition = (TransitionImpl)activityImpl.getOutgoingTransitions().get(0);
      ActivityImpl from = transition.getDestination();
      ActivityImpl to = transition.getSource();
      TransitionImpl withdraw = from.createOutgoingTransition();
      withdraw.setDestination(to);
      withdraw.setProperty("name", "withdraw");
      mobjTaskService.complete(mstrActiveTaskId);
      return null;
   }
   
   public void setMstrPid(String mstrPid) {
      this.mstrPid = mstrPid;
   }
   
   public void setMstrWithdrawName(String mstrWithdrawName) {
      this.mstrWithdrawName = mstrWithdrawName;
   }
   
   public void setMobjProcessEngine(ProcessEngine mobjProcessEngine) {
      this.mobjProcessEngine = mobjProcessEngine;
   }
   
   public void setMobjRuntimeService(RuntimeService mobjRuntimeService) {
      this.mobjRuntimeService = mobjRuntimeService;
   }
   
   public void
         setMobjRepositoryService(RepositoryService mobjRepositoryService) {
      this.mobjRepositoryService = mobjRepositoryService;
   }
   
   public void setMobjTaskService(TaskService mobjTaskService) {
      this.mobjTaskService = mobjTaskService;
   }
   
   public void setMobjHistoryService(HistoryService mobjHistoryService) {
      this.mobjHistoryService = mobjHistoryService;
   }
   
}

Outcomes