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

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


        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 = upgrader1.upgrade( legacyDTModel );
        } else {
            newDTModel = (GuidedDecisionTable52) model;
View Full Code Here


     * @param source
     * @return The new DTModel
     */
    public GuidedDecisionTable52 upgrade( GuidedDecisionTable52 source ) {

        final GuidedDecisionTable52 destination = source;

        //These are the columns we want to update
        final int iRowNumberColumnIndex = 0;
        Integer iSalienceColumnIndex = null;
        Integer iDurationColumnIndex = null;

        //Find the Salience and Duration column indexes
        List<BaseColumn> allColumns = destination.getExpandedColumns();
        for ( int iCol = 0; iCol < allColumns.size(); iCol++ ) {
            final BaseColumn column = allColumns.get( iCol );
            if ( column instanceof AttributeCol52 ) {
                AttributeCol52 attributeCol = (AttributeCol52) column;
                final String attributeName = attributeCol.getAttribute();
                if ( GuidedDecisionTable52.SALIENCE_ATTR.equals( attributeName ) ) {
                    iSalienceColumnIndex = iCol;
                } else if ( GuidedDecisionTable52.DURATION_ATTR.equals( attributeName ) ) {
                    iDurationColumnIndex = iCol;
                }
            }
        }

        //Update data-types
        for ( List<DTCellValue52> row : destination.getData() ) {

            //Row numbers are Integers
            final int rowNumberValue = row.get( iRowNumberColumnIndex ).getNumericValue().intValue();
            row.get( iRowNumberColumnIndex ).setNumericValue( rowNumberValue );

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

    @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

     * @param source
     * @return The new DTModel
     */
    public GuidedDecisionTable52 upgrade( GuidedDecisionTable52 source ) {

        final GuidedDecisionTable52 destination = source;

        for ( BaseColumn column : source.getExpandedColumns() ) {
            DTColumnConfig52 dtColumn = null;
            if ( column instanceof MetadataCol52 ) {
                dtColumn = (DTColumnConfig52) column;
View Full Code Here

public class GuidedDecisionTableConverter extends BaseConverter {

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

        String drl = new StringBuilder()
                .append( getPackageDeclaration(name) )
                .append( model.getImports().toString() ).append( "\n" )
                .append( GuidedDTDRLPersistence.getInstance().marshal(model) ).toString();

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

TOP

Related Classes of org.drools.guvnor.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.