@Override public void setConditionPatterns( final List<Pattern52> patterns ) { model.getConditions().clear(); model.getConditions().addAll( patterns ); }
protected boolean isHeaderUnique( String header ) { for ( CompositeColumn<?> cc : model.getConditions() ) { for ( int iChild = 0; iChild < cc.getChildColumns().size(); iChild++ ) { if ( cc.getChildColumns().get( iChild ).getHeader().equals( header ) ) { return false; } } } return true; }
protected boolean isHeaderUnique( String header ) { for ( CompositeColumn<?> cc : model.getConditions() ) { for ( int iChild = 0; iChild < cc.getChildColumns().size(); iChild++ ) { if ( cc.getChildColumns().get( iChild ).getHeader().equals( header ) ) { return false; } } } return true; }
private boolean unique( String header ) { for ( CompositeColumn<?> cc : model.getConditions() ) { for ( int iChild = 0; iChild < cc.getChildColumns().size(); iChild++ ) { if ( cc.getChildColumns().get( iChild ).getHeader().equals( header ) ) { return false; } } } return true; }
public void onDragEnd( DragEndEvent event ) { endIndex = patternsPanel.getWidgetIndex( event.getContext().draggable ); if ( endIndex == startIndex ) { return; } CompositeColumn<?> column = dtableModel.getConditions().get( startIndex ); dtableWidget.movePattern( column, endIndex ); }
/** * Delete the given column * @param modelColumn */ public void deleteColumn( LimitedEntryBRLConditionColumn modelColumn ) { if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } int index = model.getExpandedColumns().indexOf( modelColumn ); model.getConditions().remove( modelColumn ); deleteColumn( index, true ); //Log deletion of column model.getAuditLog().add( new DeleteColumnAuditLogEntry( identity.getName(), modelColumn ) ); }
/** * Add a column to the table. * @param modelColumn The Decision Table column to insert */ public void addColumn( BRLConditionColumn modelColumn ) { if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } model.getConditions().add( modelColumn ); addBRLConditionVariableColumns( modelColumn.getChildColumns(), true ); //Log addition of column model.getAuditLog().add( new InsertColumnAuditLogEntry( identity.getName(), modelColumn ) ); }
/** * Delete the given column * @param modelColumn */ public void deleteColumn( BRLConditionColumn modelColumn ) { if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } BRLConditionVariableColumn firstColumn = modelColumn.getChildColumns().get( 0 ); int firstColumnIndex = model.getExpandedColumns().indexOf( firstColumn ); int numberOfColumns = modelColumn.getChildColumns().size(); deleteColumns( firstColumnIndex, numberOfColumns, true ); model.getConditions().remove( modelColumn ); //Log deletion of column model.getAuditLog().add( new DeleteColumnAuditLogEntry( identity.getName(), modelColumn ) ); }
/** * Add a column to the table. * @param modelColumn The Decision Table column to insert */ public void addColumn( LimitedEntryBRLConditionColumn modelColumn ) { if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } model.getConditions().add( modelColumn ); addColumn( modelColumn, cellValueFactory.makeColumnData( modelColumn ), true ); //Log addition of column model.getAuditLog().add( new InsertColumnAuditLogEntry( identity.getName(), modelColumn ) ); }
/** * Add a column to the table. * @param pattern The Pattern to which the column will be added * @param modelColumn The Decision Table column to insert */ public void addColumn( Pattern52 pattern, ConditionCol52 modelColumn ) { if ( pattern == null ) { throw new IllegalArgumentException( "pattern cannot be null." ); } if ( modelColumn == null ) { throw new IllegalArgumentException( "modelColumn cannot be null." ); } //Add pattern if it does not already exist if ( !model.getConditions().contains( pattern ) ) { model.getConditions().add( pattern ); //Signal patterns changed event BoundFactsChangedEvent pce = new BoundFactsChangedEvent( rm.getLHSBoundFacts() ); eventBus.fireEvent( pce ); } //Column needs to be added to pattern first so it can be correctly positioned pattern.getChildColumns().add( modelColumn ); addColumn( modelColumn, cellValueFactory.makeColumnData( modelColumn ), true ); //Log addition of column model.getAuditLog().add( new InsertColumnAuditLogEntry( identity.getName(), modelColumn ) ); }
/** * 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 ) ); }
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 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 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( )" ) ); }
c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); c2.setValueList( "a,b,c" ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p1 );
@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" ) ); }
@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 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 testLimitedEntryConditionsConstraints1() { 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 ); LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setFieldType( DataType.TYPE_STRING ); cc1.setFactField( "name" ); cc1.setOperator( "==" ); cc1.setValue( new DTCellValue52( "Pupa" ) ); 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( name == \"Pupa\" )" ); assertTrue( index > -1 ); index = drl.indexOf( "Smurf( name == \"Pupa\" )", index + 1 ); assertFalse( index > -1 ); }
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );