Package org.drools.ruleflow.core

Examples of org.drools.ruleflow.core.Split


        ruleSet1.setRuleFlowGroup( "rule-flow-group-1" );
        final RuleSetNode ruleSet2 = new RuleSetNodeImpl();
        ruleSet2.setRuleFlowGroup( "rule-flow-group-2" );
        final RuleSetNode ruleSet3 = new RuleSetNodeImpl();
        ruleSet3.setRuleFlowGroup( "rule-flow-group-3" );
        final Split split = new SplitImpl();
        split.setType( Split.TYPE_AND );
        final Join join = new JoinImpl();
        join.setType( Join.TYPE_AND );
        final EndNode end = new EndNodeImpl();
        // connections
        new ConnectionImpl( start,
View Full Code Here


        ruleSet1.setRuleFlowGroup( "rule-flow-group-1" );
        final RuleSetNode ruleSet2 = new RuleSetNodeImpl();
        ruleSet2.setRuleFlowGroup( "rule-flow-group-2" );
        final RuleSetNode ruleSet3 = new RuleSetNodeImpl();
        ruleSet3.setRuleFlowGroup( "rule-flow-group-3" );
        final Split split = new SplitImpl();
        split.setType( Split.TYPE_XOR );
        final Join join = new JoinImpl();
        join.setType( Join.TYPE_XOR );
        final EndNode end = new EndNodeImpl();
        // connections
        new ConnectionImpl( start,
                        ruleSet0,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet0,
                        split,
                        Connection.TYPE_NORMAL );
        Connection out1 = new ConnectionImpl( split,
                        ruleSet1,
                        Connection.TYPE_NORMAL );
        Connection out2 = new ConnectionImpl( split,
                        ruleSet2,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet1,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet2,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( join,
                        ruleSet3,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet3,
                        end,
                        Connection.TYPE_NORMAL );
        Constraint constraint1 = new org.drools.ruleflow.core.impl.ConstraintImpl();
        constraint1.setPriority(1);
        split.setConstraint(out1, constraint1);
        Constraint constraint2 = new org.drools.ruleflow.core.impl.ConstraintImpl();
        constraint2.setPriority(2);
        split.setConstraint(out2, constraint2);

        // process
        final RuleFlowProcess process = new RuleFlowProcessImpl();
        process.setId( "1" );
        process.addNode( start );
        process.addNode( ruleSet0 );
        process.addNode( ruleSet1 );
        process.addNode( ruleSet2 );
        process.addNode( ruleSet3 );
        process.addNode( split );
        process.addNode( join );
        process.addNode( end );

        // rules for split
        final Rule splitRule1 = new Rule( "RuleFlow-1-" + split.getId() + "-" + ruleSet1.getId());
        splitRule1.setRuleFlowGroup( "DROOLS_SYSTEM" );
        splitRule1.setConsequence( consequence );

        final RuleTerminalNode splitNode1 = new RuleTerminalNode( 7,
                                                                 new MockTupleSource( 2 ),
                                                                 splitRule1,
                                                                 splitRule1.getLhs() );

        final Rule splitRule2 = new Rule( "RuleFlow-1-" + split.getId() + "-" + ruleSet2.getId());
        splitRule2.setRuleFlowGroup( "DROOLS_SYSTEM" );
        splitRule2.setConsequence( consequence );

        final RuleTerminalNode splitNode2 = new RuleTerminalNode( 8,
                                                                 new MockTupleSource( 2 ),
View Full Code Here

                final String ruleFlowGroup = ruleSetNode.getRuleFlowGroup();
                if ( ruleFlowGroup == null || "".equals( ruleFlowGroup ) ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.RULE_SET_NODE_WITHOUT_RULE_SET_GROUP, "name = " + ruleSetNode.getName() ) );
                }
            } else if ( node instanceof Split ) {
                final Split split = (Split) node;
                if ( split.getType() == Split.TYPE_UNDEFINED ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_WITHOUT_TYPE, "name = " + split.getName() ) );
                }
                if ( split.getFrom() == null ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_WITHOUT_INCOMING_CONNECTION, "name = " + split.getName() ) );
                }
                if ( split.getOutgoingConnections().size() < 2 ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_NOT_ENOUGH_OUTGOING_CONNECTIONS, "name = " + split.getName() ) );
                }
                if ( split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR ) {
                    for ( final Iterator it = split.getOutgoingConnections().iterator(); it.hasNext(); ) {
                        final Connection connection = (Connection) it.next();
                        if ( split.getConstraint( connection ) == null ) {
                            errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_OUTGOING_CONNECTION_WITHOUT_CONSTRAINT, "name = " + split.getName() ) );
                        }
                    }
                }
            } else if ( node instanceof Join ) {
                final Join join = (Join) node;
View Full Code Here

    protected Split getSplitNode() {
        return (Split) getNode();
    }

    public void trigger(final RuleFlowNodeInstance from) {
        final Split split = getSplitNode();
        switch ( split.getType() ) {
            case Split.TYPE_AND :
                List outgoing = split.getOutgoingConnections();
                for ( final Iterator iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    getProcessInstance().getNodeInstance( connection.getTo() ).trigger( this );
                }
                break;
            case Split.TYPE_XOR :
                outgoing = split.getOutgoingConnections();
                int priority = Integer.MAX_VALUE;
                Connection selected = null;
              RuleFlowGroup systemRuleFlowGroup = getProcessInstance().getAgenda().getRuleFlowGroup("DROOLS_SYSTEM");
                for ( final Iterator iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    Constraint constraint = split.getConstraint(connection);
                    if (constraint != null && constraint.getPriority() < priority) {
                      String rule = "RuleFlow-Split-" + getProcessInstance().getProcess().getId() + "-" +
                    getNode().getId() + "-" + connection.getTo().getId();
                      for (Iterator activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
                        Activation activation = ((RuleFlowGroupNode) activations.next()).getActivation();
                        if (rule.equals(activation.getRule().getName())) {
                            selected = connection;
                            priority = constraint.getPriority();
                            break;
                        }
                      }
                    }
                }
                if (selected == null) {
                  throw new IllegalArgumentException("XOR split could not find at least one valid outgoing connection for split " + getSplitNode().getName());
                }
                getProcessInstance().getNodeInstance( selected.getTo() ).trigger( this );
                break;
            case Split.TYPE_OR :
                outgoing = split.getOutgoingConnections();
                boolean found = false;
              systemRuleFlowGroup = getProcessInstance().getAgenda().getRuleFlowGroup("DROOLS_SYSTEM");
                for ( final Iterator iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    Constraint constraint = split.getConstraint(connection);
                    if (constraint != null) {
                      String rule = "RuleFlow-Split-" + getProcessInstance().getProcess().getId() + "-" +
                        getNode().getId() + "-" + connection.getTo().getId();
                      for (Iterator activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
                        Activation activation = ((RuleFlowGroupNode) activations.next()).getActivation();
                        if (rule.equals(activation.getRule().getName())) {
                                getProcessInstance().getNodeInstance( connection.getTo() ).trigger( this );
                                found = true;
                            break;
                        }
                      }
                    }
                    if (!found) {
                      throw new IllegalArgumentException("OR split could not find at least one valid outgoing connection for split " + getSplitNode().getName());
                    }
                }
                break;
            default :
                throw new IllegalArgumentException( "Illegal split type " + split.getType() );
        }
    }
View Full Code Here

          }
        }
        Node[] nodes = ruleFlow.getNodes();
        for (int i = 0; i < nodes.length; i++) {
           if (nodes[i] instanceof Split) {
             Split split = (Split) nodes[i];
             if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
               for (Iterator iterator = split.getOutgoingConnections().iterator(); iterator.hasNext(); ) {
                 Connection connection = (Connection) iterator.next();
                 result += createSplitRule(process, connection, split.getConstraint(connection).getConstraint());
               }
             }
           } else if (nodes[i] instanceof MilestoneNode) {
             MilestoneNode milestone = (MilestoneNode) nodes[i];
             result += createMilestoneRule(process, milestone);
View Full Code Here

        }

        Node[] nodes = ruleFlow.getNodes();
        for (int i = 0; i < nodes.length; i++) {
           if (nodes[i] instanceof Split) {
             Split split = (Split) nodes[i];
             if (split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR) {
               for (Iterator iterator = split.getOutgoingConnections().iterator(); iterator.hasNext(); ) {
                 Connection connection = (Connection) iterator.next();
                 result += createSplitRule(process, connection, split.getConstraint(connection).getConstraint());
               }
             }
           } else if (nodes[i] instanceof MilestoneNode) {
             MilestoneNode milestone = (MilestoneNode) nodes[i];
             result += createMilestoneRule(process, milestone);
View Full Code Here

        ruleSet1.setRuleFlowGroup( "rule-flow-group-1" );
        final RuleSetNode ruleSet2 = new RuleSetNodeImpl();
        ruleSet2.setRuleFlowGroup( "rule-flow-group-2" );
        final RuleSetNode ruleSet3 = new RuleSetNodeImpl();
        ruleSet3.setRuleFlowGroup( "rule-flow-group-3" );
        final Split split = new SplitImpl();
        split.setType( Split.TYPE_AND );
        final Join join = new JoinImpl();
        join.setType( Join.TYPE_AND );
        final EndNode end = new EndNodeImpl();
        // connections
        new ConnectionImpl( start,
View Full Code Here

        ruleSet1.setRuleFlowGroup( "rule-flow-group-1" );
        final RuleSetNode ruleSet2 = new RuleSetNodeImpl();
        ruleSet2.setRuleFlowGroup( "rule-flow-group-2" );
        final RuleSetNode ruleSet3 = new RuleSetNodeImpl();
        ruleSet3.setRuleFlowGroup( "rule-flow-group-3" );
        final Split split = new SplitImpl();
        split.setType( Split.TYPE_XOR );
        final Join join = new JoinImpl();
        join.setType( Join.TYPE_XOR );
        final EndNode end = new EndNodeImpl();
        // connections
        new ConnectionImpl( start,
                        ruleSet0,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet0,
                        split,
                        Connection.TYPE_NORMAL );
        Connection out1 = new ConnectionImpl( split,
                        ruleSet1,
                        Connection.TYPE_NORMAL );
        Connection out2 = new ConnectionImpl( split,
                        ruleSet2,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet1,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet2,
                        join,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( join,
                        ruleSet3,
                        Connection.TYPE_NORMAL );
        new ConnectionImpl( ruleSet3,
                        end,
                        Connection.TYPE_NORMAL );
        Constraint constraint1 = new org.drools.ruleflow.core.impl.ConstraintImpl();
        constraint1.setPriority(1);
        split.setConstraint(out1, constraint1);
        Constraint constraint2 = new org.drools.ruleflow.core.impl.ConstraintImpl();
        constraint2.setPriority(2);
        split.setConstraint(out2, constraint2);

        // process
        final RuleFlowProcess process = new RuleFlowProcessImpl();
        process.setId( "1" );
        process.addNode( start );
        process.addNode( ruleSet0 );
        process.addNode( ruleSet1 );
        process.addNode( ruleSet2 );
        process.addNode( ruleSet3 );
        process.addNode( split );
        process.addNode( join );
        process.addNode( end );

        // rules for split
        final Rule splitRule1 = new Rule( "RuleFlow-Split-1-" + split.getId() + "-" + ruleSet1.getId());
        splitRule1.setRuleFlowGroup( "DROOLS_SYSTEM" );
        splitRule1.setConsequence( consequence );

        final RuleTerminalNode splitNode1 = new RuleTerminalNode( 7,
                                                                 new MockTupleSource( 2 ),
                                                                 splitRule1,
                                                                 splitRule1.getLhs(),
                                                                  buildContext );

        final Rule splitRule2 = new Rule( "RuleFlow-Split-1-" + split.getId() + "-" + ruleSet2.getId());
        splitRule2.setRuleFlowGroup( "DROOLS_SYSTEM" );
        splitRule2.setConsequence( consequence );

        final RuleTerminalNode splitNode2 = new RuleTerminalNode( 8,
                                                                 new MockTupleSource( 2 ),
View Full Code Here

    protected Split getSplitNode() {
        return (Split) getNode();
    }

    public void trigger(final RuleFlowNodeInstance from) {
        final Split split = getSplitNode();
        switch ( split.getType() ) {
            case Split.TYPE_AND :
                List outgoing = split.getOutgoingConnections();
                for ( final Iterator iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    getProcessInstance().getNodeInstance( connection.getTo() ).trigger( this );
                }
                break;
            case Split.TYPE_XOR :
                outgoing = split.getOutgoingConnections();
                int priority = Integer.MAX_VALUE;
                Connection selected = null;
              RuleFlowGroup systemRuleFlowGroup = getProcessInstance().getAgenda().getRuleFlowGroup("DROOLS_SYSTEM");
                for ( final Iterator iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    Constraint constraint = split.getConstraint(connection);
                    if (constraint != null && constraint.getPriority() < priority) {
                      String rule = "RuleFlow-" + getProcessInstance().getProcess().getId() + "-" +
                    getNode().getId() + "-" + connection.getTo().getId();
                      for (Iterator activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
                        Activation activation = ((RuleFlowGroupNode) activations.next()).getActivation();
                        if (rule.equals(activation.getRule().getName())) {
                            selected = connection;
                            priority = constraint.getPriority();
                            break;
                        }
                      }
                    }
                }
                if (selected == null) {
                  throw new IllegalArgumentException("XOR split could not find at least one valid outgoing connection for split " + getSplitNode().getName());
                }
                getProcessInstance().getNodeInstance( selected.getTo() ).trigger( this );
                break;
            case Split.TYPE_OR :
                outgoing = split.getOutgoingConnections();
                boolean found = false;
              systemRuleFlowGroup = getProcessInstance().getAgenda().getRuleFlowGroup("DROOLS_SYSTEM");
                for ( final Iterator iterator = outgoing.iterator(); iterator.hasNext(); ) {
                    final Connection connection = (Connection) iterator.next();
                    Constraint constraint = split.getConstraint(connection);
                    if (constraint != null) {
                      String rule = "RuleFlow-" + getProcessInstance().getProcess().getId() + "-" +
                        getNode().getId() + "-" + connection.getTo().getId();
                      for (Iterator activations = systemRuleFlowGroup.iterator(); activations.hasNext(); ) {
                        Activation activation = ((RuleFlowGroupNode) activations.next()).getActivation();
                        if (rule.equals(activation.getRule().getName())) {
                                getProcessInstance().getNodeInstance( connection.getTo() ).trigger( this );
                                found = true;
                            break;
                        }
                      }
                    }
                    if (!found) {
                      throw new IllegalArgumentException("OR split could not find at least one valid outgoing connection for split " + getSplitNode().getName());
                    }
                }
                break;
            default :
                throw new IllegalArgumentException( "Illegal split type " + split.getType() );
        }
    }
View Full Code Here

                final String ruleFlowGroup = ruleSetNode.getRuleFlowGroup();
                if ( ruleFlowGroup == null || "".equals( ruleFlowGroup ) ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.RULE_SET_NODE_WITHOUT_RULE_SET_GROUP ) );
                }
            } else if ( node instanceof Split ) {
                final Split split = (Split) node;
                if ( split.getType() == Split.TYPE_UNDEFINED ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_WITHOUT_TYPE ) );
                }
                if ( split.getFrom() == null ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_WITHOUT_INCOMING_CONNECTION ) );
                }
                if ( split.getOutgoingConnections().size() < 2 ) {
                    errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_NOT_ENOUGH_OUTGOING_CONNECTIONS ) );
                }
                if ( split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR ) {
                    for ( final Iterator it = split.getOutgoingConnections().iterator(); it.hasNext(); ) {
                        final Connection connection = (Connection) it.next();
                        if ( split.getConstraint( connection ) == null ) {
                            errors.add( new RuleFlowProcessValidationErrorImpl( RuleFlowProcessValidationError.SPLIT_OUTGOING_CONNECTION_WITHOUT_CONSTRAINT ) );
                        }
                    }
                }
            } else if ( node instanceof Join ) {
View Full Code Here

TOP

Related Classes of org.drools.ruleflow.core.Split

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.