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

Examples of org.drools.guvnor.models.commons.shared.rule.DSLSentence


        }
    }

    private DSLSentence toDSLSentence( List<String> dslPatterns,
                                       String dslLine ) {
        DSLSentence dslSentence = new DSLSentence();
        for ( String dslPattern : dslPatterns ) {
            String regex = dslPattern.replaceAll( "\\{\\s*[\\:\\.\\w]+\\s*\\}", "(.*)" );
            Matcher m = Pattern.compile( regex ).matcher( dslLine );
            if ( m.matches() ) {
                dslSentence.setDefinition( dslPattern );
                for ( int i = 0; i < m.groupCount(); i++ ) {
                    dslSentence.getValues().get( i ).setValue( m.group( i + 1 ) );
                }
                return dslSentence;
            }
        }
        dslSentence.setDefinition( dslLine );
        return dslSentence;
    }
View Full Code Here


        m.addRhsItem( set );

        final ActionRetractFact ret = new ActionRetractFact( "p1" );
        m.addRhsItem( ret );

        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( "Send an email to {administrator}" );

        m.addRhsItem( sen );
        return m;
    }
View Full Code Here

        String dslFile = "[then]Send an email to {administrator}=sendMailTo({administrator});";

        RuleModel unmarshalledModel = brlPersistence.unmarshalUsingDSL( drl, null, dslFile );

        IAction[] actions = unmarshalledModel.rhs;
        DSLSentence dslSentence = (DSLSentence) actions[ actions.length - 1 ];
        assertEquals( "Send an email to {administrator}", dslSentence.getDefinition() );

        assertEqualsIgnoreWhitespace( expected, brlPersistence.marshal( unmarshalledModel ) );
    }
View Full Code Here

                        "\t\tThe credit rating is AA\n" +
                        "\tthen\n" +
                        "end\n";
        final String dslDefinition = "The credit rating is {rating:ENUM:Applicant.creditRating}";

        final DSLSentence dsl = new DSLSentence();
        dsl.setDefinition( dslDefinition );

        //Check values are correctly parsed
        final List<DSLVariableValue> values = dsl.getValues();
        assertEquals( 1,
                      values.size() );
        assertTrue( values.get( 0 ) instanceof DSLComplexVariableValue );
        assertEquals( "rating",
                      values.get( 0 ).getValue() );
        assertEquals( "ENUM:Applicant.creditRating",
                      ( (DSLComplexVariableValue) values.get( 0 ) ).getId() );

        //The following line is normally performed by the UI when the user sets values
        dsl.getValues().get( 0 ).setValue( "AA" );

        //Check interpolation
        final String expansion = dsl.interpolate();

        assertEquals( "The credit rating is AA",
                      expansion );
        assertEquals( dsl.getDefinition(),
                      dslDefinition );

        final RuleModel m = new RuleModel();
        m.name = "Rule With DSL";
        m.addLhsItem( dsl );

        String drl = brlPersistence.marshal( m );
        assertEqualsIgnoreWhitespace( expected, drl );

        String dslFile = "[when]" + dslDefinition + "=Credit( rating == {rating} )";

        RuleModel unmarshalledModel = brlPersistence.unmarshalUsingDSL( drl, null, dslFile );

        DSLSentence dslSentence = (DSLSentence) unmarshalledModel.lhs[ 0 ];
        assertEquals( dslDefinition, dslSentence.getDefinition() );
        assertEquals( 1, dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "AA", dslComplexVariableValue.getValue() );
        assertEquals( "ENUM:Applicant.creditRating", dslComplexVariableValue.getId() );

        assertEqualsIgnoreWhitespace( expected, brlPersistence.marshal( unmarshalledModel ) );
    }
View Full Code Here

                        "when\n" +
                        "The credit rating is AA\n" +
                        "then\n" +
                        "end";

        final DSLSentence dsl = new DSLSentence();
        dsl.setDefinition( dslDefinition );
        //The following line is normally performed by the UI when the user sets values
        dsl.getValues().get( 0 ).setValue( "AA" );

        //Append DSL to RuleModel to check marshalling
        final RuleModel m = new RuleModel();
        m.name = "r1";
        m.addLhsItem( dsl );
View Full Code Here

        final ActionRetractFact ret = new ActionRetractFact( "p1" );
        m.addRhsItem( ret );

        if ( useDsl ) {
            final DSLSentence sen = new DSLSentence();
            sen.setDefinition( "Send an email to {administrator}" );
            m.addRhsItem( sen );
        }

        return m;
    }
View Full Code Here

    }

    @Test
    public void testAssertWithDSL() throws Exception {
        RuleModel m = new RuleModel();
        DSLSentence sen = new DSLSentence();
        sen.setDefinition( "I CAN HAS DSL" );
        m.addRhsItem( sen );
        ActionInsertFact ins = new ActionInsertFact( "Shizzle" );
        ActionFieldValue val = new ActionFieldValue( "goo",
                                                     "42",
                                                     "Numeric" );
View Full Code Here

    @Test
    public void testCompositeFactPatternWithFromWithDSL() {
        final RuleModel m = new RuleModel();
        m.name = "model";

        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( "A DSL phrase" );
        m.addLhsItem( sen );

        final FactPattern fp1 = new FactPattern( "Data" );
        fp1.setBoundName( "$d" );
        m.addLhsItem( fp1 );
View Full Code Here

        assertEquals( 1,
                      rm.lhs.length );
        assertTrue( rm.lhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslPattern = (DSLSentence) rm.lhs[ 0 ];

        assertEquals( "If processInstance",
                      dslPattern.getDefinition() );
        assertEquals( 0,
                      dslPattern.getValues().size() );

        assertEquals( 1,
                      rm.rhs.length );
        assertTrue( rm.rhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslAction = (DSLSentence) rm.rhs[ 0 ];

        assertEquals( "MyLog {myout}",
                      dslAction.getDefinition() );
        assertEquals( 2,
                      dslAction.getValues().size() );

        assertTrue( dslAction.getValues().get( 0 ) instanceof DSLVariableValue );
        assertTrue( dslAction.getValues().get( 1 ) instanceof DSLVariableValue );

        assertEquals( "sample out rule 1",
                      dslAction.getValues().get( 0 ).getValue() );
        assertEquals( "myout",
                      dslAction.getValues().get( 1 ).getValue() );

    }
View Full Code Here

        assertEquals( 1,
                      rm.lhs.length );
        assertTrue( rm.lhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslPattern = (DSLSentence) rm.lhs[ 0 ];

        assertEquals( "If processInstance",
                      dslPattern.getDefinition() );
        assertEquals( 0,
                      dslPattern.getValues().size() );

        assertEquals( 1,
                      rm.rhs.length );
        assertTrue( rm.rhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslAction = (DSLSentence) rm.rhs[ 0 ];

        assertEquals( "MyLog {myout}",
                      dslAction.getDefinition() );
        assertEquals( 2,
                      dslAction.getValues().size() );

        assertTrue( dslAction.getValues().get( 0 ) instanceof DSLVariableValue );
        assertTrue( dslAction.getValues().get( 1 ) instanceof DSLVariableValue );

        assertEquals( "5-4 sample out",
                      dslAction.getValues().get( 0 ).getValue() );
        assertEquals( "myout",
                      dslAction.getValues().get( 1 ).getValue() );

    }
View Full Code Here

TOP

Related Classes of org.drools.guvnor.models.commons.shared.rule.DSLSentence

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.