Package org.drools.workbench.models.datamodel.rule

Examples of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint


                if ( isConstraintComplete( constr ) ) {
                    if ( constr instanceof SingleFieldConstraintEBLeftSide ) {
                        buf.append( ( (SingleFieldConstraintEBLeftSide) constr ).getExpressionLeftSide().getText() );
                    } else {
                        SingleFieldConstraint parent = (SingleFieldConstraint) constr.getParent();
                        StringBuilder parentBuf = new StringBuilder();
                        while ( parent != null ) {
                            String fieldName = parent.getFieldName();
                            parentBuf.insert( 0,
                                              fieldName + "." );
                            parent = (SingleFieldConstraint) parent.getParent();
                        }
                        buf.append( parentBuf );
                        String fieldName = constr.getFieldName();
                        buf.append( fieldName );
                    }
View Full Code Here


                int endSquare = value.indexOf( ']' );
                operatorParams = value.substring( 1, endSquare ).trim();
                value = value.substring( endSquare + 1 ).trim();
            }

            SingleFieldConstraint fieldConstraint = isExpression ?
                    createExpressionBuilderConstraint( factPattern,
                                                       fieldName,
                                                       operator,
                                                       value ) :
                    createSingleFieldConstraint( fieldName,
                                                 operator,
                                                 value );

            if ( operatorParams != null ) {
                int i = 0;
                for ( String param : operatorParams.split( "," ) ) {
                    ( (BaseSingleFieldConstraint) fieldConstraint ).setParameter( "" + i++, param.trim() );
                }
                ( (BaseSingleFieldConstraint) fieldConstraint ).setParameter( "org.drools.workbench.models.commons.backend.rule.visibleParameterSet", "" + i );
                ( (BaseSingleFieldConstraint) fieldConstraint ).setParameter( "org.drools.workbench.models.commons.backend.rule.operatorParameterGenerator",
                                                                              "org.drools.workbench.models.commons.backend.rule.CEPOperatorParameterDRLBuilder" );
            }

            if ( fieldName.equals( "this" ) && ( operator == null || operator.equals( "!= null" ) ) ) {
                fieldConstraint.setFieldType( DataType.TYPE_THIS );
            }
            fieldConstraint.setFactType( factPattern.getFactType() );

            return fieldConstraint;
        }
View Full Code Here

                                                                         String value ) {
            // TODO: we should find a way to know when the expression uses a getter and in this case create a plain SingleFieldConstraint
            //int dotPos = fieldName.lastIndexOf('.');
            //SingleFieldConstraint con = createSingleFieldConstraint(dotPos > 0 ? fieldName.substring(dotPos+1) : fieldName, operator, value);

            SingleFieldConstraint con = createSingleFieldConstraintEBLeftSide( factPattern,
                                                                               fieldName,
                                                                               operator,
                                                                               value );

            for ( FieldConstraint fieldConstraint : factPattern.getFieldConstraints() ) {
                if ( fieldConstraint instanceof SingleFieldConstraint ) {
                    SingleFieldConstraint sfc = (SingleFieldConstraint) fieldConstraint;
                    if ( sfc.getOperator().equals( "!= null" ) ) {
                        int parentPos = fieldName.indexOf( sfc.getFieldName() + "." );
                        if ( parentPos >= 0 && !fieldName.substring( parentPos + sfc.getFieldName().length() + 1 ).contains( "." ) ) {
                            con.setParent( sfc );
                            break;
                        }
                    }
                }
View Full Code Here

        }

        private SingleFieldConstraint createSingleFieldConstraint( String fieldName,
                                                                   String operator,
                                                                   String value ) {
            SingleFieldConstraint con = new SingleFieldConstraint();
            fieldName = setFieldBindingOnContraint( fieldName, con );
            con.setFieldName( fieldName );
            setOperatorAndValueOnConstraint( operator, value, con );
            return con;
        }
View Full Code Here

        private SingleFieldConstraint createParentFor( FactPattern factPattern,
                                                       String fieldName ) {
            int dotPos = fieldName.lastIndexOf( '.' );
            if ( dotPos > 0 ) {
                SingleFieldConstraint constraint = createNullCheckFieldConstraint( factPattern, fieldName.substring( 0, dotPos ) );
                factPattern.addConstraint( constraint );
                return constraint;
            }
            return null;
        }
View Full Code Here

        private EvalExpr( String expr ) {
            this.expr = expr;
        }

        public FieldConstraint asFieldConstraint( FactPattern factPattern ) {
            SingleFieldConstraint con = new SingleFieldConstraint();
            con.setConstraintValueType( SingleFieldConstraint.TYPE_PREDICATE );
            con.setValue( expr );
            return con;
        }
View Full Code Here

                }

                assertConstraintValue( constr );

                if ( isConstraintComplete( constr ) ) {
                    SingleFieldConstraint parent = (SingleFieldConstraint) constr.getParent();
                    StringBuilder parentBuf = new StringBuilder();
                    while ( parent != null ) {
                        String fieldName = parent.getFieldName();
                        parentBuf.insert( 0,
                                          fieldName + "." );
                        parent = (SingleFieldConstraint) parent.getParent();
                    }
                    buf.append( parentBuf );
                    if ( constr instanceof SingleFieldConstraintEBLeftSide ) {
                        buf.append( ( (SingleFieldConstraintEBLeftSide) constr ).getExpressionLeftSide().getText() );
                    } else {
View Full Code Here

            if ( generateTemplateCheck ) {
                if ( constr instanceof SingleFieldConstraint && ( (SingleFieldConstraint) constr ).getConnectives() != null ) {
                    // if there are connectives, and the first is a template key, then all templates keys must be checked up front
                    // individual connectives, that have template keys, will still need to be checked too.
                    SingleFieldConstraint sconstr = (SingleFieldConstraint) constr;
                    buf.append( "@if{" + ( (SingleFieldConstraint) constr ).getValue() + " != empty" );
                    for ( int j = 0; j < sconstr.getConnectives().length; j++ ) {
                        final ConnectiveConstraint conn = sconstr.getConnectives()[ j ];
                        if ( conn.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_TEMPLATE ) {
                            buf.append( " || " + conn.getValue() + " != empty" );
                        }
                    }
                    buf.append( "}" );
View Full Code Here

                operatorParams = value.substring( 1,
                                                  endSquare ).trim();
                value = value.substring( endSquare + 1 ).trim();
            }

            SingleFieldConstraint fieldConstraint = isExpression ?
                    createExpressionBuilderConstraint( m,
                                                       factPattern,
                                                       fieldName,
                                                       operator,
                                                       value ) :
                    createSingleFieldConstraint( m,
                                                 factPattern,
                                                 fieldName,
                                                 operator,
                                                 value );

            if ( operatorParams != null ) {
                int i = 0;
                for ( String param : operatorParams.split( "," ) ) {
                    fieldConstraint.setParameter( "" + i++,
                                                  param.trim() );
                }
                fieldConstraint.setParameter( "org.drools.workbench.models.commons.backend.rule.visibleParameterSet",
                                              "" + i );
                fieldConstraint.setParameter( "org.drools.workbench.models.commons.backend.rule.operatorParameterGenerator",
                                              "org.drools.workbench.models.commons.backend.rule.CEPOperatorParameterDRLBuilder" );
            }

            if ( fieldName.equals( "this" ) && ( operator == null || operator.equals( "!= null" ) ) ) {
                fieldConstraint.setFieldType( DataType.TYPE_THIS );
            }
            fieldConstraint.setFactType( factPattern.getFactType() );

            ModelField field = findField( findFields( m,
                                                      dmo,
                                                      factPattern.getFactType() ),
                                          fieldConstraint.getFieldName() );

            if ( field != null && ( fieldConstraint.getFieldType() == null || fieldConstraint.getFieldType().trim().length() == 0 ) ) {
                fieldConstraint.setFieldType( field.getType() );
            }
            return fieldConstraint;
        }
View Full Code Here

                                                                         final String value ) {
            // TODO: we should find a way to know when the expression uses a getter and in this case create a plain SingleFieldConstraint
            //int dotPos = fieldName.lastIndexOf('.');
            //SingleFieldConstraint con = createSingleFieldConstraint(dotPos > 0 ? fieldName.substring(dotPos+1) : fieldName, operator, value);

            SingleFieldConstraint con = createSingleFieldConstraintEBLeftSide( m,
                                                                               factPattern,
                                                                               fieldName,
                                                                               operator,
                                                                               value );
View Full Code Here

TOP

Related Classes of org.drools.workbench.models.datamodel.rule.SingleFieldConstraint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.