Package org.drools.workbench.models.guided.dtable.shared.model

Examples of org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52


        //Create new assets for Guided Decision Tables
        for ( int iCounter = 0; iCounter < dtables.size(); iCounter++ ) {

            //Add imports
            final GuidedDecisionTable52 dtable = dtables.get( iCounter );
            for ( Import item : imports ) {
                dtable.getImports().addImport( new org.drools.workbench.models.commons.shared.imports.Import( item.getClassName() ) );
            }

            //Make new resource
            final String assetName = makeNewAssetName( dtable.getTableName(),
                                                       guidedDTableType );
            guidedDecisionTableService.create( context,
                                               assetName,
                                               dtable,
                                               "Converted from XLS Decision Table" );
View Full Code Here


    @Test
    public void testIndexGuidedDecisionTableActions() throws IOException, InterruptedException {
        //Add test files
        final Path path = basePath.resolve( "dtable1.gdst" );
        final GuidedDecisionTable52 model = GuidedDecisionTableFactory.makeTableWithActionCol( "org.drools.workbench.screens.guided.dtable.backend.server.indexing",
                                                                                               new ArrayList<Import>() {{
                                                                                                   add( new Import( "org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant" ) );
                                                                                               }},
                                                                                               "dtable1" );
        final String xml = GuidedDTXMLPersistence.getInstance().marshal( model );
View Full Code Here

    @Override
    public FormatConversionResult convert( String name,
                                           byte[] input ) {
        String xml = new String( input );
        GuidedDecisionTable52 model = GuidedDTXMLPersistence.getInstance().unmarshal( xml );

        String drl = new StringBuilder().append( GuidedDTDRLPersistence.getInstance().marshal( model ) ).toString();

        return new FormatConversionResult( getDestinationName( name, hasDSLSentences( model ) ), drl.getBytes() );
    }
View Full Code Here

public class GuidedDecisionTableFactory {

    public static GuidedDecisionTable52 makeTableWithAttributeCol( final String packageName,
                                                                   final Collection<Import> imports,
                                                                   final String tableName ) {
        final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setPackageName( packageName );
        dt.getImports().getImports().addAll( imports );
        dt.setTableName( tableName );

        AttributeCol52 attr = new AttributeCol52();
        attr.setAttribute( "ruleflow-group" );
        dt.getAttributeCols().add( attr );

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "myRuleFlowGroup" }
        } ) );

        return dt;
    }
View Full Code Here

    }

    public static GuidedDecisionTable52 makeTableWithConditionCol( final String packageName,
                                                                   final Collection<Import> imports,
                                                                   final String tableName ) {
        final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setPackageName( packageName );
        dt.getImports().getImports().addAll( imports );
        dt.setTableName( tableName );

        Pattern52 p1 = new Pattern52();
        p1.setBoundName( "$a" );
        p1.setFactType( "Applicant" );

        ConditionCol52 con1 = new ConditionCol52();
        con1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con1.setFieldType( DataType.TYPE_NUMERIC_INTEGER );
        con1.setFactField( "age" );
        con1.setHeader( "Applicant age" );
        con1.setOperator( "==" );
        p1.getChildColumns().add( con1 );

        dt.getConditions().add( p1 );

        Pattern52 p2 = new Pattern52();
        p2.setBoundName( "$m" );
        p2.setFactType( "Mortgage" );

        ConditionCol52 con2 = new ConditionCol52();
        con2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
        con2.setFieldType( DataType.TYPE_NUMERIC_INTEGER );
        con2.setFactField( "amount" );
        con2.setHeader( "Mortgage amount" );
        con2.setOperator( "==" );
        p2.getChildColumns().add( con2 );

        dt.getConditions().add( p2 );

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "33", "" }
        } ) );

        return dt;
    }
View Full Code Here

    }

    public static GuidedDecisionTable52 makeTableWithActionCol( final String packageName,
                                                                final Collection<Import> imports,
                                                                final String tableName ) {
        final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setPackageName( packageName );
        dt.getImports().getImports().addAll( imports );
        dt.setTableName( tableName );

        ActionInsertFactCol52 ins = new ActionInsertFactCol52();
        ins.setBoundName( "$i" );
        ins.setFactType( "Applicant" );
        ins.setFactField( "age" );
        ins.setType( DataType.TYPE_NUMERIC_INTEGER );
        dt.getActionCols().add( ins );

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "33" }
        } ) );

        return dt;
    }
View Full Code Here

    }

    public static GuidedDecisionTable52 makeTableWithBRLFragmentConditionCol( final String packageName,
                                                                              final Collection<Import> imports,
                                                                              final String tableName ) {
        final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setPackageName( packageName );
        dt.getImports().getImports().addAll( imports );
        dt.setTableName( tableName );

        final BRLConditionColumn brl = new BRLConditionColumn();

        final FactPattern fp1 = new FactPattern();
        fp1.setFactType( "Applicant" );
        final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
        sfc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE );
        sfc1.setFactType( "Applicant" );
        sfc1.setOperator( "==" );
        sfc1.setFieldName( "age" );
        sfc1.setValue( "f1" );
        fp1.addConstraint( sfc1 );

        final FactPattern fp2 = new FactPattern();
        fp2.setFactType( "Mortgage" );
        final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
        sfc2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE );
        sfc2.setFactType( "Mortgage" );
        sfc2.setOperator( "==" );
        sfc2.setFieldName( "amount" );
        sfc2.setValue( "f2" );
        fp2.addConstraint( sfc2 );

        brl.getDefinition().add( fp1 );
        brl.getDefinition().add( fp2 );
        brl.getChildColumns().add( new BRLConditionVariableColumn( "f1",
                                                                   DataType.TYPE_NUMERIC_INTEGER ) );
        brl.getChildColumns().add( new BRLConditionVariableColumn( "f2",
                                                                   DataType.TYPE_NUMERIC_INTEGER ) );
        dt.getConditions().add( brl );

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "33", "" }
        } ) );

        return dt;
    }
View Full Code Here

    }

    public static GuidedDecisionTable52 makeTableWithBRLFragmentActionCol( final String packageName,
                                                                           final Collection<Import> imports,
                                                                           final String tableName ) {
        final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
        dt.setPackageName( packageName );
        dt.getImports().getImports().addAll( imports );
        dt.setTableName( tableName );

        final BRLActionColumn brl = new BRLActionColumn();

        final ActionInsertFact ifc1 = new ActionInsertFact();
        ifc1.setFactType( "Applicant" );
        ifc1.setBoundName( "$a" );
        final ActionFieldValue afv1 = new ActionFieldValue();
        afv1.setNature( FieldNatureType.TYPE_TEMPLATE );
        afv1.setField( "age" );
        afv1.setValue( "f1" );
        ifc1.addFieldValue( afv1 );

        final ActionInsertFact ifc2 = new ActionInsertFact();
        ifc2.setFactType( "Mortgage" );
        ifc2.setBoundName( "$m" );
        final ActionFieldValue afv2 = new ActionFieldValue();
        afv2.setNature( FieldNatureType.TYPE_TEMPLATE );
        afv2.setField( "amount" );
        afv2.setValue( "f2" );
        ifc2.addFieldValue( afv2 );

        final ActionSetField asf = new ActionSetField();
        asf.setVariable( "$a" );
        asf.addFieldValue( new ActionFieldValue( "age",
                                                 "33",
                                                 DataType.TYPE_NUMERIC_INTEGER ) );

        final ActionUpdateField auf = new ActionUpdateField();
        asf.setVariable( "$m" );
        asf.addFieldValue( new ActionFieldValue( "amount",
                                                 "10000",
                                                 DataType.TYPE_NUMERIC_INTEGER ) );

        brl.getDefinition().add( ifc1 );
        brl.getDefinition().add( ifc2 );
        brl.getChildColumns().add( new BRLActionVariableColumn( "f1",
                                                                DataType.TYPE_NUMERIC_INTEGER ) );
        brl.getChildColumns().add( new BRLActionVariableColumn( "f2",
                                                                DataType.TYPE_NUMERIC_INTEGER ) );
        brl.getDefinition().add( asf );
        brl.getDefinition().add( auf );

        dt.getConditions().add( brl );

        dt.setData( DataUtilities.makeDataLists( new String[][]{
                new String[]{ "1", "desc", "33", "" }
        } ) );

        return dt;
    }
View Full Code Here

    @Test
    public void testIndexGuidedDecisionTableBRLFragmentActions() throws IOException, InterruptedException {
        //Add test files
        final Path path = basePath.resolve( "dtable1.gdst" );
        final GuidedDecisionTable52 model = GuidedDecisionTableFactory.makeTableWithBRLFragmentActionCol( "org.drools.workbench.screens.guided.dtable.backend.server.indexing",
                                                                                                          new ArrayList<Import>() {{
                                                                                                              add( new Import( "org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Applicant" ) );
                                                                                                              add( new Import( "org.drools.workbench.screens.guided.dtable.backend.server.indexing.classes.Mortgage" ) );
                                                                                                          }},
                                                                                                          "dtable1" );
View Full Code Here

     */
    public GuidedDecisionTable52 upgrade( GuidedDecisionTable legacyDTModel ) {

        assertConditionColumnPatternGrouping( legacyDTModel );

        GuidedDecisionTable52 newDTModel = new GuidedDecisionTable52();

        newDTModel.setTableFormat( GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY );

        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
        if ( legacyDTModel.metadataCols != null ) {
            for ( MetadataCol c : legacyDTModel.metadataCols ) {
                newDTModel.getMetadataCols().add( makeNewColumn( c ) );
            }
        }

        //Attribute columns' data-type is based upon the attribute name
        if ( legacyDTModel.attributeCols != null ) {
            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).
        List<Pattern52> patterns = new ArrayList<Pattern52>();
        Map<String, Pattern52> uniquePatterns = new HashMap<String, Pattern52>();
        if ( legacyDTModel.conditionCols != null ) {
            for ( int i = 0; i < legacyDTModel.conditionCols.size(); i++ ) {
                ConditionCol c = legacyDTModel.conditionCols.get( i );
                String boundName = c.boundName;
                Pattern52 p = uniquePatterns.get( boundName );
                if ( p == null ) {
                    p = new Pattern52();
                    p.setBoundName( boundName );
                    p.setFactType( c.factType );
                    patterns.add( p );
                    uniquePatterns.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 ) {
                newDTModel.getConditions().add( p );
            }
        }

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

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

        //Copy the boundName for ActionRetractFactCol into the data of the new Guided Decision Table model
        if ( legacyDTModel.actionCols != null ) {
            final int metaDataColCount = ( legacyDTModel.metadataCols == null ? 0 : legacyDTModel.metadataCols.size() );
            final int attributeColCount = ( legacyDTModel.attributeCols == null ? 0 : legacyDTModel.attributeCols.size() );
            final int conditionColCount = ( legacyDTModel.conditionCols == null ? 0 : legacyDTModel.conditionCols.size() );
            final int DATA_COLUMN_OFFSET = metaDataColCount + attributeColCount + conditionColCount + 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

TOP

Related Classes of org.drools.workbench.models.guided.dtable.shared.model.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.