public FieldConstraint asFieldConstraint( FactPattern factPattern ) { CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( connector.equals( "&&" ) ? CompositeFieldConstraint.COMPOSITE_TYPE_AND : CompositeFieldConstraint.COMPOSITE_TYPE_OR ); for ( Expr expr : subExprs ) { comp.addConstraint( expr.asFieldConstraint( factPattern ) ); } return comp; } }
private CompositeFieldConstraint visitCompositeFieldConstraint( CompositeFieldConstraint cfc ) { CompositeFieldConstraint clone = new CompositeFieldConstraint(); clone.setCompositeJunctionType( cfc.getCompositeJunctionType() ); if ( cfc.getConstraints() != null ) { clone.setConstraints( new FieldConstraint[ cfc.getConstraints().length ] ); for ( int i = 0; i < cfc.getConstraints().length; i++ ) { FieldConstraint fc = cfc.getConstraints()[ i ]; clone.getConstraints()[ i ] = (FieldConstraint) visit( fc ); } } return clone; }
public FieldConstraint getConstraint( int index ) { if ( this.constraintList == null ) { return null; } return this.constraintList.getConstraint( index ); }
/** * This will add a top level constraint. */ public void addConstraint( final FieldConstraint constraint ) { if ( constraintList == null ) { constraintList = new CompositeFieldConstraint(); } this.constraintList.addConstraint( constraint ); }
/** * This will return the list of field constraints that are in the root * CompositeFieldConstraint object. If there is no root, then an empty array * will be returned. * @return an empty array, or the list of constraints (which may be * composites). */ public FieldConstraint[] getFieldConstraints() { if ( this.constraintList == null ) { return new FieldConstraint[ 0 ]; } return this.constraintList.getConstraints(); }
public void onChange( ChangeEvent event ) { CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( composites.getValue( composites.getSelectedIndex() ) ); fp.addConstraint( comp ); modeller.refreshWidget(); popup.hide(); } } );
buf.append( "( " ); FieldConstraint[] nestedConstraints = cfc.getConstraints(); if ( nestedConstraints != null ) { for ( int i = 0; i < nestedConstraints.length; i++ ) { if ( i < ( nestedConstraints.length - 1 ) ) { buf.append( cfc.getCompositeJunctionType() + " " );
public void setFieldConstraints( final List<FieldConstraint> sortedConstraints ) { if ( sortedConstraints != null ) { if ( this.constraintList != null ) { this.constraintList.setConstraints( new FieldConstraint[ sortedConstraints.size() ] ); for ( int i = 0; i < sortedConstraints.size(); i++ ) { this.constraintList.getConstraints()[ i ] = (FieldConstraint) sortedConstraints.get( i ); } } else if ( sortedConstraints.size() > 0 ) { throw new IllegalStateException( "Cannot have constraints if constraint list is null." ); } } else { this.constraintList.setConstraints( null ); } }
public void removeConstraint( final int idx ) { this.constraintList.removeConstraint( idx ); }
private void visitCompositeFieldConstraint( CompositeFieldConstraint cfc ) { if ( cfc.getConstraints() != null ) { for ( FieldConstraint fc : cfc.getConstraints() ) { visit( fc ); } } }
public void onChange( ChangeEvent event ) { CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( composites.getValue( composites.getSelectedIndex() ) ); hasConstraints.addConstraint( comp ); modeller.refreshWidget(); popup.hide(); } } );
if ( constraint.getCompositeJunctionType().equals( CompositeFieldConstraint.COMPOSITE_TYPE_AND ) ) { desc = Constants.INSTANCE.AllOf() + ":"; } else { 2 ); FieldConstraint[] nested = constraint.getConstraints(); DirtyableFlexTable inner = new DirtyableFlexTable(); if ( nested != null ) {
@Test public void testScopedVariablesWithCompositeFact() { RuleModel m = new RuleModel(); FactPattern p = new FactPattern(); CompositeFieldConstraint cf = new CompositeFieldConstraint(); cf.addConstraint( new SingleFieldConstraint( "x" ) ); p.addConstraint( cf ); SingleFieldConstraint sf = new SingleFieldConstraint( "q" ); sf.setFieldBinding( "abc" ); p.addConstraint( sf ); SingleFieldConstraint sf2 = new SingleFieldConstraint( "q" ); sf2.setFieldBinding( "qed" ); cf.addConstraint( sf2 ); m.addLhsItem( p ); List vars = m.getAllVariables(); assertEquals( 1, vars.size() ); assertEquals( "abc", vars.get( 0 ) ); } /*
public void onClick( ClickEvent event ) { if ( Window.confirm( Constants.INSTANCE.RemoveThisItemFromNestedConstraint() ) ) { setModified( true ); constraint.removeConstraint( currentRow ); getModeller().refreshWidget(); } } } );
CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( CompositeFieldConstraint.COMPOSITE_TYPE_AND ); p.addConstraint( comp ); sfc1.setValue( "gooValue" ); sfc1.setOperator( "==" ); comp.addConstraint( sfc1 ); sfc2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); sfc2.setOperator( "!= null" ); comp.addConstraint( sfc2 ); sfc3.setValue( "barValue" ); sfc3.setOperator( "==" ); comp.addConstraint( sfc3 );
private void generateConstraints( final FactPattern pattern ) { int printedCount = 0; for ( int i = 0; i < pattern.getFieldConstraints().length; i++ ) { StringBuilder buffer = new StringBuilder(); generateConstraint( pattern.getConstraintList().getConstraints()[ i ], false, buffer ); if ( buffer.length() > 0 ) { if ( printedCount > 0 ) { buf.append( ", " ); } buf.append( buffer ); printedCount++; } } }
@Test public void testFieldsDeclaredButNoConstraints() { RuleModel m = new RuleModel(); m.name = "boo"; FactPattern p = new FactPattern( "Person" ); // this isn't an effective constraint, so it should be ignored. p.addConstraint( new SingleFieldConstraint( "field1" ) ); m.addLhsItem( p ); String actual = BRDRLPersistence.getInstance().marshal( m ); String expected = "rule \"boo\" \tdialect \"mvel\"\n when Person() then end"; checkMarshallUnmarshall( expected, m ); SingleFieldConstraint con = (SingleFieldConstraint) p.getConstraintList().getConstraint( 0 ); con.setFieldBinding( "q" ); // now it should appear, as we are binding a var to it expected = "rule \"boo\" dialect \"mvel\" when Person(q : field1) then end"; checkMarshallUnmarshall( expected, m ); }
CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( CompositeFieldConstraint.COMPOSITE_TYPE_OR ); p.addConstraint( comp ); sfc1.setValue( "gooValue" ); sfc1.setOperator( "==" ); comp.addConstraint( sfc1 ); sfc2.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); sfc2.setOperator( "!= null" ); comp.addConstraint( sfc2 ); sfc3.setValue( "barValue" ); sfc3.setOperator( "==" ); comp.addConstraint( sfc3 );
private DropDownData getDropDownData() { //Set applicable flags and reference data depending upon type if ( DataType.TYPE_BOOLEAN.equals( this.fieldType ) ) { this.isDropDownDataEnum = false; this.dropDownData = DropDownData.create( new String[]{ "true", "false" } ); } else { this.isDropDownDataEnum = true; final Map<String, String> currentValueMap = new HashMap<String, String>(); if ( constraintList != null && constraintList.getConstraints() != null ) { for ( FieldConstraint con : constraintList.getConstraints() ) { if ( con instanceof SingleFieldConstraint ) { SingleFieldConstraint sfc = (SingleFieldConstraint) con; String fieldName = sfc.getFieldName(); currentValueMap.put( fieldName, sfc.getValue() ); } } } this.dropDownData = sce.getEnums( this.factType, fieldName, currentValueMap ); } return dropDownData; }
CompositeFieldConstraint comp = new CompositeFieldConstraint(); comp.setCompositeJunctionType( CompositeFieldConstraint.COMPOSITE_TYPE_OR ); p.addConstraint( comp ); X.getConnectives()[ 0 ].setOperator( "|| ==" ); X.getConnectives()[ 0 ].setValue( "bar" ); comp.addConstraint( X ); Y.setValue( "foo" ); Y.setOperator( "==" ); comp.addConstraint( Y ); CompositeFieldConstraint comp2 = new CompositeFieldConstraint(); comp2.setCompositeJunctionType( CompositeFieldConstraint.COMPOSITE_TYPE_AND ); final SingleFieldConstraint Q1 = new SingleFieldConstraint(); Q1.setFieldType( DataType.TYPE_STRING ); Q1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); comp2.addConstraint( Q1 ); Q2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); comp2.addConstraint( Q2 ); comp.addConstraint( comp2 );