private FactPattern visitFactPattern( FactPattern pattern ) { FactPattern clone = new FactPattern(); clone.setBoundName( pattern.getBoundName() ); clone.setFactType( pattern.getFactType() ); clone.setNegated( pattern.isNegated() ); CEPWindow cloneCEPWindow = new CEPWindow(); cloneCEPWindow.setOperator( pattern.getWindow().getOperator() ); cloneCEPWindow.setParameters( cloneCEPWindowParameters( pattern.getWindow() ) ); clone.setWindow( cloneCEPWindow ); for ( FieldConstraint fc : pattern.getFieldConstraints() ) { clone.addConstraint( (FieldConstraint) visit( fc ) ); } return clone; }
private void generateFactPattern( final FactPattern pattern ) { if ( pattern.isNegated() ) { buf.append( "not " ); } else if ( pattern.isBound() ) { bindingsPatterns.put( pattern.getBoundName(), pattern ); buf.append( pattern.getBoundName() ); buf.append( " : " ); } if ( pattern.getFactType() != null ) { buf.append( pattern.getFactType() ); } buf.append( "( " ); // top level constraints if ( pattern.getConstraintList() != null ) { generateConstraints( pattern ); } buf.append( ")" ); //Add CEP window definition CEPWindow window = pattern.getWindow(); if ( window.isDefined() ) { buf.append( " " ); buf.append( window.getOperator() ); buf.append( buildOperatorParameterDRL( window.getParameters() ) ); } }
public ExpressionVariable( FactPattern fact ) { super( fact.getBoundName(), fact.getFactType(), fact.getFactType() ); if ( !fact.isBound() ) { throw new RuntimeException( "the fact is not bounded: " + fact ); } this.fact = fact; }
private boolean canConditionBeDeleted( BRLConditionColumn col ) { for ( IPattern p : col.getDefinition() ) { if ( p instanceof FactPattern ) { FactPattern fp = (FactPattern) p; if ( fp.isBound() ) { if ( isBindingUsed( fp.getBoundName() ) ) { return false; } } } } return true; }
private RuleModel getModelWithNoConstraints() { final RuleModel m = new RuleModel(); m.name = "Complex Rule"; final FactPattern pat = new FactPattern( "Person" ); pat.setBoundName( "p1" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldBinding( "f1" ); con.setFieldName( "age" ); // con.operator = "<"; // con.value = "42"; pat.addConstraint( con ); m.addLhsItem( pat ); return m; }
private RuleModel getCompositeFOL( String type ) { RuleModel m = new RuleModel(); m.name = "or"; CompositeFactPattern cp = new CompositeFactPattern( type ); FactPattern p1 = new FactPattern( "Person" ); SingleFieldConstraint sf1 = new SingleFieldConstraint( "age" ); sf1.setOperator( "==" ); sf1.setValue( "42" ); p1.addConstraint( sf1 ); cp.addFactPattern( p1 ); FactPattern p2 = new FactPattern( "Person" ); SingleFieldConstraint sf2 = new SingleFieldConstraint( "age" ); sf2.setOperator( "==" ); sf2.setValue( "43" ); p2.addConstraint( sf2 ); cp.addFactPattern( p2 ); m.addLhsItem( cp ); return m; }
FactPattern fp1 = new FactPattern( "Driver" ); fp1.setBoundName( "$brl1" ); sfc1.setFieldType( DataType.TYPE_STRING ); fp1.addConstraint( sfc1 ); brlCondition.getDefinition().add( fp1 ); dt.getConditions().add( brlCondition ); FactPattern fp2 = new FactPattern( "Driver" ); fp2.setBoundName( "$brl1" ); sfc2.setFieldType( DataType.TYPE_STRING ); fp2.addConstraint( sfc2 ); model.addLhsItem( fp2 ); assertNotNull( r2 ); assertEquals( "Driver", r2.getFactType() );
( (FactPattern) rm.lhs[ 0 ] ).getFactType() ); assertEquals( "p1", ( (FactPattern) rm.lhs[ 0 ] ).getBoundName() ); ( (FactPattern) rm.lhs[ 1 ] ).getFactType() ); assertEquals( "c", ( (FactPattern) rm.lhs[ 1 ] ).getBoundName() ); person.getConstraintList().getConstraints().length ); SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint( 0 ); assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType() ); cons = (SingleFieldConstraint) person.getConstraint( 1 ); assertEquals( BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType() ); cons = (SingleFieldConstraint) person.getConstraint( 2 ); assertEquals( BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType() ); assertEquals( person.isNegated(), true ); cheese.getConstraintList().getConstraints().length ); cons = (SingleFieldConstraint) cheese.getConstraint( 0 ); assertEquals( "type", cons.getFieldName() );
final FactPattern fp1 = (FactPattern) m.lhs[ 0 ]; assertEquals( "$a", fp1.getBoundName() ); assertEquals( "Applicant", fp1.getFactType() ); final FactPattern fp2 = (FactPattern) m.lhs[ 2 ]; assertEquals( "$b", fp2.getBoundName() ); assertEquals( "Bananna", fp2.getFactType() );
private FactPattern getFactPattern( PatternDescr pattern, Map<String, String> boundParams ) { String type = pattern.getObjectType(); FactPattern factPattern = new FactPattern( type ); parseConstraint( factPattern, pattern.getConstraint() ); if ( pattern.getIdentifier() != null ) { String identifier = pattern.getIdentifier(); factPattern.setBoundName( identifier ); boundParams.put( identifier, type ); } return factPattern; }
FactPattern brl1DefinitionFactPattern1 = new FactPattern( "Smurf" ); brl1DefinitionFactPattern1Constraint1.setOperator( "==" ); brl1DefinitionFactPattern1Constraint1.setValue( "$name" ); brl1DefinitionFactPattern1.addConstraint( brl1DefinitionFactPattern1Constraint1 ); brl1DefinitionFactPattern1Constraint2.setOperator( "==" ); brl1DefinitionFactPattern1Constraint2.setValue( "$age" ); brl1DefinitionFactPattern1.addConstraint( brl1DefinitionFactPattern1Constraint2 ); rm.lhs.length ); assertEquals( "Baddie", ( (FactPattern) rm.lhs[ 0 ] ).getFactType() ); assertEquals( "Smurf", ( (FactPattern) rm.lhs[ 1 ] ).getFactType() ); result0Fp1.getConstraintList().getConstraints().length ); SingleFieldConstraint result0Fp1Con1 = (SingleFieldConstraint) result0Fp1.getConstraint( 0 ); assertEquals( BaseSingleFieldConstraint.TYPE_LITERAL, result0Fp1Con1.getConstraintValueType() ); result0Fp2.getConstraintList().getConstraints().length ); SingleFieldConstraint result0Fp2Con1 = (SingleFieldConstraint) result0Fp2.getConstraint( 0 ); assertEquals( BaseSingleFieldConstraint.TYPE_TEMPLATE, result0Fp2Con1.getConstraintValueType() ); SingleFieldConstraint result0Fp2Con2 = (SingleFieldConstraint) result0Fp2.getConstraint( 1 );
/** * Get the data-type associated with the binding * @param var * @return The data-type, or null if the binding could not be found */ public String getLHSBindingType( final String var ) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[ i ]; if ( pat instanceof FromCompositeFactPattern ) { pat = ( (FromCompositeFactPattern) pat ).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.isBound() && var.equals( p.getBoundName() ) ) { return p.getFactType(); } for ( FieldConstraint fc : p.getFieldConstraints() ) { String type = getFieldBinding( fc, var ); if ( type != null ) { return type; } } } } return null; }
public String getFactType() { if ( this.factPattern == null ) { return null; } return this.factPattern.getFactType(); }
private void addNewFact( String itemText, int position ) { this.model.addLhsItem( new FactPattern( itemText ), position ); }
/** * This returns the pattern label. */ private Widget getPatternLabel( final FactPattern fp ) { ClickHandler click = new ClickHandler() { public void onClick( ClickEvent event ) { popupCreator.showPatternPopup( (Widget) event.getSource(), fp, null, false ); } }; String patternName = ( pattern.isBound() ) ? pattern.getFactType() + " <b>[" + pattern.getBoundName() + "]</b>" : pattern.getFactType(); String desc; if ( isAll0WithLabel ) { desc = Constants.INSTANCE.All0with( patternName ); } else { if ( pattern.getNumberOfConstraints() > 0 ) { desc = Constants.INSTANCE.ThereIsAAn0With( patternName ); } else { desc = Constants.INSTANCE.ThereIsAAn0( patternName ); } desc = anA( desc, patternName ); } return new ClickableLabel( desc, click, !this.readOnly ); }
@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 ); }
final FactPattern fact = (FactPattern) pat; if ( fact.getConstraintList() != null ) { final FieldConstraint[] cons = fact.getConstraintList().getConstraints(); if ( cons != null ) { for ( int k = 0; k < cons.length; k++ ) { if ( fact.isBound() ) { result.add( fact.getBoundName() ); if ( fact.isBound() ) { result.add( fact.getBoundName() );
if ( fact.isBound() ) { result.add( fact.getBoundName() ); for ( int j = 0; j < fact.getFieldConstraints().length; j++ ) { FieldConstraint fc = fact.getFieldConstraints()[ j ]; if ( fc instanceof SingleFieldConstraintEBLeftSide ) { SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) fc;
private void parseConstraint( FactPattern factPattern, ConditionalElementDescr constraint ) { for ( BaseDescr descr : constraint.getDescrs() ) { if ( descr instanceof ExprConstraintDescr ) { ExprConstraintDescr exprConstraint = (ExprConstraintDescr) descr; Expr expr = parseExpr( exprConstraint.getExpression() ); factPattern.addConstraint( expr.asFieldConstraint( factPattern ) ); } } }
/** * This will return the FactPattern that a variable is bound Eto. * @param var The bound fact variable (NOT bound field). * @return null or the FactPattern found. */ public FactPattern getLHSBoundFact( final String var ) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[ i ]; if ( pat instanceof FromCompositeFactPattern ) { pat = ( (FromCompositeFactPattern) pat ).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }