*/
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 );
}
}
}