4 Replies Latest reply on Nov 8, 2012 7:18 AM by Hari Krishna

    problem with using constranits of split node

    hong lu Newbie

      Hi,  I am newbie to jBPM and I am using JBPM5.2.

       

      I want to program a split process and get exception messages:

       

      Exception in thread "main" java.lang.IllegalArgumentException: XOR split could not find at least one valid outgoing connection for split null

      at org.jbpm.workflow.instance.node.SplitInstance.internalTrigger(SplitInstance.java:98)

      at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

      at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerConnection(NodeInstanceImpl.java:185)

      at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerCompleted(NodeInstanceImpl.java:150)

      at org.jbpm.workflow.instance.node.StartNodeInstance.triggerCompleted(StartNodeInstance.java:49)

      at org.jbpm.workflow.instance.node.StartNodeInstance.internalTrigger(StartNodeInstance.java:41)

      at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:122)

      at org.jbpm.ruleflow.instance.RuleFlowProcessInstance.internalStart(RuleFlowProcessInstance.java:35)

      at org.jbpm.process.instance.impl.ProcessInstanceImpl.start(ProcessInstanceImpl.java:188)

      at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.start(WorkflowProcessInstanceImpl.java:303)

      at org.jbpm.process.instance.ProcessRuntimeImpl.startProcessInstance(ProcessRuntimeImpl.java:168)

      at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:138)

      at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:130)

      at org.drools.common.AbstractWorkingMemory.startProcess(AbstractWorkingMemory.java:1074)

      at org.drools.impl.StatefulKnowledgeSessionImpl.startProcess(StatefulKnowledgeSessionImpl.java:301)

      at com.infy.workflow.MainTest.main(MainTest.java:111)

       

      forgive me for my bad english.

       

      Thanks very much.

       

      the source as below:

       

      public class MainTest {
      public static void main(String[] args) {
        RuleFlowProcess process = new RuleFlowProcess();
        process.setId("com.infy.login");
        process.setName("login process");

        List<Variable> variables = new ArrayList<Variable>();
        Variable variable = new Variable();
        variable.setName("isLogin");
        BooleanDataType isLogin = new BooleanDataType();
        isLogin.writeValue(true);
        variable.setType(isLogin);
        variables.add(variable);
        process.getVariableScope().setVariables(variables);

        StartNode startNode = new StartNode();
        startNode.setName("Start");
        startNode.setId(1);
        process.addNode(startNode);

        Split splitNode = new Split(Split.TYPE_XOR);
        splitNode.setId(2);
        process.addNode(splitNode);
        new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, splitNode, Node.CONNECTION_DEFAULT_TYPE);

        ActionNode actionNode = new ActionNode();
        actionNode.setName("validUser");
        DroolsAction action = new DroolsConsequenceAction("java", null);
        action.setMetaData("Action", new Action() {
         public void execute(ProcessContext context) throws Exception {
          System.out.println("The user is an valid user.");
         }
        });
        actionNode.setAction(action);
        actionNode.setId(3);
        process.addNode(actionNode);
        Connection validFlow = new ConnectionImpl(splitNode, Node.CONNECTION_DEFAULT_TYPE, actionNode,
          Node.CONNECTION_DEFAULT_TYPE);
        Constraint validConstraint = new RuleConstraintEvaluator();
        validConstraint.setDialect("java");
        validConstraint.setType("code");
        validConstraint.setConstraint("return false;");
        splitNode.setConstraint(validFlow, validConstraint);

        ActionNode actionNode2 = new ActionNode();
        actionNode2.setName("validUser");
        DroolsAction action2 = new DroolsConsequenceAction("java", null);
        action2.setMetaData("Action", new Action() {
         public void execute(ProcessContext context) throws Exception {
          System.out.println("The user is an invalid user.");
         }
        });
        actionNode2.setAction(action2);
        actionNode2.setId(4);
        process.addNode(actionNode2);
        Connection invalidFlow = new ConnectionImpl(splitNode, Node.CONNECTION_DEFAULT_TYPE, actionNode2,
          Node.CONNECTION_DEFAULT_TYPE);
        Constraint invalidConstraint = new RuleConstraintEvaluator();
        invalidConstraint.setDialect("java");
        invalidConstraint.setType("code");
        invalidConstraint.setConstraint("return true;");
        splitNode.setConstraint(invalidFlow, invalidConstraint);

        EndNode endNode = new EndNode();
        endNode.setName("EndNode");
        endNode.setId(5);
        process.addNode(endNode);
        new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);

        EndNode endNode2 = new EndNode();
        endNode2.setName("EndNode2");
        endNode2.setId(6);
        process.addNode(endNode2);
        new ConnectionImpl(actionNode2, Node.CONNECTION_DEFAULT_TYPE, endNode2, Node.CONNECTION_DEFAULT_TYPE);

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        AbstractRuleBase ruleBase = (AbstractRuleBase) ((InternalKnowledgeBase) kbase).getRuleBase();
        ruleBase.addProcess(process);
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

        ProcessInstance processInstance = ksession.startProcess("com.infy.login");
      }
      }