private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) { sfc.setFactType( fp.getFactType() ); sfc.setFieldName( fixFieldName( sfc.getFieldName() ) ); if ( sfc.connectives == null ) { return; } for ( ConnectiveConstraint cc : sfc.connectives ) { cc.setFactType( fp.getFactType() ); cc.setFieldName( fixFieldName( cc.getFieldName() ) ); } }
private void fixConstraints(FactPattern fp, SingleFieldConstraint sfc) { sfc.setFactType( fp.getFactType() ); sfc.setFieldName( fixFieldName( sfc.getFieldName() ) ); if ( sfc.connectives == null ) { return; } for ( ConnectiveConstraint cc : sfc.connectives ) { cc.setFactType( fp.getFactType() ); cc.setFieldName( fixFieldName( cc.getFieldName() ) ); } }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType( sfc.getConstraintValueType() ); clone.setExpressionValue( (ExpressionFormLine) visit( sfc.getExpressionValue() ) ); clone.setFieldBinding( sfc.getFieldBinding() ); clone.setFactType( sfc.getFactType() ); clone.setFieldName( sfc.getFieldName() ); clone.setFieldType( sfc.getFieldType() ); clone.setOperator( sfc.getOperator() ); for ( Map.Entry<String, String> entry : sfc.getParameters().entrySet() ) { clone.setParameter( entry.getKey(), entry.getValue() ); } clone.setValue( sfc.getValue() ); if ( sfc.connectives != null ) { clone.connectives = new ConnectiveConstraint[sfc.connectives.length]; for ( int i = 0; i < sfc.connectives.length; i++ ) { clone.connectives[i] = (ConnectiveConstraint) visit( sfc.connectives[i] ); } } return clone; }
private SingleFieldConstraint visitSingleFieldConstraint(SingleFieldConstraint sfc) { SingleFieldConstraint clone = new SingleFieldConstraint(); clone.setConstraintValueType( sfc.getConstraintValueType() ); clone.setExpressionValue( (ExpressionFormLine) visit( sfc.getExpressionValue() ) ); clone.setFieldBinding( sfc.getFieldBinding() ); clone.setFactType( sfc.getFactType() ); clone.setFieldName( sfc.getFieldName() ); clone.setFieldType( sfc.getFieldType() ); clone.setOperator( sfc.getOperator() ); for ( Map.Entry<String, String> entry : sfc.getParameters().entrySet() ) { clone.setParameter( entry.getKey(), entry.getValue() ); } clone.setValue( sfc.getValue() ); if ( sfc.connectives != null ) { clone.connectives = new ConnectiveConstraint[sfc.connectives.length]; for ( int i = 0; i < sfc.connectives.length; i++ ) { clone.connectives[i] = (ConnectiveConstraint) visit( sfc.connectives[i] ); } } return clone; }
sfc1.setFieldBinding( "$sfc1" ); sfc1.setOperator( "==" ); sfc1.setFactType( "Driver" ); sfc1.setFieldName( "name" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFactType( "Goober" ); sfc1.setFieldName( "gooField" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc2.setFactType( "Goober" ); sfc2.setFieldName( "fooField" ); sfc2.setFieldType( SuggestionCompletionEngine.TYPE_OBJECT ); sfc3.setFactType( "Bar" ); sfc3.setFieldName( "barField" ); sfc3.setParent( sfc2 ); sfc4.setFactType( "Goober" ); sfc4.setFieldName( "zooField" ); sfc4.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFactType( "Goober" ); sfc1.setFieldName( "gooField" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc2.setFactType( "Goober" ); sfc2.setFieldName( "fooField" ); sfc2.setFieldType( SuggestionCompletionEngine.TYPE_OBJECT ); sfc1.setFactType( "Bar" ); sfc3.setFieldName( "barField" ); sfc3.setParent( sfc2 ); sfc4.setFactType( "Goober" ); sfc4.setFieldName( "zooField" ); sfc4.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFactType( "Goober" ); sfc1.setFieldName( "gooField" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc2.setFactType( "Goober" ); sfc2.setFieldName( "fooField" ); sfc2.setFieldType( SuggestionCompletionEngine.TYPE_OBJECT ); sfc3.setFactType( "Bar" ); sfc3.setFieldName( "barField" ); sfc3.setParent( sfc2 );
sfc1.setFieldBinding( "$sfc1" ); sfc1.setOperator( "==" ); sfc1.setFactType( "Driver" ); sfc1.setFieldName( "name" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFactType( "Goober" ); sfc1.setFieldName( "gooField" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc2.setFactType( "Goober" ); sfc2.setFieldName( "fooField" ); sfc2.setFieldType( SuggestionCompletionEngine.TYPE_OBJECT ); sfc3.setFactType( "Bar" ); sfc3.setFieldName( "barField" ); sfc3.setParent( sfc2 );
sfc0p0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); sfc0p0.setFieldBinding( "$sfc0p0" ); sfc0p0.setFactType( "FT0" ); sfc0p0.setFieldName( "sfc0p0" ); sfc0p0.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc1p0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); sfc1p0.setFieldBinding( "$sfc1p0" ); sfc1p0.setFactType( "FT0" ); sfc1p0.setFieldName( "sfc1p0" ); sfc1p0.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc0p1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); sfc0p1.setFieldBinding( "$sfc0p1" ); sfc0p1.setFactType( "FT1" ); sfc0p1.setFieldName( "sfc0p1" ); sfc0p1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc1p1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); sfc1p1.setFieldBinding( "$sfc1p1" ); sfc1p1.setFactType( "FT1" ); sfc1p1.setFieldName( "sfc1p1" ); sfc1p1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFieldBinding( "$sfc1" ); sfc1.setOperator( "==" ); sfc1.setFactType( "Driver" ); sfc1.setFieldName( "name" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFieldBinding( "$sfc1" ); sfc1.setOperator( "==" ); sfc1.setFactType( "Driver" ); sfc1.setFieldName( "name" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); sfc2.setFieldBinding( "$sfc1" ); sfc2.setOperator( "==" ); sfc2.setFactType( "Driver" ); sfc2.setFieldName( "name" ); sfc2.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
sfc1.setFieldBinding( "$sfc1" ); sfc1.setOperator( "==" ); sfc1.setFactType( "Driver" ); sfc1.setFieldName( "name" ); sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
fp0sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); fp0sfc0.setFieldBinding( "$fp0sfc0" ); fp0sfc0.setFactType( "FT0" ); fp0sfc0.setFieldName( "fp0sfc0" ); fp0sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); fp0sfc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); fp0sfc1.setFieldBinding( "$fp0sfc1" ); fp0sfc1.setFactType( "FT0" ); fp0sfc1.setFieldName( "fp0sfc1" ); fp0sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); fp1sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); fp1sfc0.setFieldBinding( "$fp1sfc0" ); fp1sfc0.setFactType( "FT1" ); fp1sfc0.setFieldName( "fp1sfc0" ); fp1sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
fp0sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); fp0sfc0.setFieldBinding( "$fp0sfc0" ); fp0sfc0.setFactType( "FT0" ); fp0sfc0.setFieldName( "fp0sfc0" ); fp0sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); fp0sfc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); fp0sfc1.setFieldBinding( "$fp0sfc1" ); fp0sfc1.setFactType( "FT0" ); fp0sfc1.setFieldName( "fp0sfc1" ); fp0sfc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); fp1sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_TEMPLATE ); fp1sfc0.setFieldBinding( "$fp1sfc0" ); fp1sfc0.setFactType( "FT1" ); fp1sfc0.setFieldName( "fp1sfc0" ); fp1sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );
@Test public void testFromCollectWithEmbeddedFromEntryPoint() { RuleModel m = new RuleModel(); m.name = "r1"; SingleFieldConstraint sfc = new SingleFieldConstraint( "bar" ); sfc.setFactType( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ); sfc.setFieldBinding( "$a" ); sfc.setOperator( "==" ); sfc.setValue( "777" ); FactPattern fp = new FactPattern( "Foo" ); fp.addConstraint( sfc ); FromEntryPointFactPattern fep = new FromEntryPointFactPattern(); fep.setEntryPointName( "ep" ); fep.setFactPattern( fp ); FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern(); fac.setRightPattern( fep ); fac.setFactPattern( new FactPattern( "java.util.List" ) ); m.addLhsItem( fac ); String actual = BRDRLPersistence.getInstance().marshal( m ); String expected = "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( ) from collect ( Foo( $a : bar == 777 ) from entry-point \"ep\" ) \n" + "then\n" + "end"; assertEqualsIgnoreWhitespace( expected, actual ); }
@Test public void testFromAccumulateWithEmbeddedFromEntryPoint() { RuleModel m = new RuleModel(); m.name = "r1"; SingleFieldConstraint sfc = new SingleFieldConstraint( "bar" ); sfc.setFactType( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ); sfc.setFieldBinding( "$a" ); sfc.setOperator( "==" ); sfc.setValue( "777" ); FactPattern fp = new FactPattern( "Foo" ); fp.addConstraint( sfc ); FromEntryPointFactPattern fep = new FromEntryPointFactPattern(); fep.setEntryPointName( "ep" ); fep.setFactPattern( fp ); FromAccumulateCompositeFactPattern fac = new FromAccumulateCompositeFactPattern(); fac.setSourcePattern( fep ); fac.setFactPattern( new FactPattern( "java.util.List" ) ); fac.setFunction( "max($a)" ); m.addLhsItem( fac ); String actual = BRDRLPersistence.getInstance().marshal( m ); String expected = "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "java.util.List( ) from accumulate ( Foo( $a : bar == 777 ) from entry-point \"ep\", \n" + "max($a))\n" + "then\n" + "end"; assertEqualsIgnoreWhitespace( expected, actual ); }
private RuleModel getComplexModel() { final RuleModel m = new RuleModel(); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); final FactPattern pat = new FactPattern( "Person" ); pat.setBoundName( "p1" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFactType( "Person" ); con.setFieldBinding( "f1" ); con.setFieldName( "age" ); con.setOperator( "<" ); con.setValue( "42" ); pat.addConstraint( con ); m.addLhsItem( pat ); final CompositeFactPattern comp = new CompositeFactPattern( "not" ); comp.addFactPattern( new FactPattern( "Cancel" ) ); m.addLhsItem( comp ); final ActionUpdateField set = new ActionUpdateField(); set.variable = "p1"; set.addFieldValue( new ActionFieldValue( "status", "rejected", SuggestionCompletionEngine.TYPE_STRING ) ); m.addRhsItem( set ); final ActionRetractFact ret = new ActionRetractFact( "p1" ); m.addRhsItem( ret ); final DSLSentence sen = new DSLSentence(); sen.setDefinition( "Send an email to {administrator}" ); m.addRhsItem( sen ); return m; }
sfc0.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); sfc0.setFieldBinding( "$sfc0" ); sfc0.setFactType( "FT0" ); sfc0.setFieldName( "sfc0" ); sfc0.setFieldType( SuggestionCompletionEngine.TYPE_STRING );