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

Examples of org.drools.ide.common.client.modeldriven.dt52.GuidedDecisionTable52


    }

    @Test
    public void testDefaultValue() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "$c" );
        p1.setFactType( "CheeseLover" );

        ConditionCol52 c = new ConditionCol52();
        c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        c.setFactField( "favouriteCheese" );
        c.setDefaultValue( "cheddar" );
        c.setOperator( "==" );
        p1.getChildColumns().add( c );
        dt.getConditions().add( p1 );

        //With provided value
        String[][] data = new String[][]{
                new String[]{"1", "desc", "edam"},
        };
        dt.setData( upgrader.makeDataLists( data ) );

        String drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertFalse( drl.indexOf( "$c : CheeseLover( favouriteCheese == \"edam\" )" ) == -1 );

        //Without provided value #1
        data = new String[][]{
                new String[]{"1", "desc", null},
        };
        dt.setData( upgrader.makeDataLists( data ) );

        drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertTrue( drl.indexOf( "$c : CheeseLover( favouriteCheese == \"cheddar\" )" ) == -1 );

        //Without provided value #2
        data = new String[][]{
                new String[]{"1", "desc", ""},
        };
        dt.setData( upgrader.makeDataLists( data ) );

        drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

        assertTrue( drl.indexOf( "$c : CheeseLover( favouriteCheese == \"cheddar\" )" ) == -1 );
View Full Code Here


    }

    @Test
    public void testLimitedEntryAttributes() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        AttributeCol52 attr = new AttributeCol52();
        attr.setAttribute( "salience" );
        dt.getAttributeCols().add( attr );

        dt.setData( upgrader.makeDataLists( new String[][]{
                                                           new String[]{"1", "desc", "100"},
                                                           new String[]{"2", "desc", "200"}
                                                           } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here

    }

    @Test
    public void testLimitedEntryMetadata() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        MetadataCol52 md = new MetadataCol52();
        md.setMetadata( "metadata" );
        dt.getMetadataCols().add( md );

        dt.setData( upgrader.makeDataLists( new String[][]{
                                                           new String[]{"1", "desc", "md1"},
                                                           new String[]{"2", "desc", "md2"}
                                                           } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here

    }

    @Test
    public void testLimitedEntryConditionsNoConstraints() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "p1" );
        p1.setFactType( "Smurf" );
        dt.getConditions().add( p1 );

        // This is a hack consistent with how the Expanded Form decision table
        // works. I wouldn't be too surprised if this changes at some time, but
        // GuidedDTDRLPersistence.marshal does not support empty patterns at
        // present.
        LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
        cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc1.setValue( new DTCellValue52( "y" ) );
        p1.getChildColumns().add( cc1 );

        dt.setData( upgrader.makeDataLists( new Object[][]{
                                                           new Object[]{1l, "desc", true},
                                                           new Object[]{2l, "desc", false}
                                                           } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here

    }

    @Test
    public void testLimitedEntryConditionsConstraints1() {
        GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setTableFormat( TableFormat.LIMITED_ENTRY );
        dt.setTableName( "limited-entry" );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "p1" );
        p1.setFactType( "Smurf" );
        dt.getConditions().add( p1 );

        LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
        cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        cc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
        cc1.setFactField( "name" );
        cc1.setOperator( "==" );
        cc1.setValue( new DTCellValue52( "Pupa" ) );
        p1.getChildColumns().add( cc1 );

        dt.setData( upgrader.makeDataLists( new Object[][]{
                                                           new Object[]{1l, "desc", true},
                                                           new Object[]{2l, "desc", false}
                                                           } ) );

        GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
View Full Code Here

                                     format );

        //Set the Table Format and check-in
        //TODO Is it possible to alter the content and save without checking-in?
        Asset asset = repositoryAssetService.loadRuleAsset( uuid );
        GuidedDecisionTable52 content = (GuidedDecisionTable52) asset.getContent();
        content.setTableFormat( configuration.getTableFormat() );
        asset.setCheckinComment( "Table Format automatically set to [" + configuration.getTableFormat().toString() + "]" );
        repositoryAssetService.checkinVersion( asset );

        return uuid;
    }
View Full Code Here

     */
    public GuidedDecisionTable52 upgrade(GuidedDecisionTable legacyDTModel) {

        assertConditionColumnPatternGrouping( legacyDTModel );

        GuidedDecisionTable52 newDTModel = new GuidedDecisionTable52();

        newDTModel.setTableName( legacyDTModel.tableName );
        newDTModel.setParentName( legacyDTModel.parentName );

        newDTModel.setRowNumberCol( new RowNumberCol52() );
        newDTModel.setDescriptionCol( new DescriptionCol52() );

        //Metadata columns' data-type is implicitly defined in the metadata value. For example
        //a String metadata attribute is: "value", a numerical: 1. No conversion action required
        for ( MetadataCol c : legacyDTModel.getMetadataCols() ) {
            newDTModel.getMetadataCols().add( makeNewColumn( c ) );
        }

        //Attribute columns' data-type is based upon the attribute name
        for ( AttributeCol c : legacyDTModel.attributeCols ) {
            newDTModel.getAttributeCols().add( makeNewColumn( c ) );
        }

        //Legacy decision tables did not have Condition field data-types. Set all Condition
        //fields to a *sensible* default of String (as this matches legacy behaviour).
        Map<String, Pattern52> patterns = new HashMap<String, Pattern52>();
        for ( int i = 0; i < legacyDTModel.conditionCols.size(); i++ ) {
            ConditionCol c = legacyDTModel.conditionCols.get( i );
            String boundName = c.boundName;
            Pattern52 p = patterns.get( boundName );
            if ( p == null ) {
                p = new Pattern52();
                p.setBoundName( boundName );
                p.setFactType( c.factType );
                patterns.put( boundName,
                              p );
            }
            if ( p.getFactType() != null && !p.getFactType().equals( c.factType ) ) {
                throw new IllegalArgumentException( "Inconsistent FactTypes for ConditionCols bound to '" + boundName + "' detected." );
            }
            p.getChildColumns().add( makeNewColumn( c ) );
        }
        for ( Pattern52 p : patterns.values() ) {
            newDTModel.getConditions().add( p );
        }

        //Action columns have a discrete data-type. No conversion action required.
        for ( ActionCol c : legacyDTModel.actionCols ) {
            newDTModel.getActionCols().add( makeNewColumn( c ) );
        }

        //Copy across data
        newDTModel.setData( makeDataLists( legacyDTModel.data ) );

        //Copy the boundName for ActionRetractFactCol into the data of the new Guided Decision Table model
        final int DATA_COLUMN_OFFSET = legacyDTModel.conditionCols.size() + legacyDTModel.getMetadataCols().size() + legacyDTModel.attributeCols.size() + GuidedDecisionTable.INTERNAL_ELEMENTS;
        for ( int iCol = 0; iCol < legacyDTModel.actionCols.size(); iCol++ ) {
            ActionCol lc = legacyDTModel.actionCols.get( iCol );
            if ( lc instanceof ActionRetractFactCol ) {
                String boundName = ((ActionRetractFactCol) lc).boundName;
                for ( List<DTCellValue52> row : newDTModel.getData() ) {
                    row.get( DATA_COLUMN_OFFSET + iCol ).setStringValue( boundName );
                }
            }
        }

View Full Code Here

        return xt.toXML( dt );
    }

    public GuidedDecisionTable52 unmarshal(String xml) {
        if ( xml == null || xml.trim().equals( "" ) ) {
            return new GuidedDecisionTable52();
        }

        //Upgrade DTModel to new class
        Object model = xt.fromXML( xml );
        GuidedDecisionTable52 newDTModel;
        if ( model instanceof GuidedDecisionTable ) {
            GuidedDecisionTable legacyDTModel = (GuidedDecisionTable) model;
            newDTModel = UPGRADER.upgrade( legacyDTModel );
        } else {
            newDTModel = (GuidedDecisionTable52) model;
View Full Code Here

    private DroolsBuildMarker[] parseGDSTFile(IFile file) {
        List markers = new ArrayList();
        try {
            String gdst = convertToString( file.getContents() );
            GuidedDecisionTable52 dt = GuidedDTXMLPersistence.getInstance().unmarshal( gdst );
            String drl = GuidedDTDRLPersistence.getInstance().marshal( dt );

            // TODO pass this through DSL converter in case brl is based on dsl

            DRLInfo drlInfo =
View Full Code Here

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

           GuidedDecisionTable52 dt = new GuidedDecisionTable52();

           Pattern52 p1 = new Pattern52();
           p1.setBoundName( "p" );
           p1.setFactType("Person");

           ConditionCol52 col = new ConditionCol52();
           col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
           col.setFieldType(SuggestionCompletionEngine.TYPE_STRING);
           col.setFactField("hair");
           col.setOperator( "==" );
           p1.getConditions().add( col );

           dt.getConditionPatterns().add( p1 );

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

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

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

TOP

Related Classes of org.drools.ide.common.client.modeldriven.dt52.GuidedDecisionTable52

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.