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

Examples of org.drools.ide.common.client.modeldriven.dt.TypeSafeGuidedDecisionTable


        rule1.updateFormat( AssetFormats.DRL );
        rule1.updateContent( "rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end" );
        rule1.checkin( "" );
        repo.save();

        TypeSafeGuidedDecisionTable dt = new TypeSafeGuidedDecisionTable();
        ConditionCol col = new ConditionCol();
        col.setBoundName( "p" );
        col.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        col.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        col.setFactField( "hair" );
        col.setFactType( "Person" );
        col.setOperator( "==" );
        dt.getConditionCols().add( col );

        ActionSetFieldCol ac = new ActionSetFieldCol();
        ac.setBoundName( "p" );
        ac.setFactField( "likes" );
        ac.setType( SuggestionCompletionEngine.TYPE_STRING );
        dt.getActionCols().add( ac );

        dt.setData( RepositoryUpgradeHelper.makeDataLists( new String[][]{new String[]{"1", "descrip", "pink", "cheese"}} ) );

        String uid = impl.createNewRule( "decTable",
                                         "",
                                         "decisiontables",
                                         pkg.getName(),
View Full Code Here


        asset.checkin( "" );

        asset = pkg.addAsset( "testLoadSaveEventDT",
                              "" );
        asset.updateFormat( AssetFormats.DECISION_TABLE_GUIDED );
        TypeSafeGuidedDecisionTable gt = new TypeSafeGuidedDecisionTable();
        asset.updateContent( GuidedDTXMLPersistence.getInstance().marshal( gt ) );
        asset.checkin( "" );
    }
View Full Code Here

        PackageItem pkg = repo.loadDefaultPackage();
        AssetItem asset = pkg.addAsset( "testEmptyDT",
                                        "" );
        asset.updateFormat( AssetFormats.DECISION_TABLE_GUIDED );
        TypeSafeGuidedDecisionTable gt = new TypeSafeGuidedDecisionTable();
        asset.updateContent( GuidedDTXMLPersistence.getInstance().marshal( gt ) );
        asset.checkin( "" );

        GuidedDTContentHandler ch = new GuidedDTContentHandler();
        ch.compile( null,
View Full Code Here

                                                SuggestionCompletionEngine.TYPE_BOOLEAN )
                        } );
            }
        } );

        dt = new TypeSafeGuidedDecisionTable();

        at1 = new AttributeCol();
        at1.setAttribute( "salience" );
        at2 = new AttributeCol();
        at2.setAttribute( "enabled" );
View Full Code Here

    }

    @Test
    public void testRoundTrip() {

        TypeSafeGuidedDecisionTable dt = new TypeSafeGuidedDecisionTable();

        dt.getActionCols().add( new ActionInsertFactCol() );
        ActionSetFieldCol set = new ActionSetFieldCol();
        set.setFactField( "foo" );
        dt.getActionCols().add( set );

        dt.getMetadataCols().add( new MetadataCol() );

        dt.getAttributeCols().add( new AttributeCol() );

        dt.getConditionCols().add( new ConditionCol() );

        dt.setData( RepositoryUpgradeHelper.makeDataLists( new String[][]{new String[]{"1", "hola"}} ) );
        dt.setTableName( "blah" );

        String xml = GuidedDTXMLPersistence.getInstance().marshal( dt );
        System.out.println( xml );
        assertNotNull( xml );
        assertEquals( -1,
                      xml.indexOf( "ActionSetField" ) );
        assertEquals( -1,
                      xml.indexOf( "ConditionCol" ) );
        assertEquals( -1,
                      xml.indexOf( "GuidedDecisionTable" ) );

        TypeSafeGuidedDecisionTable dt_ = GuidedDTXMLPersistence.getInstance().unmarshal( xml );
        assertNotNull( dt_ );
        assertEquals( "blah",
                      dt_.getTableName() );
        assertEquals( 1,
                      dt_.getMetadataCols().size() );
        assertEquals( 1,
                      dt_.getAttributeCols().size() );
        assertEquals( 2,
                      dt_.getActionCols().size() );
        assertEquals( 1,
                      dt_.getConditionCols().size() );

    }
View Full Code Here

    }

    @Test
    public void testBackwardsCompatability() throws Exception {
        String xml = BRLPersistenceTest.loadResource( "ExistingDecisionTable.xml" );
        TypeSafeGuidedDecisionTable dt_ = GuidedDTXMLPersistence.getInstance().unmarshal( xml );
        assertNotNull( dt_ );
        assertEquals( "blah",
                      dt_.getTableName() );
        assertEquals( 1,
                      dt_.getMetadataCols().size() );
        assertEquals( 1,
                      dt_.getAttributeCols().size() );
        assertEquals( 2,
                      dt_.getActionCols().size() );
        assertEquals( 1,
                      dt_.getConditionCols().size() );

        assertTrue( dt_.getActionCols().get( 1 ) instanceof ActionSetFieldCol );
        ActionSetFieldCol asf = (ActionSetFieldCol) dt_.getActionCols().get( 1 );
        assertEquals( "foo",
                      asf.getFactField() );
        assertEquals( false,
                      asf.isUpdate() );
    }
View Full Code Here

    //
    //
    // }
    @Test
    public void testValueLists() {
        TypeSafeGuidedDecisionTable dt = new TypeSafeGuidedDecisionTable();

        // add cols for LHS
        ConditionCol c1 = new ConditionCol();
        c1.setBoundName( "c1" );
        c1.setFactType( "Driver" );
        c1.setFactField( "name" );
        c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c1 );

        ConditionCol c1_ = new ConditionCol();
        c1_.setBoundName( "c1" );
        c1_.setFactType( "Driver" );
        c1_.setFactField( "name" );
        c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE );

        dt.getConditionCols().add( c1_ );

        ConditionCol c1__ = new ConditionCol();
        c1__.setBoundName( "c1" );
        c1__.setFactType( "Driver" );
        c1__.setFactField( "name" );
        c1__.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c1__.setValueList( "one,two,three" );
        dt.getConditionCols().add( c1__ );

        ConditionCol c2 = new ConditionCol();
        c2.setBoundName( "c2" );
        c2.setFactType( "Driver" );
        c2.setFactField( "nothing" );
        c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c2 );

        ActionSetFieldCol asf = new ActionSetFieldCol();
        asf.setBoundName( "c1" );
        asf.setFactField( "name" );
        dt.getActionCols().add( asf );

        ActionInsertFactCol ins = new ActionInsertFactCol();
        ins.setBoundName( "x" );
        ins.setFactField( "rating" );
        ins.setFactType( "Person" );
        dt.getActionCols().add( ins );

        ActionInsertFactCol ins_ = new ActionInsertFactCol();
        ins_.setBoundName( "x" );
        ins_.setFactField( "rating" );
        ins_.setFactType( "Person" );
        ins_.setValueList( "one,two,three" );
        dt.getActionCols().add( ins_ );

        ActionSetFieldCol asf_ = new ActionSetFieldCol();
        asf_.setBoundName( "c1" );
        asf_.setFactField( "goo" );
        dt.getActionCols().add( asf_ );

        ActionSetFieldCol asf__ = new ActionSetFieldCol();
        asf__.setBoundName( "c1" );
        asf__.setFactField( "goo" );
        asf__.setValueList( "one,two,three" );
        dt.getActionCols().add( asf__ );

        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
        sce.putDataEnumList( "Driver.name",
                             new String[]{"bob", "michael"} );
        sce.putDataEnumList( "Person.rating",
                             new String[]{"1", "2"} );

        String[] r = dt.getValueList( c1,
                                      sce );
        assertEquals( 2,
                      r.length );
        assertEquals( "bob",
                      r[0] );
        assertEquals( "michael",
                      r[1] );

        assertEquals( 0,
                      dt.getValueList( c1_,
                                       sce ).length );

        r = dt.getValueList( c1__,
                             sce );
        assertEquals( 3,
                      r.length );
        assertEquals( "one",
                      r[0] );
        assertEquals( "two",
                      r[1] );
        assertEquals( "three",
                      r[2] );

        assertEquals( 0,
                      dt.getValueList( c2,
                                       sce ).length );

        r = dt.getValueList( asf,
                             sce );
        assertEquals( 2,
                      r.length );
        assertEquals( "bob",
                      r[0] );
        assertEquals( "michael",
                      r[1] );

        r = dt.getValueList( ins,
                             sce );
        assertEquals( 2,
                      r.length );
        assertEquals( "1",
                      r[0] );
        assertEquals( "2",
                      r[1] );

        r = dt.getValueList( ins_,
                             sce );
        assertEquals( 3,
                      r.length );
        assertEquals( "one",
                      r[0] );
        assertEquals( "two",
                      r[1] );
        assertEquals( "three",
                      r[2] );

        assertEquals( 0,
                      dt.getValueList( asf_,
                                       sce ).length );

        r = dt.getValueList( asf__,
                             sce );
        assertEquals( 3,
                      r.length );
        assertEquals( "one",
                      r[0] );
        assertEquals( "two",
                      r[1] );
        assertEquals( "three",
                      r[2] );

        AttributeCol at = new AttributeCol();
        at.setAttribute( "no-loop" );
        dt.getAttributeCols().add( at );

        r = dt.getValueList( at,
                             sce );
        assertEquals( 2,
                      r.length );
        assertEquals( "true",
                      r[0] );
        assertEquals( "false",
                      r[1] );

        at.setAttribute( "enabled" );
        assertEquals( 2,
                      dt.getValueList( at,
                                       sce ).length );

        at.setAttribute( "salience" );
        assertEquals( 0,
                      dt.getValueList( at,
                                       sce ).length );

    }
View Full Code Here

                                                SuggestionCompletionEngine.TYPE_STRING )
                        } );
            }
        } );

        TypeSafeGuidedDecisionTable dt = new TypeSafeGuidedDecisionTable();

        AttributeCol at = new AttributeCol();
        at.setAttribute( "salience" );
        AttributeCol at_ = new AttributeCol();
        at_.setAttribute( "enabled" );

        dt.getAttributeCols().add( at );
        dt.getAttributeCols().add( at_ );

        ConditionCol c1 = new ConditionCol();
        c1.setBoundName( "c1" );
        c1.setFactType( "Driver" );
        c1.setFactField( "name" );
        c1.setOperator( "==" );
        c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c1 );

        ConditionCol c1_ = new ConditionCol();
        c1_.setBoundName( "c1" );
        c1_.setFactType( "Driver" );
        c1_.setFactField( "age" );
        c1_.setOperator( "==" );
        c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c1_ );

        ConditionCol c2 = new ConditionCol();
        c2.setBoundName( "c1" );
        c2.setFactType( "Driver" );
        c2.setFactField( "age" );
        c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c2 );

        ActionSetFieldCol a = new ActionSetFieldCol();
        a.setBoundName( "c1" );
        a.setFactField( "name" );
        dt.getActionCols().add( a );

        ActionSetFieldCol a2 = new ActionSetFieldCol();
        a2.setBoundName( "c1" );
        a2.setFactField( "age" );
        dt.getActionCols().add( a2 );

        ActionInsertFactCol ins = new ActionInsertFactCol();
        ins.setBoundName( "x" );
        ins.setFactType( "Driver" );
        ins.setFactField( "name" );
        dt.getActionCols().add( ins );

        ActionInsertFactCol ins_ = new ActionInsertFactCol();
        ins_.setBoundName( "x" );
        ins_.setFactType( "Driver" );
        ins_.setFactField( "age" );
        dt.getActionCols().add( ins_ );

        assertTrue( dt.isNumeric( at,
                                  sce ) );
        assertFalse( dt.isNumeric( at_,
                                   sce ) );
        assertFalse( dt.isNumeric( c1,
                                   sce ) );
        assertTrue( dt.isNumeric( c1_,
                                  sce ) );
        assertFalse( dt.isNumeric( a,
                                   sce ) );
        assertTrue( dt.isNumeric( a2,
                                  sce ) );
        assertFalse( dt.isNumeric( ins,
                                   sce ) );
        assertTrue( dt.isNumeric( ins_,
                                  sce ) );
        assertFalse( dt.isNumeric( c2,
                                   sce ) );
    }
View Full Code Here

                                                SuggestionCompletionEngine.TYPE_BOOLEAN )
                       } );
            }
        } );

        TypeSafeGuidedDecisionTable dt = new TypeSafeGuidedDecisionTable();

        AttributeCol salienceAttribute = new AttributeCol();
        salienceAttribute.setAttribute( "salience" );
        AttributeCol enabledAttribute = new AttributeCol();
        enabledAttribute.setAttribute( "enabled" );

        dt.getAttributeCols().add( salienceAttribute );
        dt.getAttributeCols().add( enabledAttribute );

        ConditionCol conditionColName = new ConditionCol();
        conditionColName.setBoundName( "c1" );
        conditionColName.setFactType( "Driver" );
        conditionColName.setFactField( "name" );
        conditionColName.setOperator( "==" );
        conditionColName.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( conditionColName );

        ConditionCol conditionColAge = new ConditionCol();
        conditionColAge.setBoundName( "c1" );
        conditionColAge.setFactType( "Driver" );
        conditionColAge.setFactField( "age" );
        conditionColAge.setOperator( "==" );
        conditionColAge.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( conditionColAge );

        ConditionCol conditionColDate = new ConditionCol();
        conditionColDate.setBoundName( "c1" );
        conditionColDate.setFactType( "Driver" );
        conditionColDate.setFactField( "date" );
        conditionColDate.setOperator( "==" );
        conditionColDate.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( conditionColDate );

        ConditionCol conditionColApproved = new ConditionCol();
        conditionColApproved.setBoundName( "c1" );
        conditionColApproved.setFactType( "Driver" );
        conditionColApproved.setFactField( "approved" );
        conditionColApproved.setOperator( "==" );
        conditionColApproved.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( conditionColApproved );

        ConditionCol conditionColAge2 = new ConditionCol();
        conditionColAge2.setBoundName( "c1" );
        conditionColAge2.setFactType( "Driver" );
        conditionColAge2.setFactField( "age" );
        conditionColAge2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( conditionColAge2 );

        ActionSetFieldCol a = new ActionSetFieldCol();
        a.setBoundName( "c1" );
        a.setFactField( "name" );
        dt.getActionCols().add( a );

        ActionSetFieldCol a2 = new ActionSetFieldCol();
        a2.setBoundName( "c1" );
        a2.setFactField( "age" );
        dt.getActionCols().add( a2 );

        ActionInsertFactCol ins = new ActionInsertFactCol();
        ins.setBoundName( "x" );
        ins.setFactType( "Driver" );
        ins.setFactField( "name" );
        dt.getActionCols().add( ins );

        ActionInsertFactCol ins_ = new ActionInsertFactCol();
        ins_.setBoundName( "x" );
        ins_.setFactType( "Driver" );
        ins_.setFactField( "age" );
        dt.getActionCols().add( ins_ );

        assertEquals( "salience",
                      dt.getType( salienceAttribute,
                                  sce ) );
        assertEquals( "enabled",
                      dt.getType( enabledAttribute,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      dt.getType( conditionColName,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC,
                      dt.getType( conditionColAge,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_DATE,
                      dt.getType( conditionColDate,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_BOOLEAN,
                      dt.getType( conditionColApproved,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      dt.getType( a,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC,
                      dt.getType( a2,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_STRING,
                      dt.getType( ins,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC,
                      dt.getType( ins_,
                                  sce ) );
        assertEquals( SuggestionCompletionEngine.TYPE_NUMERIC,
                      dt.getType( conditionColAge2,
                                  sce ) );
    }
View Full Code Here

                                  sce ) );
    }

    @Test
    public void testNoConstraintLists() {
        TypeSafeGuidedDecisionTable dt = new TypeSafeGuidedDecisionTable();

        // add cols for LHS
        ConditionCol c1 = new ConditionCol();
        c1.setBoundName( "c1" );
        c1.setFactType( "Driver" );
        c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        dt.getConditionCols().add( c1 );

        ConditionCol c2 = new ConditionCol();
        c2.setBoundName( "c2" );
        c2.setFactType( "Driver" );
        c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c2.setValueList( "a,b,c" );
        dt.getConditionCols().add( c2 );

        SuggestionCompletionEngine sce = new SuggestionCompletionEngine();
        sce.putDataEnumList( "Driver.name",
                             new String[]{"bob", "michael"} );

        assertEquals( 0,
                      dt.getValueList( c1,
                                       sce ).length );
        assertEquals( 3,
                      dt.getValueList( c2,
                                       sce ).length );

    }
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.dt.TypeSafeGuidedDecisionTable

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.