cancel
Showing results for 
Search instead for 
Did you mean: 

what's problem with my code

yz_ellen
Champ in-the-making
Champ in-the-making
the code is wrong ,how I can solve , this my code  intend to jump to any node(usertask).    


  ProcessDefinitionEntity def = (ProcessDefinitionEntity)        ((RepositoryServiceImpl)repositoryService).getDeployedProcessDefinition("mutitask:17:5704");
      ActivityImpl source = null;
      ActivityImpl destination = null;
      
   
       Execution execution = (Execution) runtimeService.createExecutionQuery()
          .executionId("6501")
          .singleResult();
      
      String activitiId = ((ExecutionEntity) execution).getActivityId();
        ScopeImpl scopeImpl=def;
            ActivityImpl  des=null;
       ActivityImpl  source=null;
       source= scopeImpl.findActivity("usertask2");
       des=scopeImpl.findActivity("usertask1");
      
      Map<String, Object> vals = new HashMap<String, Object>();
      vals.put("isInvolve", true);
      
      TransitionImpl transition = new TransitionImpl("mytransition", def);
      //TransitionImpl transition=source.createOutgoingTransition();
      
      // transition.setProperties(vals);
      transition.setSource(source);
      transition.setDestination(destination);
      
      System.out.println(transition);
      System.out.println(source.getOutgoingTransitions());
      
      ExecutionEntity execution2 = (ExecutionEntity) runtimeService.createExecutionQuery().executionId("6501").singleResult();
      
      // taskService.complete("10", vals);
      try {
         execution2.take(transition);
         
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
             
        
             error message :
java.lang.NullPointerException
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:481)
   at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:326)
   at com.zfsoft.workflow.test.activiti.TestRuntimeService.testTranaction(TestRuntimeService.java:200)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
   at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
   at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
   at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
   at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
   at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
   at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
   at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
   at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
   at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
   at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
   at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
   at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
   at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
   at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
   at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
   at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
   at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)



  thank you
7 REPLIES 7

yz_ellen
Champ in-the-making
Champ in-the-making
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="mutitask" name="mutitask">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="usertask1" activiti:assignee="smith">
   
    </userTask>
    <userTask id="usertask2" name="usertask2" activiti:assignee="smith"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow5" name="" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
    <userTask id="usertask3" name="User Task" activiti:assignee="smith"></userTask>
    <sequenceFlow id="flow12" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
    <sequenceFlow id="flow13" name="" sourceRef="usertask1" targetRef="usertask3"></sequenceFlow>
    <sequenceFlow id="flow14" name="" sourceRef="usertask3" targetRef="usertask2"></sequenceFlow>
    <sequenceFlow id="flow16" name="" sourceRef="usertask3" targetRef="usertask1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_mutitask">
    <bpmndi:BPMNPlane bpmnElement="mutitask" id="BPMNPlane_mutitask">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35" width="35" x="30" y="40"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
        <omgdc:Bounds height="55" width="105" x="90" y="180"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
        <omgdc:Bounds height="55" width="105" x="560" y="210"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35" width="35" x="480" y="6"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
        <omgdc:Bounds height="55" width="105" x="350" y="270"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="665" y="237"></omgdi:waypoint>
        <omgdi:waypoint x="480" y="23"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
        <omgdi:waypoint x="65" y="57"></omgdi:waypoint>
        <omgdi:waypoint x="90" y="207"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
        <omgdi:waypoint x="195" y="207"></omgdi:waypoint>
        <omgdi:waypoint x="350" y="297"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
        <omgdi:waypoint x="455" y="297"></omgdi:waypoint>
        <omgdi:waypoint x="560" y="237"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
        <omgdi:waypoint x="455" y="297"></omgdi:waypoint>
        <omgdi:waypoint x="90" y="207"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

chrishe
Champ in-the-making
Champ in-the-making
OK, I already have a discuss with the author. Here is the requirement:
There is a process, for example, has five user tasks, and for some kind reason, the process need to rollback, like the current active element is the third user task, and it need back to the first one. I know that kind of process is dirty, but this kind of suck requirement is really exist in the real life.
So the author try to develop such kind of function, which can jump from one user task to another randomly. It's seems really hard and not so elegant in the workflow.
Do you guys meet this kind of situation? If so, how to do that?

fred1
Champ in-the-making
Champ in-the-making
the code is wrong ,how I can solve , this my code  intend to jump to any node(usertask).

I don't know about the code but you can jump to a usertask by simply writing it directly into the database (with JDBC).
If you already have an execution just change the ACT_ID_ in ACT_RU_EXECUTION and update the task in ACT_RU_TASK and ACT_RU_IDENTITYLINK.

I would be interested if you get your code working though, because I want to jump to nodes that are not usertasks (script or servicetasks). My approach doesn't work for that and yours might be right.

chrishe
Champ in-the-making
Champ in-the-making
I'm a little worried about the solution of updating records in db directly will cause some unknow issue….
These days we are working on the way of jumping from one node to another, and the idea is create a new Transition from the source node to the target node, then use the take method in ActivityExecution, but get some problem, you can find the problem I post http://forums.activiti.org/en/viewtopic.php?f=4&t=2023

fred1
Champ in-the-making
Champ in-the-making
I agree that my solution may create unforeseen problems but if I understand the reply from the other thread correctly, to create Transitions you would need to make changes to the engine and create possibly hazardous sideeffects as well. And I don't think the developers are implementing this soon, though a manual change in a running workflow would certainly be useful in many cases.

If you want to try my approach, I forgot to mention that ACT_HI_ACTINST may need updating, too.

The alternative is making your bpmn-processmodel flexible enough (eg. with error-handling or gateways and flow that allow jumping to any node).

chrishe
Champ in-the-making
Champ in-the-making
To be honest, I'm a little upset these days, since the function of jump one node to another is the fundation function in our application. But I have no idea how to implement it. At the same time, the JBPM4 has run perfect under my thoughts.

After some strugglling, we try to turn to use JBPM4, which is more mature. I know the word 'mature' may invoke the disaggrement by the Activiti fans. Yes, the Activiti is base on the JBPM4. I means, these are lots of applications based on the JBPM4, and also there are many references we can get. For the activiti, I just find there are many guys get passion, but we don't have a mature user group.

So for the real project, I have to wait, and rollback to the JBPM4. I don't know other guy's idea, pls leave your thougt, not just pass away. We love Activiti, your thought will helpful to the team.

rs-activiti
Champ in-the-making
Champ in-the-making
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));
}
}