private void createEmptyDecisionTable( final String baseFileName, final Path contextPath, final GuidedDecisionTable52.TableFormat tableFormat ) { final GuidedDecisionTable52 model = new GuidedDecisionTable52(); model.setTableFormat( tableFormat ); model.setTableName( baseFileName ); save( baseFileName, contextPath, model, null ); }
private boolean unique( String header ) { for ( ActionCol52 o : model.getActionCols() ) { if ( o.getHeader().equals( header ) ) { return false; } } return true; }
private void setupColumnsNote() { configureColumnsNote.setVisible( model.getAttributeCols().size() == 0 && model.getConditionsCount() == 0 && model.getActionCols().size() == 0 ); }
private void removeOtherwiseStates( DTColumnConfig52 column ) { int index = this.model.getExpandedColumns().indexOf( column ); for ( List<DTCellValue52> row : this.model.getData() ) { DTCellValue52 dcv = row.get( index ); dcv.setOtherwise( false ); } }
tsdt.getTableName() ); tsdt.getMetadataCols().size() ); tsdt.getAttributeCols().size() ); tsdt.getConditions().size() ); tsdt.getConditionPattern( "z1" ).getBoundName() ); assertEquals( "Driver", tsdt.getConditionPattern( "z1" ).getFactType() ); tsdt.getConditionPattern( "f1" ).getBoundName() ); assertEquals( "Person", tsdt.getConditionPattern( "f1" ).getFactType() ); tsdt.getConditionPattern( "f2" ).getBoundName() ); assertEquals( "Person2", tsdt.getConditionPattern( "f2" ).getFactType() ); tsdt.getConditionPattern( "z1" ).getChildColumns().size() ); tsdt.getConditionPattern( "f1" ).getChildColumns().size() ); tsdt.getConditionPattern( "f2" ).getChildColumns().size() ); tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getConstraintValueType() ); assertEquals( "age", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getFactField() );
@Test public void testLimitedEntryConditionsNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( GuidedDecisionTable52.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( DataUtilities.makeDataLists( new Object[][]{ new Object[]{ 1l, "desc", true }, new Object[]{ 2l, "desc", false } } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); int index = -1; index = drl.indexOf( "Smurf( )" ); assertTrue( index > -1 ); index = drl.indexOf( "Smurf( )", index + 1 ); assertFalse( index > -1 ); }
@Test public void test2Rules() throws Exception { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableName( "michael" ); dt.getAttributeCols().add( attr ); dt.getConditions().add( p1 ); dt.getConditions().add( p2 ); ins.setFactField( "price" ); ins.setType( DataType.TYPE_NUMERIC_INTEGER ); dt.getActionCols().add( ins ); dt.getActionCols().add( ret ); set.setFactField( "goo1" ); set.setType( DataType.TYPE_STRING ); dt.getActionCols().add( set ); set2.setDefaultValue( new DTCellValue52( "whee" ) ); set2.setType( DataType.TYPE_STRING ); dt.getActionCols().add( set2 ); dt.setData( DataUtilities.makeDataLists( new String[][]{ new String[]{ "1", "desc", "42", "33", "michael", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2" }, new String[]{ "2", "desc", "66", "39", "bob", "age * 0.3", "age > 7", "6.60", "", "gooVal1", "whee" }
@Test @SuppressWarnings("serial") public void testNumeric() { final GuidedDecisionTable52 dt = new GuidedDecisionTable52(); final ProjectDefinition pd = ProjectDefinitionBuilder.newProjectDefinitionBuilder() .addFact( "Driver" ) dt.getAttributeCols().add( at ); dt.getAttributeCols().add( at_ ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1_.getChildColumns().add( c1_ ); dt.getConditions().add( p1_ ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p2 ); dt.getActionCols().add( a ); dt.getActionCols().add( a2 ); ins.setFactType( "Driver" ); ins.setFactField( "name" ); dt.getActionCols().add( ins );
GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.getActionCols().add( new ActionInsertFactCol52() ); ActionSetFieldCol52 set = new ActionSetFieldCol52(); set.setFactField( "foo" ); dt.getActionCols().add( set ); dt.getMetadataCols().add( new MetadataCol52() ); dt.getAttributeCols().add( new AttributeCol52() ); dt.getConditions().add( p ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{ "1", "hola" } } ) ); dt.setTableName( "blah" ); assertNotNull( dt_ ); assertEquals( "blah", dt_.getTableName() ); assertEquals( 1, dt_.getMetadataCols().size() ); assertEquals( 1, dt_.getAttributeCols().size() ); assertEquals( 2, dt_.getActionCols().size() ); assertEquals( 1, dt_.getConditions().size() ); assertEquals( 1, dt_.getConditions().get( 0 ).getChildColumns().size() );
for ( int iRow = 0; iRow < model.getData().size(); iRow++ ) { data.addRow(); BaseColumn rowNumberCol = model.getRowNumberCol(); DynamicColumn<BaseColumn> rowNumberColumn = new DynamicColumn<BaseColumn>( rowNumberCol, cellFactory.getCell( rowNumberCol ), BaseColumn descriptionCol = model.getDescriptionCol(); DynamicColumn<BaseColumn> descriptionColumn = new DynamicColumn<BaseColumn>( descriptionCol, cellFactory.getCell( descriptionCol ), for ( MetadataCol52 col : model.getMetadataCols() ) { DynamicColumn<BaseColumn> column = new DynamicColumn<BaseColumn>( col, cellFactory.getCell( col ), for ( AttributeCol52 col : model.getAttributeCols() ) { DynamicColumn<BaseColumn> column = new DynamicColumn<BaseColumn>( col, cellFactory.getCell( col ), for ( CompositeColumn<?> cc : model.getConditions() ) { if ( cc instanceof LimitedEntryBRLConditionColumn ) { LimitedEntryBRLConditionColumn brl = (LimitedEntryBRLConditionColumn) cc; for ( ActionCol52 col : model.getActionCols() ) { if ( col instanceof LimitedEntryBRLActionColumn ) { LimitedEntryBRLActionColumn brl = (LimitedEntryBRLActionColumn) col; AnalysisCol52 analysisCol = model.getAnalysisCol(); DynamicColumn<BaseColumn> analysisColumn = new DynamicColumn<BaseColumn>( analysisCol,
@Test public void testNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "x" ); p1.setFactType( "Context" ); ConditionCol52 c = new ConditionCol52(); c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c ); dt.getConditions().add( p1 ); ActionSetFieldCol52 asf = new ActionSetFieldCol52(); asf.setBoundName( "x" ); asf.setFactField( "age" ); asf.setType( DataType.TYPE_STRING ); dt.getActionCols().add( asf ); String[][] data = new String[][]{ new String[]{ "1", "desc", "y", "old" } }; dt.setData( DataUtilities.makeDataLists( data ) ); String drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertTrue( drl.indexOf( "Context( )" ) > -1 ); assertTrue( drl.indexOf( "x.setAge" ) > drl.indexOf( "Context( )" ) ); assertFalse( drl.indexOf( "update( x );" ) > -1 ); dt.setData( DataUtilities.makeDataLists( new String[][]{ new String[]{ "1", "desc", "", "old" } } ) ); drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertEquals( -1, drl.indexOf( "Context( )" ) ); }
final List<BaseColumn> allColumns = this.model.getExpandedColumns(); final BaseColumn baseColumn = allColumns.get( iBaseColIndex ); final BRLConditionColumn brl = model.getBRLColumn( baseBRLConditionColumn ); final RuleModel rm = new RuleModel(); IPattern[] lhs = new IPattern[ brl.getDefinition().size() ]; final BRLConditionVariableColumn vc = getConditionVariableColumnIndex( brl.getChildColumns(), valueHolder.getValue() ); final int iCol = model.getExpandedColumns().indexOf( vc ); dependentColumnIndexes.add( iCol ); final BRLActionColumn brl = model.getBRLColumn( baseBRLActionColumn ); final RuleModel rm = new RuleModel(); IAction[] rhs = new IAction[ brl.getDefinition().size() ]; final BRLActionVariableColumn vc = getActionVariableColumnIndex( brl.getChildColumns(), valueHolder.getValue() ); final int iCol = model.getExpandedColumns().indexOf( vc ); dependentColumnIndexes.add( iCol ); final Pattern52 basePattern = this.model.getPattern( baseConditionColumn ); for ( ConditionCol52 cc : basePattern.getChildColumns() ) { if ( oracle.isDependentEnum( basePattern.getFactType(), final Pattern52 basePattern = model.getConditionPattern( baseActionColumn.getBoundName() ); final String binding = baseActionColumn.getBoundName(); for ( ActionCol52 ac : this.model.getActionCols() ) { if ( ac instanceof ActionSetFieldCol52 ) {
@Test public void testBackwardsCompatability() throws Exception { String xml = loadResource( "ExistingDecisionTable.xml" ); GuidedDecisionTable52 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_.getConditions().size() ); assertEquals( 1, dt_.getConditions().get( 0 ).getChildColumns().size() ); assertTrue( dt_.getActionCols().get( 1 ) instanceof ActionSetFieldCol52 ); ActionSetFieldCol52 asf = (ActionSetFieldCol52) dt_.getActionCols().get( 1 ); assertEquals( "foo", asf.getFactField() ); assertEquals( false, asf.isUpdate() ); }
@Test public void testPackageNameAndImports() throws Exception { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setPackageName( "org.drools.guvnor.models.guided.dtable.backend" ); dt.getImports().addImport( new Import( "java.lang.String" ) ); dt.setTableName( "michael" ); Pattern52 p1 = new Pattern52(); p1.setBoundName( "f1" ); p1.setFactType( "Driver" ); ConditionCol52 con = new ConditionCol52(); con.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); con.setFactField( "age" ); con.setHeader( "Driver f1 age" ); con.setOperator( "==" ); p1.getChildColumns().add( con ); dt.getConditions().add( p1 ); dt.setData( DataUtilities.makeDataLists( new String[][]{ new String[]{ "1", "desc", "42" } } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); assertTrue( drl.indexOf( "package org.drools.guvnor.models.guided.dtable.backend;" ) == 0 ); assertTrue( drl.indexOf( "import java.lang.String;" ) > 0 ); }
@Test public void testLimitedEntryAttributes() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); AttributeCol52 attr = new AttributeCol52(); attr.setAttribute( "salience" ); dt.getAttributeCols().add( attr ); dt.setData( DataUtilities.makeDataLists( new String[][]{ new String[]{ "1", "desc", "100" }, new String[]{ "2", "desc", "200" } } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); assertTrue( drl.indexOf( "salience 100" ) > -1 ); assertTrue( drl.indexOf( "salience 200" ) > -1 ); }
@Test public void testLimitedEntryMetadata() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( GuidedDecisionTable52.TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); MetadataCol52 md = new MetadataCol52(); md.setMetadata( "metadata" ); dt.getMetadataCols().add( md ); dt.setData( DataUtilities.makeDataLists( new String[][]{ new String[]{ "1", "desc", "md1" }, new String[]{ "2", "desc", "md2" } } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); assertTrue( drl.indexOf( "@metadata(md1)" ) > -1 ); assertTrue( drl.indexOf( "@metadata(md2)" ) > -1 ); }
public void setContent( final NewGuidedDecisionTableAssetWizardContext context, final DataModelOracle oracle, final NewGuidedDecisionTableHandler handler ) { this.context = context; this.model = new GuidedDecisionTable52(); this.model.setTableFormat( context.getTableFormat() ); this.oracle = oracle; this.handler = handler; final Validator validator = new Validator( model.getConditions() ); for ( WizardPage page : pages ) { final AbstractGuidedDecisionTableWizardPage dtp = (AbstractGuidedDecisionTableWizardPage) page; dtp.setContent( context, oracle, model, validator ); dtp.initialise(); } }
@Test public void testOnlyDecisionTableColumns() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setFactType( "Driver" ); p1.setBoundName( "$p1" ); ConditionCol52 c1 = new ConditionCol52(); c1.setFactField( "name" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); c1.setBinding( "$c1" ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ActionInsertFactCol52 ins = new ActionInsertFactCol52(); ins.setBoundName( "$ins" ); ins.setFactField( "rating" ); ins.setFactType( "Person" ); ins.setType( DataType.TYPE_STRING ); dt.getActionCols().add( ins ); BRLRuleModel model = new BRLRuleModel( dt ); assertNotNull( model.getAllVariables() ); assertEquals( 3, model.getAllVariables().size() ); assertTrue( model.getAllVariables().contains( "$p1" ) ); assertTrue( model.getAllVariables().contains( "$c1" ) ); assertTrue( model.getAllVariables().contains( "$ins" ) ); }
/** * Delete the given column from the given pattern * @param modelColumn */ public void deleteColumn( ConditionCol52 modelColumn ) { if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } int index = model.getExpandedColumns().indexOf( modelColumn ); Pattern52 pattern = model.getPattern( modelColumn ); pattern.getChildColumns().remove( modelColumn ); //Remove pattern if it contains zero conditions if ( pattern.getChildColumns().size() == 0 ) { model.getConditions().remove( pattern ); //Signal patterns changed event to Decision Table Widget BoundFactsChangedEvent pce = new BoundFactsChangedEvent( rm.getLHSBoundFacts() ); eventBus.fireEvent( pce ); } deleteColumn( index, true ); //Log deletion of column model.getAuditLog().add( new DeleteColumnAuditLogEntry( identity.getName(), modelColumn ) ); }
/** * Delete the given column * @param modelColumn */ public void deleteColumn( ActionCol52 modelColumn ) { if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } int index = model.getExpandedColumns().indexOf( modelColumn ); model.getActionCols().remove( modelColumn ); deleteColumn( index, true ); //Log deletion of column model.getAuditLog().add( new DeleteColumnAuditLogEntry( identity.getName(), modelColumn ) ); }