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; }
private String setOperatorAndValueOnConstraint( String operator, String value, SingleFieldConstraint con ) { if ( operator != null ) { con.setOperator( operator ); boolean isAnd = value.contains( "&&" ); String[] splittedValue = isAnd ? value.split( "\\&\\&" ) : value.split( "\\|\\|" ); String type = setValueOnConstraint( operator, con, splittedValue[ 0 ].trim() ); if ( splittedValue.length > 1 ) { ConnectiveConstraint[] connectiveConstraints = new ConnectiveConstraint[ splittedValue.length - 1 ]; for ( int i = 0; i < connectiveConstraints.length; i++ ) { String constraint = splittedValue[ i + 1 ].trim(); String connectiveOperator = findOperator( constraint ); String connectiveValue = constraint.substring( connectiveOperator.length() ).trim(); connectiveConstraints[ i ] = new ConnectiveConstraint(); connectiveConstraints[ i ].setOperator( ( isAnd ? "&& " : "|| " ) + connectiveOperator ); setValueOnConstraint( operator, connectiveConstraints[ i ], connectiveValue ); } con.setConnectives( connectiveConstraints ); } return type; } return null; }
@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 ); }
conn.getConstraintValueType(), conn.getFieldType(), conn.getOperator(), parameters, conn.getValue(), conn.getExpressionValue() );
private void visitSingleFieldConstraint( SingleFieldConstraint sfc ) { InterpolationVariable var = new InterpolationVariable( sfc.getValue(), sfc.getFieldType(), factPattern.getFactType(), sfc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == sfc.getConstraintValueType() && !vars.containsKey( var ) ) { vars.put( var, vars.size() ); } //Visit Connection constraints if ( sfc.getConnectives() != null ) { for ( int i = 0; i < sfc.getConnectives().length; i++ ) { final ConnectiveConstraint cc = sfc.getConnectives()[ i ]; InterpolationVariable ccVar = new InterpolationVariable( cc.getValue(), cc.getFieldType(), factPattern.getFactType(), cc.getFieldName() ); if ( BaseSingleFieldConstraint.TYPE_TEMPLATE == cc.getConstraintValueType() && !vars.containsKey( ccVar ) ) { vars.put( ccVar, vars.size() ); } } } }
private Widget connectiveOperatorDropDown( final ConnectiveConstraint cc ) { if ( !isReadOnly ) { String factType = cc.getFactType(); String fieldName = cc.getFieldName(); String[] operators = this.getCompletions().getConnectiveOperatorCompletions( factType, fieldName ); CEPOperatorsDropdown w = new CEPOperatorsDropdown( operators, cc ); w.addValueChangeHandler( new ValueChangeHandler<OperatorSelection>() { public void onValueChange( ValueChangeEvent<OperatorSelection> event ) { OperatorSelection selection = event.getValue(); String selected = selection.getValue(); cc.setOperator( selected ); } } ); return w; } else { SmallLabel sl = new SmallLabel( "<b>" + ( cc.getOperator() == null ? Constants.INSTANCE.pleaseChoose() : HumanReadable.getOperatorDisplayName(cc.getOperator()) ) + "</b>" ); return sl; } }
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() ); } } } }
this.factType = cc.getFactType(); this.fieldName = cc.getFieldName(); this.fieldType = cc.getFieldType();
String fieldName = cc.getFieldName(); if ( fieldName.equals( DataType.TYPE_THIS ) ) { showLiteralSelector = CEPOracle.isCEPOperator( cc.getOperator() ); showFormulaSelector = showFormulaSelector && showLiteralSelector;
public void onValueChange( ValueChangeEvent<OperatorSelection> event ) { OperatorSelection selection = event.getValue(); String selected = selection.getValue(); cc.setOperator( selected ); } } );
/** * This adds a new connective. */ public void addNewConnective() { String fieldName = this.fieldName; String fieldType = this.fieldType; String factType = this.factType; if ( this.connectives == null ) { this.connectives = new ConnectiveConstraint[]{ new ConnectiveConstraint( factType, fieldName, fieldType ) }; } else { final ConnectiveConstraint[] newList = new ConnectiveConstraint[ this.connectives.length + 1 ]; for ( int i = 0; i < this.connectives.length; i++ ) { newList[ i ] = this.connectives[ i ]; } newList[ this.connectives.length ] = new ConnectiveConstraint( factType, fieldName, fieldType ); this.connectives = newList; } }
public ConnectiveConstraint( final String factType, final String fieldName, final String fieldType, final String opr, final String val ) { this.factType = factType; this.fieldName = fieldName; this.fieldType = fieldType; this.operator = opr; this.setValue( val ); }
( (SingleFieldConstraint) con ).setFieldType( type ); } else if ( con instanceof ConnectiveConstraint ) { ( (ConnectiveConstraint) con ).setFieldType( type );
X.setOperator( "==" ); X.setConnectives( new ConnectiveConstraint[ 1 ] ); 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" ); comp.addConstraint( X );
/** * 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 ); } }