private void addNewFact( String itemText, int position ) { this.model.addLhsItem( new FactPattern( itemText ), position ); }
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; }
public void onChange( ChangeEvent event ) { pattern.setFactPattern( new FactPattern( box.getItemText( box.getSelectedIndex() ) ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
public void onChange( ChangeEvent event ) { pattern.addFactPattern( new FactPattern( box.getItemText( box.getSelectedIndex() ) ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
public void onChange( ChangeEvent event ) { pattern.setFactPattern( new FactPattern( box.getItemText( box.getSelectedIndex() ) ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
public void onChange( ChangeEvent event ) { getFromCollectPattern().setRightPattern( new FactPattern( box.getItemText( box.getSelectedIndex() ) ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
public void onChange( ChangeEvent event ) { getFromAccumulatePattern().setSourcePattern( new FactPattern( box.getItemText( box.getSelectedIndex() ) ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
public void onChange( ChangeEvent event ) { pattern.setFactPattern( new FactPattern( box.getValue( box.getSelectedIndex() ) ) ); setModified( true ); getModeller().refreshWidget(); popup.hide(); } } );
@Test public void testGetVariableNameForRHS() { RuleModel m = new RuleModel(); m.name = "blah"; FactPattern pat = new FactPattern( "Person" ); pat.setBoundName( "pat" ); m.addLhsItem( pat ); List l = m.getAllVariables(); assertEquals( 1, l.size() ); assertEquals( "pat", l.get( 0 ) ); }
@Test public void testInsertLogical() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsertLogical( new Report() );\nend\n"; final RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertLogicalFact( "Report" ) ); m.name = "my rule"; checkMarshallUnmarshall( expected, m ); }
@Test public void testAddItemLhs() { final RuleModel model = new RuleModel(); final FactPattern x = new FactPattern(); model.addLhsItem( x ); assertEquals( 1, model.lhs.length ); final FactPattern y = new FactPattern(); model.addLhsItem( y ); assertEquals( 2, model.lhs.length ); assertEquals( x, model.lhs[0] ); assertEquals( y, model.lhs[1] ); }
@Test public void testBasics() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\nend\n"; RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertFact( "Report" ) ); m.name = "my rule"; checkMarshallUnmarshall( expected, m ); }
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; }
@Test public void textIsNotNullOperator() { final RuleModel m = new RuleModel(); m.name = "IsNotNullOperator"; final FactPattern pat = new FactPattern( "Person" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldName( "age" ); con.setOperator( "!= null" ); pat.addConstraint( con ); m.addLhsItem( pat ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "Person( age != null )" ) != -1 ); checkMarshallUnmarshall( s, m ); }
@Test public void textIsNullOperator() { final RuleModel m = new RuleModel(); m.name = "IsNullOperator"; final FactPattern pat = new FactPattern( "Person" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldName( "age" ); con.setOperator( "== null" ); pat.addConstraint( con ); m.addLhsItem( pat ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "Person( age == null )" ) != -1 ); checkMarshallUnmarshall( s, m ); }
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; }
@Test public void testPredicateConstraint() { RuleModel m = new RuleModel(); m.name = "yeah"; FactPattern p = new FactPattern( "Goober" ); SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType( SingleFieldConstraint.TYPE_PREDICATE ); con.setValue( "field soundslike \"poo\"" ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"yeah\" " + "\tdialect \"mvel\"\n when " + "Goober( eval( field soundslike \"poo\" ) )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testSingleExists() throws Exception { RuleModel m = new RuleModel(); m.name = "or"; CompositeFactPattern cp = new CompositeFactPattern( CompositeFactPattern.COMPOSITE_TYPE_EXISTS ); FactPattern p1 = new FactPattern( "Person" ); SingleFieldConstraint sf1 = new SingleFieldConstraint( "age" ); sf1.setOperator( "==" ); sf1.setValue( "42" ); p1.addConstraint( sf1 ); cp.addFactPattern( p1 ); m.addLhsItem( cp ); String result = BRDRLPersistence.getInstance().marshal( m ); assertTrue( result.indexOf( "exists (Person( age == 42 )) " ) > 0 ); checkMarshallUnmarshall( result, m ); }
@Test public void testReturnValueConstraint() { RuleModel m = new RuleModel(); m.name = "yeah"; FactPattern p = new FactPattern( "Goober" ); SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType( SingleFieldConstraint.TYPE_RET_VALUE ); con.setValue( "someFunc(x)" ); con.setOperator( "==" ); con.setFieldName( "goo" ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"yeah\" " + "\tdialect \"mvel\"\n when " + "Goober( goo == ( someFunc(x) ) )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@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 ); }