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; }
/** * 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 void visitSingleFieldConstraint( SingleFieldConstraintEBLeftSide sfexp ) { String genericType = sfexp.getExpressionLeftSide().getGenericType(); String factType = sfexp.getExpressionLeftSide().getPreviousClassType(); if ( factType == null ) { factType = sfexp.getExpressionLeftSide().getClassType(); } InterpolationVariable var = new InterpolationVariable( sfexp.getValue(), genericType, factType, sfexp.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfexp.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfexp.getConnectives() != null ) { for ( int i = 0; i < sfexp.getConnectives().length; i++ ) { final ConnectiveConstraint cc = sfexp.getConnectives()[ i ]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), genericType, factType, cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
@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 ); }
public void onClick( ClickEvent event ) { SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.setConstraintValueType( SingleFieldConstraint.TYPE_UNDEFINED ); con.setExpressionLeftSide( new ExpressionFormLine( new ExpressionUnboundFact( pattern ) ) ); hasConstraints.addConstraint( con ); modeller.refreshWidget(); popup.hide(); } } );
@Override public void setFieldBinding( String fieldBinding ) { getExpressionLeftSide().setBinding( fieldBinding ); }
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; }
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; }
buf.append( ( (SingleFieldConstraintEBLeftSide) constr ).getExpressionLeftSide().getText() ); } else { String fieldName = constr.getFieldName(); SingleFieldConstraintEBLeftSide sfexp = (SingleFieldConstraintEBLeftSide) constr; addFieldRestriction( buf, sfexp.getConstraintValueType(), sfexp.getExpressionLeftSide().getGenericType(), sfexp.getOperator(), parameters, sfexp.getValue(),
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; }
@Test public void testAllVariableBindings2() { final RuleModel model = new RuleModel(); model.lhs = new IPattern[1]; final FactPattern fp = new FactPattern( "Car" ); model.lhs[0] = fp; fp.setBoundName( "$c" ); SingleFieldConstraint sfc = new SingleFieldConstraintEBLeftSide( "make" ); sfc.getExpressionValue().appendPart( new ExpressionField( "make", "java.lang.String", "String" ) ); sfc.setFieldBinding( "$m" ); fp.addConstraint( sfc ); List<String> vars = model.getAllVariables(); assertEquals( 2, vars.size() ); assertEquals( "$c", vars.get( 0 ) ); assertEquals( "$m", vars.get( 1 ) ); }
@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 ); }
public void onClick( ClickEvent event ) { SingleFieldConstraintEBLeftSide con = new SingleFieldConstraintEBLeftSide(); con.setConstraintValueType( SingleFieldConstraint.TYPE_UNDEFINED ); fp.addConstraint( con ); con.setExpressionLeftSide( new ExpressionFormLine( new ExpressionUnboundFact( pattern ) ) ); modeller.refreshWidget(); popup.hide(); } } );
@Override public String getFieldName() { return getExpressionLeftSide().getFieldName(); }
@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 ); }
@Override public String getFieldType() { return getExpressionLeftSide().getClassType(); }
@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 ); }
@Override public String getFieldBinding() { return getExpressionLeftSide().getBinding(); }
@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 ); }
protected List<String> getFieldBinding( FieldConstraint f ) { List<String> result = new ArrayList<String>(); if ( f instanceof SingleFieldConstraint ) { SingleFieldConstraint con = (SingleFieldConstraint) f; if ( con.isBound() ) { result.add( con.getFieldBinding() ); } if ( con.getExpressionValue() != null && con.getExpressionValue().isBound() ) { result.add( con.getExpressionValue().getBinding() ); } if ( con instanceof SingleFieldConstraintEBLeftSide ) { SingleFieldConstraintEBLeftSide exp = (SingleFieldConstraintEBLeftSide) con; if ( exp.getExpressionLeftSide() != null && exp.getExpressionLeftSide().isBound() ) { result.add( exp.getExpressionLeftSide().getBinding() ); } } } else if ( f instanceof CompositeFieldConstraint ) { CompositeFieldConstraint cfc = (CompositeFieldConstraint) f; if ( cfc.getConstraints() != null ) { for ( FieldConstraint ss : cfc.getConstraints() ) { List<String> t = getFieldBinding( ss ); result.addAll( t ); } } } return result; }