Package org.drools.workbench.models.commons.shared.rule

Examples of org.drools.workbench.models.commons.shared.rule.ActionInsertFact


        /*
         * add the bound variable of the rhs
         */
        List<String> vars2 = model.getModel().getRHSBoundFacts();
        for ( String v : vars2 ) {
            ActionInsertFact factPattern = model.getModel().getRHSBoundFact( v );
            if ( factPattern.getFactType().equals( this.methodParameter.getType() ) ) {
                // First selection is empty
                if ( listVariable.getItemCount() == 0 ) {
                    listVariable.addItem( "..." );
                }
                listVariable.addItem( v );
View Full Code Here


                FactPattern factPattern = model.getModel().getLHSBoundFact( v );
                if ( factPattern.getFactType().equals( this.parameterType ) ) {
                    createButton = true;
                }
            } else {
                ActionInsertFact factPattern = model.getModel().getRHSBoundFact( v );
                if ( factPattern.getFactType().equals( this.parameterType ) ) {
                    createButton = true;
                }
            }
            if ( createButton == true ) {
                form.addAttribute( Constants.INSTANCE.BoundVariable() + ":",
View Full Code Here

        return clone;
    }

    //ActionInsertFact, ActionSetField, ActionpdateField
    private ActionInsertFact visitActionFieldList( ActionInsertFact afl ) {
        ActionInsertFact clone = new ActionInsertFact();
        clone.setFactType( afl.getFactType() );
        clone.setBoundName( afl.getBoundName() );
        for ( ActionFieldValue afv : afl.getFieldValues() ) {
            ActionFieldValue afvClone = new ActionFieldValue();
            afvClone.setField( afv.getField() );
            afvClone.setNature( afv.getNature() );
            afvClone.setType( afv.getType() );
            afvClone.setValue( afv.getValue() );
            clone.addFieldValue( afvClone );
        }
        return clone;
    }
View Full Code Here

                }
            } else if ( line.startsWith( "insert" ) ) {
                String fact = unwrapParenthesis( line );
                String type = getStatementType( fact, factsType );
                if ( type != null ) {
                    ActionInsertFact action = new ActionInsertFact( type );
                    m.addRhsItem( action );
                    if ( factsType.containsKey( fact ) ) {
                        action.setBoundName( fact );
                        addSettersToAction( setStatements, fact, action, isJavaDialect );
                    }
                }
            } else if ( line.startsWith( "update" ) ) {
                String variable = unwrapParenthesis( line );
                ActionUpdateField action = new ActionUpdateField();
                action.setVariable( variable );
                m.addRhsItem( action );
                addSettersToAction( setStatements, variable, action, isJavaDialect );
            } else if ( line.startsWith( "retract" ) ) {
                String variable = unwrapParenthesis( line );
                m.addRhsItem( new ActionRetractFact( variable ) );
View Full Code Here

        m.addLhsItem( new FactPattern( "Person" ) );
        m.addLhsItem( new FactPattern( "Accident" ) );
        m.addAttribute( new RuleAttribute( "no-loop",
                                           "true" ) );

        m.addRhsItem( new ActionInsertFact( "Report" ) );
        ActionGlobalCollectionAdd ag = new ActionGlobalCollectionAdd();
        ag.setFactName( "x" );
        ag.setGlobalName( "g" );
        m.addRhsItem( ag );
        m.name = "my rule";
View Full Code Here

        Z.setValue( "foo" );
        Z.setOperator( "==" );

        p.addConstraint( Z );

        ActionInsertFact ass = new ActionInsertFact( "Whee" );
        m.addRhsItem( ass );

        String xml = BRXMLPersistence.getInstance().marshal( m );
        //System.err.println(xml);
View Full Code Here

                }
            } else if ( line.startsWith( "insert" ) ) {
                String fact = unwrapParenthesis( line );
                String type = getStatementType( fact, factsType );
                if ( type != null ) {
                    ActionInsertFact action = new ActionInsertFact( type );
                    m.addRhsItem( action );
                    if ( factsType.containsKey( fact ) ) {
                        action.setBoundName( fact );
                        addSettersToAction( setStatements, fact, action, isJavaDialect );
                    }
                }
            } else if ( line.startsWith( "update" ) ) {
                String variable = unwrapParenthesis( line );
                ActionUpdateField action = new ActionUpdateField();
                action.setVariable( variable );
                m.addRhsItem( action );
                addSettersToAction( setStatements, variable, action, isJavaDialect );
            } else if ( line.startsWith( "retract" ) ) {
                String variable = unwrapParenthesis( line );
                m.addRhsItem( new ActionRetractFact( variable ) );
View Full Code Here

        ins.setFactType( "Person" );
        ins.setType( DataType.TYPE_STRING );
        dt.getActionCols().add( ins );

        BRLActionColumn brlAction = new BRLActionColumn();
        ActionInsertFact aif = new ActionInsertFact( "Person" );
        aif.setBoundName( "$aif" );
        aif.addFieldValue( new ActionFieldValue( "rating",
                                                 null,
                                                 DataType.TYPE_STRING ) );
        aif.getFieldValues()[ 0 ].setNature( BaseSingleFieldConstraint.TYPE_LITERAL );

        brlAction.getDefinition().add( aif );
        dt.getActionCols().add( brlAction );

        BRLRuleModel model = new BRLRuleModel( dt );

        assertNotNull( model.getAllVariables() );
        assertEquals( 4,
                      model.getAllVariables().size() );
        assertTrue( model.getAllVariables().contains( "$p1" ) );
        assertTrue( model.getAllVariables().contains( "$c1" ) );
        assertTrue( model.getAllVariables().contains( "$ins" ) );
        assertTrue( model.getAllVariables().contains( "$aif" ) );

        assertNotNull( model.getRHSBoundFacts() );
        assertEquals( 2,
                      model.getRHSBoundFacts().size() );
        assertTrue( model.getRHSBoundFacts().contains( "$ins" ) );
        assertTrue( model.getRHSBoundFacts().contains( "$aif" ) );

        ActionInsertFact r1 = model.getRHSBoundFact( "$ins" );
        assertNotNull( r1 );
        assertTrue( r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor);
        ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
        assertEquals( "Person",
                      raif1.getFactType() );
        assertEquals( "rating",
                      raif1.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif1.getFieldValues()[ 0 ].getType() );
        assertNull( raif1.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif1.getFieldValues()[ 0 ].getNature() );

        ActionInsertFact r2 = model.getRHSBoundFact( "$aif" );
        assertNotNull( r2 );
        assertTrue( r2 instanceof ActionInsertFact );
        ActionInsertFact raif2 = (ActionInsertFact) r2;
        assertEquals( "Person",
                      raif2.getFactType() );
        assertEquals( "rating",
                      raif2.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif2.getFieldValues()[ 0 ].getType() );
        assertNull( raif2.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif2.getFieldValues()[ 0 ].getNature() );

    }
View Full Code Here

        ins2.setFactType( "Person2" );
        ins2.setType( DataType.TYPE_STRING );
        dt.getActionCols().add( ins2 );

        BRLActionColumn brlAction = new BRLActionColumn();
        ActionInsertFact aif = new ActionInsertFact( "Person" );
        aif.setBoundName( "$aif" );
        aif.addFieldValue( new ActionFieldValue( "rating",
                                                 null,
                                                 DataType.TYPE_STRING ) );
        aif.getFieldValues()[ 0 ].setNature( BaseSingleFieldConstraint.TYPE_LITERAL );

        brlAction.getDefinition().add( aif );
        dt.getActionCols().add( brlAction );

        BRLRuleModel model = new BRLRuleModel( dt );

        assertNotNull( model.getRHSBoundFacts() );
        assertEquals( 3,
                      model.getRHSBoundFacts().size() );
        assertTrue( model.getRHSBoundFacts().contains( "$ins" ) );
        assertTrue( model.getRHSBoundFacts().contains( "$ins2" ) );
        assertTrue( model.getRHSBoundFacts().contains( "$aif" ) );

        ActionInsertFact r1 = model.getRHSBoundFact( "$ins" );
        assertNotNull( r1 );
        assertTrue( r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor );
        ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
        assertEquals( "Person",
                      raif1.getFactType() );
        assertEquals( "rating",
                      raif1.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif1.getFieldValues()[ 0 ].getType() );
        assertNull( raif1.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif1.getFieldValues()[ 0 ].getNature() );

        ActionInsertFact r2 = model.getRHSBoundFact( "$ins2" );
        assertNotNull( r2 );
        assertTrue( r2 instanceof ActionInsertFactCol52ActionInsertLogicalFactAdaptor);
        ActionInsertFactCol52ActionInsertLogicalFactAdaptor raif2 = (ActionInsertFactCol52ActionInsertLogicalFactAdaptor) r2;
        assertEquals( "Person2",
                      raif2.getFactType() );
        assertEquals( "rating2",
                      raif2.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif2.getFieldValues()[ 0 ].getType() );
        assertNull( raif2.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif2.getFieldValues()[ 0 ].getNature() );

        ActionInsertFact r3 = model.getRHSBoundFact( "$aif" );
        assertNotNull( r3 );
        assertTrue( r3 instanceof ActionInsertFact );
        ActionInsertFact raif3 = (ActionInsertFact) r3;
        assertEquals( "Person",
                      raif3.getFactType() );
        assertEquals( "rating",
                      raif3.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif3.getFieldValues()[ 0 ].getType() );
        assertNull( raif3.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif3.getFieldValues()[ 0 ].getNature() );

    }
View Full Code Here

        ins.setType( DataType.TYPE_STRING );
        dt.getActionCols().add( ins );

        //Setup RuleModel columns (new BRLActionColumn being added)
        BRLRuleModel model = new BRLRuleModel( dt );
        ActionInsertFact aif = new ActionInsertFact( "Person" );
        aif.setBoundName( "$aif" );
        aif.addFieldValue( new ActionFieldValue( "rating",
                                                 null,
                                                 DataType.TYPE_STRING ) );
        aif.getFieldValues()[ 0 ].setNature( BaseSingleFieldConstraint.TYPE_LITERAL );
        model.addRhsItem( aif );

        //Checks
        assertNotNull( model.getRHSBoundFacts() );
        assertEquals( 2,
                      model.getRHSBoundFacts().size() );
        assertTrue( model.getRHSBoundFacts().contains( "$ins" ) );
        assertTrue( model.getRHSBoundFacts().contains( "$aif" ) );

        ActionInsertFact r1 = model.getRHSBoundFact( "$ins" );
        assertNotNull( r1 );
        assertTrue( r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor );
        ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
        assertEquals( "Person",
                      raif1.getFactType() );
        assertEquals( "rating",
                      raif1.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif1.getFieldValues()[ 0 ].getType() );
        assertNull( raif1.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif1.getFieldValues()[ 0 ].getNature() );

        ActionInsertFact r2 = model.getRHSBoundFact( "$aif" );
        assertNotNull( r2 );
        assertTrue( r2 instanceof ActionInsertFact );
        ActionInsertFact raif2 = (ActionInsertFact) r2;
        assertEquals( "Person",
                      raif2.getFactType() );
        assertEquals( "rating",
                      raif2.getFieldValues()[ 0 ].getField() );
        assertEquals( DataType.TYPE_STRING,
                      raif2.getFieldValues()[ 0 ].getType() );
        assertNull( raif2.getFieldValues()[ 0 ].getValue() );
        assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL,
                      raif2.getFieldValues()[ 0 ].getNature() );
    }
View Full Code Here

TOP

Related Classes of org.drools.workbench.models.commons.shared.rule.ActionInsertFact

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.