@Override public void setChosenConditions( final Pattern52 pattern, final List<ConditionCol52> conditions ) { pattern.getChildColumns().clear(); pattern.getChildColumns().addAll( conditions ); }
private void addColumn( final Pattern52 p ) { for ( ConditionCol52 c : p.getChildColumns() ) { addColumn( p, c ); } }
@Override public void makeResult( final GuidedDecisionTable52 model ) { //Copy actions to decision table model. Assertion of bindings occurs in FactPatternsPage for ( Map.Entry<Pattern52, List<ActionSetFieldCol52>> ps : patternToActionsMap.entrySet() ) { final Pattern52 p = ps.getKey(); //Patterns with no conditions don't get created if ( p.getChildColumns().size() > 0 ) { final String binding = p.getBoundName(); for ( ActionSetFieldCol52 a : ps.getValue() ) { a.setBoundName( binding ); model.getActionCols().add( a ); } } } }
public void onDragEnd( DragEndEvent event ) { endIndex = conditionsPanel.getWidgetIndex( event.getContext().draggable ); if ( endIndex == startIndex ) { return; } ConditionCol52 conditionBeingMoved = pattern.getChildColumns().get( startIndex ); dtableWidget.moveCondition( pattern, conditionBeingMoved, endIndex ); }
private boolean canConditionBeDeleted( ConditionCol52 col ) { Pattern52 pattern = model.getPattern( col ); if ( pattern.getChildColumns().size() > 1 ) { return true; } if ( isBindingUsed( pattern.getBoundName() ) ) { return false; } return true; }
private boolean isBindingUnique( String binding ) { for ( Pattern52 p : model.getPatterns() ) { if ( p.getBoundName().equals( binding ) ) { return false; } for ( ConditionCol52 c : p.getChildColumns() ) { if ( c.isBound() ) { if ( c.getBinding().equals( binding ) ) { return false; } } } } return true; }
public Set<String> getBindings( String className ) { //For some reason, Fact Pattern data-types use the leaf name of the fully qualified Class Name //whereas Fields use the fully qualified Class Name. We don't use the generic fieldType (see //SuggestionCompletionEngine.TYPE) as we can't distinguish between different numeric types String simpleClassName = className; if ( simpleClassName != null && simpleClassName.lastIndexOf( "." ) > 0 ) { simpleClassName = simpleClassName.substring( simpleClassName.lastIndexOf( "." ) + 1 ); } Set<String> bindings = new HashSet<String>(); for ( Pattern52 p : this.model.getPatterns() ) { if ( className == null || p.getFactType().equals( simpleClassName ) ) { String binding = p.getBoundName(); if ( !( binding == null || "".equals( binding ) ) ) { bindings.add( binding ); } } for ( ConditionCol52 c : p.getChildColumns() ) { if ( c.isBound() ) { String fieldDataType = oracle.getFieldClassName( p.getFactType(), c.getFactField() ); if ( fieldDataType.equals( className ) ) { bindings.add( c.getBinding() ); } } } } return bindings; }
@Override public boolean isComplete() { //Have all patterns conditions been defined? boolean areConditionsDefined = true; for ( Pattern52 p : model.getPatterns() ) { for ( ConditionCol52 c : p.getChildColumns() ) { if ( !getValidator().isConditionValid( c ) ) { areConditionsDefined = false; break; } } } //Signal Condition definitions to other pages final ConditionsDefinedEvent event = new ConditionsDefinedEvent( areConditionsDefined ); conditionsDefinedEvent.fire( event ); return areConditionsDefined; }
/** * 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 ) ); }
private List<ConditionCol52> findAvailableColumnsToExpand() { final List<ConditionCol52> availableColumns = new ArrayList<ConditionCol52>(); for ( CompositeColumn<?> cc : model.getPatterns() ) { if ( cc instanceof Pattern52 ) { final Pattern52 p = (Pattern52) cc; for ( ConditionCol52 c : p.getChildColumns() ) { switch ( model.getTableFormat() ) { case EXTENDED_ENTRY: if ( modelUtils.hasValueList( c ) ) { final String[] values = modelUtils.getValueList( c ); if ( values != null && values.length > 1 ) { availableColumns.add( c ); } } else if ( oracle.hasEnums( p.getFactType(), c.getFactField() ) ) { availableColumns.add( c ); } break; case LIMITED_ENTRY: availableColumns.add( c ); } } } } return availableColumns; }
/** * 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 ) ); }
protected String getCssStyleName( final Pattern52 p ) { if ( !validator.isPatternBindingUnique( p ) ) { return WizardResources.INSTANCE.css().wizardDTableValidationError(); } for ( final ConditionCol52 c : p.getChildColumns() ) { if ( !validator.isConditionValid( c ) ) { return WizardResources.INSTANCE.css().wizardDTableValidationError(); } } return ""; }
@Override public void selectPattern( final Pattern52 pattern ) { //Pattern is null when programmatically deselecting an item if ( pattern == null ) { return; } //Add Fact fields final String type = pattern.getFactType(); final String[] fieldNames = oracle.getFieldCompletions( type ); final List<AvailableField> availableFields = new ArrayList<AvailableField>(); for ( String fieldName : fieldNames ) { final String fieldType = oracle.getFieldType( type, fieldName ); final String fieldDisplayType = HumanReadableDataTypes.getUserFriendlyTypeName( fieldType ); final AvailableField field = new AvailableField( fieldName, fieldType, fieldDisplayType, BaseSingleFieldConstraint.TYPE_LITERAL ); availableFields.add( field ); } //Add predicates if ( model.getTableFormat() == GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY ) { final AvailableField field = new AvailableField( Constants.INSTANCE.DecisionTableWizardPredicate(), BaseSingleFieldConstraint.TYPE_PREDICATE ); availableFields.add( field ); } view.setAvailableFields( availableFields ); view.setChosenConditions( pattern.getChildColumns() ); }
@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.getChildColumns().add( c ); dt.getConditions().add( p1 );
p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); 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 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 ); }
@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 ); }