Package org.drools.ide.common.client.modeldriven.brl

Examples of org.drools.ide.common.client.modeldriven.brl.FactPattern


                                                                        enums );
        assertEquals( "String",
                      engine.getFieldType( "NestedClass",
                                           "name" ) );

        FactPattern pat = new FactPattern( "Fact" );
        SingleFieldConstraint f1 = new SingleFieldConstraint( "f1" );
        f1.setValue( "a1" );
        pat.addConstraint( f1 );
        pat.addConstraint( new SingleFieldConstraint( "f2" ) );

        DropDownData data = engine.getEnums( pat.getFactType(),
                                             pat.constraintList,
                                             "f2" );

        assertNotNull( data );
        assertEquals( 3,
View Full Code Here


        sce.putDataEnumList( "Fact.value[type=sex]",
                               new String[]{"M", "F"} );
        sce.putDataEnumList( "Fact.value[type=colour]",
                               new String[]{"RED", "WHITE", "BLUE"} );

        FactPattern pat = new FactPattern( "Fact" );
        SingleFieldConstraint sfc = new SingleFieldConstraint( "type" );
        sfc.setValue( "sex" );
        pat.addConstraint( sfc );
        String[] result = sce.getEnums( pat.getFactType(),
                                        pat.constraintList,
                                        "value" ).fixedList;
        assertEquals( 2,
                      result.length );
        assertEquals( "M",
                      result[0] );
        assertEquals( "F",
                      result[1] );

        pat = new FactPattern( "Fact" );
        sfc = new SingleFieldConstraint( "type" );
        sfc.setValue( "colour" );
        pat.addConstraint( sfc );

        result = sce.getEnums( pat.getFactType(),
                               pat.constraintList,
                               "value" ).fixedList;
        assertEquals( 3,
                      result.length );
        assertEquals( "RED",
                      result[0] );
        assertEquals( "WHITE",
                      result[1] );
        assertEquals( "BLUE",
                      result[2] );

        result = sce.getEnums( pat.getFactType(),
                               pat.constraintList,
                               "type" ).fixedList;
        assertEquals( 2,
                      result.length );
        assertEquals( "sex",
View Full Code Here

        sce.putDataEnumList( "Fact.field3[field1=a1,field2=b1]",
                               new String[]{"c1", "c2", "c3"} );
        sce.putDataEnumList( "Fact.field4[field1=a1]",
                               new String[]{"d1", "d2"} );

        FactPattern pat = new FactPattern( "Fact" );
        SingleFieldConstraint sfc = new SingleFieldConstraint( "field1" );
        sfc.setValue( "a1" );
        pat.addConstraint( sfc );
        SingleFieldConstraint sfc2 = new SingleFieldConstraint( "field2" );
        sfc2.setValue( "b1" );
        pat.addConstraint( sfc2 );

        String[] result = sce.getEnums( pat.getFactType(),
                                        pat.constraintList,
                                        "field3" ).fixedList;
        assertEquals( 3,
                      result.length );
        assertEquals( "c1",
View Full Code Here

        sce.putDataEnumList( "Fact.field5",
                               new String[]{"e1", "e2"} );
        sce.putDataEnumList( "Fact.field6[field1=a1, field2=b2, field3=c3,longerField4=d1,field5=e2]",
                               new String[]{"f1", "f2"} );

        FactPattern pat = new FactPattern( "Fact" );
        SingleFieldConstraint sfc = new SingleFieldConstraint( "field1" );
        sfc.setValue( "a1" );
        pat.addConstraint( sfc );
        SingleFieldConstraint sfc2 = new SingleFieldConstraint( "field2" );
        sfc2.setValue( "b2" );
        pat.addConstraint( sfc2 );
        SingleFieldConstraint sfc3 = new SingleFieldConstraint( "field3" );
        sfc3.setValue( "c3" );
        pat.addConstraint( sfc3 );
        SingleFieldConstraint sfc4 = new SingleFieldConstraint( "longerField4" );
        sfc4.setValue( "d1" );
        pat.addConstraint( sfc4 );

        assertNull( sce.getEnums( pat.getFactType(),
                                  pat.constraintList,
                                  "field6" ) );

        SingleFieldConstraint sfc5 = new SingleFieldConstraint( "field5" );
        sfc5.setValue( "e2" );
        pat.addConstraint( sfc5 );

        String[] result2 = sce.getEnums( pat.getFactType(),
                                         pat.constraintList,
                                         "field6" ).fixedList;
        assertEquals( 2,
                      result2.length );
        assertEquals( "f1",
View Full Code Here

        sce.putDataEnumList( "Fact.type",
                               new String[]{"sex", "colour"} );
        sce.putDataEnumList( "Fact.value[f1, f2]",
                               new String[]{"select something from database where x=@{f1} and y=@{f2}"} );

        FactPattern fp = new FactPattern( "Fact" );
        String[] drops = sce.getEnums( fp.getFactType(),
                                       fp.constraintList,
                                       "type" ).fixedList;
        assertEquals( 2,
                      drops.length );
        assertEquals( "sex",
                      drops[0] );
        assertEquals( "colour",
                      drops[1] );

        Map<String, Object> lookupFields = sce.loadDataEnumLookupFields();
        assertEquals( 1,
                      lookupFields.size() );
        String[] flds = (String[]) lookupFields.get( "Fact.value" );
        assertEquals( 2,
                      flds.length );
        assertEquals( "f1",
                      flds[0] );
        assertEquals( "f2",
                      flds[1] );

        FactPattern pat = new FactPattern( "Fact" );
        SingleFieldConstraint sfc = new SingleFieldConstraint( "f1" );
        sfc.setValue( "f1val" );
        pat.addConstraint( sfc );
        sfc = new SingleFieldConstraint( "f2" );
        sfc.setValue( "f2val" );
        pat.addConstraint( sfc );

        DropDownData dd = sce.getEnums( pat.getFactType(),
                                        pat.constraintList,
                                        "value" );
        assertNull( dd.fixedList );
        assertNotNull( dd.queryExpression );
        assertNotNull( dd.valuePairs );
View Full Code Here

        sce.putDataEnumList( "Fact.value[e1, e2]",
                               new String[]{"select something from database where x=@{e1} and y=@{e2}"} );
        sce.putDataEnumList( "Fact.value[f1, f2]",
                               new String[]{"select something from database where x=@{f1} and y=@{f2}"} );

        FactPattern fp = new FactPattern( "Fact" );
        String[] drops = sce.getEnums( fp.getFactType(),
                                       fp.constraintList,
                                       "type" ).fixedList;
        assertEquals( 2,
                      drops.length );
        assertEquals( "sex",
                      drops[0] );
        assertEquals( "colour",
                      drops[1] );

        Map<String, Object> lookupFields = sce.loadDataEnumLookupFields();
        assertEquals( 1,
                      lookupFields.size() );
        String[] flds = (String[]) lookupFields.get( "Fact.value" );
        assertEquals( 2,
                      flds.length );
        assertEquals( "f1",
                      flds[0] );
        assertEquals( "f2",
                      flds[1] );

        FactPattern pat = new FactPattern( "Fact" );
        SingleFieldConstraint sfc = new SingleFieldConstraint( "f1" );
        sfc.setValue( "f1val" );
        pat.addConstraint( sfc );
        sfc = new SingleFieldConstraint( "f2" );
        sfc.setValue( "f2val" );
        pat.addConstraint( sfc );

        DropDownData dd = sce.getEnums( pat.getFactType(),
                                        pat.constraintList,
                                        "value" );
        assertNull( dd.fixedList );
        assertNotNull( dd.queryExpression );
        assertNotNull( dd.valuePairs );
View Full Code Here

                                        "" );
        rule2.updateFormat( AssetFormats.BUSINESS_RULE );

        RuleModel model = new RuleModel();
        model.name = "rule2";
        FactPattern pattern = new FactPattern( "Person" );

        SingleFieldConstraint con = new SingleFieldConstraint();
        con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_PREDICATE );
        con.setValue( "name soundslike 'foobar'" );
        pattern.addConstraint( con );

        pattern.setBoundName( "p" );
        ActionSetField action = new ActionSetField( "p" );
        ActionFieldValue value = new ActionFieldValue( "age",
                                                       "42",
                                                       SuggestionCompletionEngine.TYPE_NUMERIC );
        action.addFieldValue( value );

        model.addLhsItem( pattern );
        model.addRhsItem( action );

        rule2.updateContent( BRXMLPersistence.getInstance().marshal( model ) );
        rule2.checkin( "" );
        repo.save();

        BuilderResult result = repositoryPackageService.buildPackage( pkg.getUUID(),
                                                                      true );
        if ( result != null ) {
            for ( int i = 0; i < result.getLines().size(); i++ ) {
                System.err.println( result.getLines().get( i ).getMessage() );
            }
        }
        assertNull( result );

        pkg = repo.loadPackage( "testBinaryPackageCompileBRL" );
        byte[] binPackage = pkg.getCompiledPackageBytes();

        // Here is where we write it out is needed... set to true if needed for
        // the binary test below "testLoadAndExecBinary"
        boolean saveBinPackage = false;
        if ( saveBinPackage ) {
            FileOutputStream out = new FileOutputStream( "RepoBinPackage.pkg" );
            out.write( binPackage );
            out.flush();
            out.close();
        }

        assertNotNull( binPackage );

        Package[] binPkgs = (Package[]) DroolsStreamUtils.streamIn( binPackage );
        assertNotNull( binPkgs );
        assertEquals( 1,
                      binPkgs.length );
        
        Package binPkg = binPkgs[0];
        assertNotNull( binPkg );
        assertTrue( binPkg.isValid() );

        // and this shows off the "soundex" thing...
        Person p = new Person( "fubar" );

        BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
        loader.addPackage( new ByteArrayInputStream( binPackage ) );
        RuleBase rb = loader.getRuleBase();

        StatelessSession sess = rb.newStatelessSession();
        sess.execute( p );
        assertEquals( 42,
                      p.getAge() );

        repositoryPackageService.createPackageSnapshot( "testBinaryPackageCompileBRL",
                                                        "SNAP1",
                                                        false,
                                                        "" );

        pattern.setFactType( "PersonX" );
        rule2.updateContent( BRXMLPersistence.getInstance().marshal( model ) );
        rule2.checkin( "" );

        result = repositoryPackageService.buildPackage( pkg.getUUID(),
                                                        true );
View Full Code Here

                                new Listener() {
                                    public void handleEvent(Event event) {
                                        if ( factsCombo.getSelectionIndex() == 0 ) {
                                            return;
                                        }
                                        modeller.getModel().addLhsItem( new FactPattern( factsCombo.getText() ) );
                                        modeller.reloadLhs();
                                        modeller.setDirty( true );
                                        close();
                                    }
                                } );
View Full Code Here

        if (getCompletion().isGlobalVariable(set.variable)) {
            this.fieldCompletions = getCompletion()
                    .getFieldCompletionsForGlobalVariable(set.variable);
            this.variableClass = (String) getCompletion().getGlobalVariable(set.variable);
        } else {
            FactPattern pattern = rule.getLHSBoundFact(set.variable);
            this.fieldCompletions = getCompletion().getFieldCompletions(
                    pattern.getFactType());
            this.isBoundFact = true;
            this.variableClass = pattern.getFactType();
        }

        GridLayout l = new GridLayout();
        l.numColumns = 6;
        l.marginBottom = 0;
View Full Code Here

public class RuleModelTest {

    @Test
    public void testAddItemLhs() {
        final RuleModel model = new RuleModel();
        final FactPattern x = new FactPattern();
        model.addLhsItem( x );
        assertEquals( 1,
                      model.lhs.length );

        final FactPattern y = new FactPattern();
        model.addLhsItem( y );

        assertEquals( 2,
                      model.lhs.length );
        assertEquals( x,
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.brl.FactPattern

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.