( (SingleFieldConstraint) con ).setFieldType( type ); } else if ( con instanceof ConnectiveConstraint ) { ( (ConnectiveConstraint) con ).setFieldType( type );
private ConnectiveConstraint visitConnectiveConstraint( ConnectiveConstraint cc ) { ConnectiveConstraint clone = new ConnectiveConstraint(); clone.setConstraintValueType( cc.getConstraintValueType() ); clone.setExpressionValue( (ExpressionFormLine) visit( cc.getExpressionValue() ) ); clone.setFieldName( cc.getFieldName() ); clone.setFieldType( cc.getFieldType() ); clone.setOperator( cc.getOperator() ); for ( Map.Entry<String, String> entry : cc.getParameters().entrySet() ) { clone.setParameter( entry.getKey(), entry.getValue() ); } clone.setValue( cc.getValue() ); return clone; }
@Test public void testConnective() { RuleModel m = new RuleModel(); m.name = "test literal strings"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldType( DataType.TYPE_STRING ); con.setFieldName( "field1" ); con.setOperator( "==" ); con.setValue( "goo" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_VARIABLE ); p.addConstraint( con ); ConnectiveConstraint connective = new ConnectiveConstraint(); connective.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); connective.setFieldType( DataType.TYPE_STRING ); connective.setOperator( "|| ==" ); connective.setValue( "blah" ); con.setConnectives( new ConnectiveConstraint[ 1 ] ); con.getConnectives()[ 0 ] = connective; m.addLhsItem( p ); String expected = "rule \"test literal strings\" " + "\tdialect \"mvel\"\n when " + "Person( field1 == goo || == \"blah\" )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
X.getConnectives()[ 0 ] = new ConnectiveConstraint(); X.getConnectives()[ 0 ].setConstraintValueType( ConnectiveConstraint.TYPE_LITERAL ); X.getConnectives()[ 0 ].setFieldType( DataType.TYPE_STRING ); X.getConnectives()[ 0 ].setOperator( "|| ==" ); X.getConnectives()[ 0 ].setValue( "bar" );