Hi!
The correct move between nodes can be achieved by implementing the following code:
I created a JumpCommand implements Command<Object>, Serializable {…}
and ActivitiRuntimeServiceExtendImpl extends RuntimeServiceImpl {}
where I added a method:
public boolean jump(String executionId, String target, Map<String, Object> variables) {
return (Boolean) commandExecutor.execute(new JumpCommand(executionId, target, variables));
}
and it works!
public class JumpCommand implements Command<Object>, Serializable {
private static final long serialVersionUID = 1L;
protected String executionId;
protected String targetActivitiId;
private Map<String, Object> variables;
public JumpCommand(String executionId, String targetActivitiId, Map<String, Object> variables) {
this.executionId = executionId;
this.targetActivitiId = targetActivitiId;
this.variables = variables;
}
public Object execute(CommandContext commandContext) {
if (executionId == null) {
throw new ActivitiException("executionId is null");
}
if (targetActivitiId == null) {
throw new ActivitiException("targetActivitiId is null!");
}
ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(executionId);
if (execution == null) {
HistoricProcessInstance hai = Context.getProcessEngineConfiguration().getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(executionId).singleResult();
if (hai!=null)
throw new ActivitiException("execution " + executionId + " has been completed at " + hai.getEndTime());
else {
throw new ActivitiException("execution " + executionId + " doesn't exist");
}
}
if (variables!=null && !variables.isEmpty()){
execution.setVariables(variables);
}
String processDefinitionId = execution.getProcessDefinitionId();
RepositoryServiceImpl rsi = (RepositoryServiceImpl) Context.getProcessEngineConfiguration().getRepositoryService();
ProcessDefinitionEntity pde = (ProcessDefinitionEntity) rsi.getDeployedProcessDefinition(processDefinitionId);
ActivityImpl targetActiviti = pde.findActivity(targetActivitiId);
if (targetActiviti == null){
throw new ActivitiException("targetActiviti " + targetActiviti + " doesn't exist");
}
try {
execution.take(targetActiviti.getIncomingTransitions().iterator().next());
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}
}
}
public class ActivitiRuntimeServiceExtendImpl extends RuntimeServiceImpl {
public boolean jump(String executionId, String target, Map<String, Object> variables) {
return (Boolean) commandExecutor.execute(new JumpCommand(executionId, target, variables));
}
}