@Override public void setFieldBinding( String fieldBinding ) { getExpressionLeftSide().setBinding( fieldBinding ); }
@Override public String getFieldName() { return getExpressionLeftSide().getFieldName(); }
@Override public String getFieldType() { return getExpressionLeftSide().getClassType(); }
@Override public String getFieldBinding() { return getExpressionLeftSide().getBinding(); }
private FieldConstraint asExpressionBuilderConstraint( FactPattern factPattern, String fieldName, String operator, String value ) { SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); fieldName = setFieldBindingOnContraint( fieldName, con ); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( factPattern ) ); String type = setOperatorAndValueOnConstraint( operator, value, con ); String[] splits = fieldName.split( "\\." ); for ( int i = 0; i < splits.length - 1; i++ ) { con.getExpressionLeftSide().appendPart( new ExpressionField( splits[ i ].trim(), "", DataType.TYPE_OBJECT ) ); } con.getExpressionLeftSide().appendPart( new ExpressionField( splits[ splits.length - 1 ].trim(), "", type ) ); return con; }
/** * This adds a new connective. */ @Override public void addNewConnective() { String factType = getExpressionLeftSide().getPreviousGenericType(); if ( factType == null ) { factType = getExpressionLeftSide().getGenericType(); } String fieldName = getExpressionLeftSide().getFieldName(); String fieldType = getExpressionLeftSide().getGenericType(); if ( this.getConnectives() == null ) { this.setConnectives( new ConnectiveConstraint[]{ new ConnectiveConstraint( factType, fieldName, fieldType ) } ); } else { final ConnectiveConstraint[] newList = new ConnectiveConstraint[ this.getConnectives().length + 1 ]; for ( int i = 0; i < this.getConnectives().length; i++ ) { newList[ i ] = this.getConnectives()[ i ]; } newList[ this.getConnectives().length ] = new ConnectiveConstraint( factType, fieldName, fieldType ); this.setConnectives( newList ); } }
private HorizontalPanel expressionBuilderLS( final SingleFieldConstraintEBLeftSide con, boolean showBinding, int padding ) { HorizontalPanel ab = new HorizontalPanel(); ab.setStyleName( "modeller-field-Label" ); if ( !con.isBound() ) { if ( bindable && showBinding && !this.readOnly ) { ab.add( new ExpressionBuilder( getModeller(), getEventBus(), con.getExpressionLeftSide() ) ); } else { ab.add( new SmallLabel( con.getExpressionLeftSide().getText() ) ); } } else { ab.add( new ExpressionBuilder( getModeller(), getEventBus(), con.getExpressionLeftSide() ) ); } return ab; }
protected String getFieldBinding( FieldConstraint fc, String var ) { String fieldType = null; if ( fc instanceof SingleFieldConstraint ) { SingleFieldConstraint s = (SingleFieldConstraint) fc; if ( s.isBound() && var.equals( s.getFieldBinding() ) ) { fieldType = s.getFieldType(); } } if ( fc instanceof SingleFieldConstraintEBLeftSide ) { SingleFieldConstraintEBLeftSide s = (SingleFieldConstraintEBLeftSide) fc; if ( s.isBound() && var.equals( s.getFieldBinding() ) ) { fieldType = s.getExpressionLeftSide().getGenericType(); } } if ( fc instanceof CompositeFieldConstraint ) { CompositeFieldConstraint s = (CompositeFieldConstraint) fc; if ( s.getConstraints() != null ) { for ( FieldConstraint ss : s.getConstraints() ) { fieldType = getFieldBinding( ss, var ); } } } return fieldType; }
@Test public void testLHSExpressionNestedJavaEnum() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedJavaEnum"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", DataType.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "genericName", "CHEESE", DataType.TYPE_COMPARABLE ) ); con.setOperator( "==" ); con.setValue( "CHEESE.Cheddar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsNestedJavaEnum\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.genericName == CHEESE.Cheddar )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionNestedBoolean() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedBoolean"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", DataType.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "smelly", "java.lang.Boolean", DataType.TYPE_BOOLEAN ) ); con.setOperator( "==" ); con.setValue( "true" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsNestedBoolean\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.smelly == true )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionNestedString() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedString"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", DataType.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "name", "java.lang.String", DataType.TYPE_STRING ) ); con.setOperator( "==" ); con.setValue( "Cheedar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsNestedString\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.name == \"Cheedar\" )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionNestedDate() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedDate"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", DataType.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "dateBrought", "java.util.Date", DataType.TYPE_DATE ) ); con.setOperator( "==" ); con.setValue( "27-Jun-2011" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsNestedDate\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.dateBrought == \"27-Jun-2011\" )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionNestedNumber() { RuleModel m = new RuleModel(); m.name = "test expressionsNestedNumber"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "favouriteCheese", "Cheese", DataType.TYPE_OBJECT ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "age", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER ) ); con.setOperator( "==" ); con.setValue( "55" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsNestedNumber\"" + "\tdialect \"mvel\"\n when " + " Person( favouriteCheese.age == 55 )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
private SingleFieldConstraintEBLeftSide visitSingleFieldConstraint( SingleFieldConstraintEBLeftSide sfexp ) { SingleFieldConstraintEBLeftSide clone = new SingleFieldConstraintEBLeftSide(); clone.setConstraintValueType( sfexp.getConstraintValueType() ); clone.setExpressionLeftSide( (ExpressionFormLine) visit( sfexp.getExpressionLeftSide() ) ); clone.setExpressionValue( (ExpressionFormLine) visit( sfexp.getExpressionValue() ) ); clone.setFieldBinding( sfexp.getFieldBinding() ); clone.setFactType( sfexp.getFactType() ); clone.setFieldName( sfexp.getFieldName() ); clone.setFieldType( sfexp.getFieldType() ); clone.setOperator( sfexp.getOperator() ); for ( Map.Entry<String, String> entry : sfexp.getParameters().entrySet() ) { clone.setParameter( entry.getKey(), entry.getValue() ); } clone.setParent( sfexp.getParent() ); clone.setValue( sfexp.getValue() ); if ( sfexp.getConnectives() != null ) { clone.setConnectives( new ConnectiveConstraint[ sfexp.getConnectives().length ] ); for ( int i = 0; i < sfexp.getConnectives().length; i++ ) { clone.getConnectives()[ i ] = (ConnectiveConstraint) visit( sfexp.getConnectives()[ i ] ); } } return clone; }
@Test public void testLHSExpressionJavaEnum() { RuleModel m = new RuleModel(); m.name = "test expressionsJavaEnum"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "CHEESE", DataType.TYPE_COMPARABLE ) ); con.setOperator( "==" ); con.setValue( "CHEESE.Cheddar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsJavaEnum\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == CHEESE.Cheddar )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionNumber() { RuleModel m = new RuleModel(); m.name = "test expressionsNumber"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER ) ); con.setOperator( "==" ); con.setValue( "55" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsNumber\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == 55 )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionDate() { RuleModel m = new RuleModel(); m.name = "test expressionsDate"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.util.Date", DataType.TYPE_DATE ) ); con.setOperator( "==" ); con.setValue( "27-Jun-2011" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsDate\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"27-Jun-2011\" )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionBoolean() { RuleModel m = new RuleModel(); m.name = "test expressionsBoolean"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.lang.Boolean", DataType.TYPE_BOOLEAN ) ); con.setOperator( "==" ); con.setValue( "true" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsBoolean\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == true )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionString2() { RuleModel m = new RuleModel(); m.name = "test expressionsString2"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionUnboundFact( p ) ); con.getExpressionLeftSide().appendPart( new ExpressionField( "field1", "java.lang.String", DataType.TYPE_STRING ) ); con.setOperator( "==" ); con.setValue( "Cheddar" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String result = BRDRLPersistence.getInstance().marshal( m ); String expected = "rule \"test expressionsString2\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"Cheddar\" )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }
@Test public void testLHSExpressionString1() { RuleModel m = new RuleModel(); m.name = "test expressionsString1"; FactPattern p = new FactPattern( "Person" ); SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.getExpressionLeftSide().appendPart( new ExpressionText( "field1" ) ); con.setOperator( "==" ); con.setValue( "goo" ); con.setConstraintValueType( SingleFieldConstraint.TYPE_LITERAL ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"test expressionsString1\"" + "\tdialect \"mvel\"\n when " + " Person( field1 == \"goo\" )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }