@Override public void onValueChange( final ValueChangeEvent<String> event ) { String binding = txtBinding.getText(); chosenPatternSelection.setBoundName( binding ); presenter.stateChanged(); validateBinding(); }
@Override public void makeResult( final GuidedDecisionTable52 model ) { //Ensure every Pattern is bound int fi = 1; for ( Pattern52 p : model.getPatterns() ) { if ( !getValidator().isPatternValid( p ) ) { String binding = NEW_FACT_PREFIX + ( fi++ ); p.setBoundName( binding ); while ( !getValidator().isPatternBindingUnique( p ) ) { binding = NEW_FACT_PREFIX + ( fi++ ); p.setBoundName( binding ); } } } }
p1.setBoundName( "p1" ); p1.setFactType( "Person" ); allPatterns.add( p1 );
editingPattern.setBoundName( fn ); editingPattern.setNegated( isPatternNegated );
@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( )" ) ); }
p1.setBoundName( "x" ); p1.setFactType( "Context" );
p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p2.setBoundName( "c2" ); p2.setFactType( "Driver" ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL );
@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 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "$c" ); p1.setFactType( "CheeseLover" );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 );
p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_PREDICATE );