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

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


        private SingleFieldConstraint createSingleFieldConstraint( final RuleModel m,
                                                                   final FactPattern factPattern,
                                                                   String fieldName,
                                                                   final String operator,
                                                                   final String value ) {
            SingleFieldConstraint con = new SingleFieldConstraint();
            fieldName = setFieldBindingOnContraint( factPattern.getFactType(),
                                                    fieldName,
                                                    m,
                                                    con,
                                                    boundParams );
            con.setFieldName( fieldName );
            setOperatorAndValueOnConstraint( m,
                                             operator,
                                             value,
                                             factPattern,
                                             con );

            //Setup parent relationships for SingleFieldConstraints
            for ( FieldConstraint fieldConstraint : factPattern.getFieldConstraints() ) {
                if ( fieldConstraint instanceof SingleFieldConstraint ) {
                    SingleFieldConstraint sfc = (SingleFieldConstraint) fieldConstraint;
                    if ( sfc.getOperator() != null && 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 createParentFor( final RuleModel m,
                                                       final FactPattern factPattern,
                                                       final String fieldName ) {
            int dotPos = fieldName.lastIndexOf( '.' );
            if ( dotPos > 0 ) {
                SingleFieldConstraint constraint = createNullCheckFieldConstraint( m,
                                                                                   factPattern,
                                                                                   fieldName.substring( 0,
                                                                                                        dotPos ) );
                factPattern.addConstraint( constraint );
                return constraint;
View Full Code Here

            this.expr = expr;
        }

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

                        final SingleFieldConstraintEBLeftSide sfcexp = ( (SingleFieldConstraintEBLeftSide) constr );
                        final ToStringExpressionVisitor visitor = new ToStringExpressionVisitor( sfcexp.getExpressionLeftSide().getBinding(),
                                                                                                 constraintValueBuilder );
                        buf.append( sfcexp.getExpressionLeftSide().getText( visitor ) );
                    } 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

                        final SingleFieldConstraintEBLeftSide sfcexp = ( (SingleFieldConstraintEBLeftSide) constr );
                        final ToStringExpressionVisitor visitor = new ToStringExpressionVisitor( sfcexp.getExpressionLeftSide().getBinding(),
                                                                                                 constraintValueBuilder );
                        buf.append( sfcexp.getExpressionLeftSide().getText( visitor ) );
                    } 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

        }
        if ( !( fc instanceof SingleFieldConstraint ) ) {
            messages.add( new UnsupportedFieldConstraintParserMessage() );
            return nodes;
        }
        final SingleFieldConstraint sfc = (SingleFieldConstraint) fc;
        if ( sfc.getConnectives() != null ) {
            messages.add( new UnsupportedFieldConstraintParserMessage() );
            return nodes;
        }

        ConstraintNode node = null;
        final String className = sfc.getFactType();
        final String fieldName = sfc.getFieldName();

        if ( sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL ) {
            final String operator = sfc.getOperator();
            final boolean isValueRequired = OperatorsOracle.isValueRequired( operator );
            if ( isValueRequired ) {
                final Value value = getValue( className,
                                              fieldName,
                                              model,
                                              dmo,
                                              messages,
                                              sfc.getValue() );
                if ( value != null ) {
                    node = new ConstraintNodeImpl( className,
                                                   fieldName,
                                                   operator,
                                                   value );
                }
            } else {
                node = new ConstraintNodeImpl( className,
                                               fieldName );
            }

        } else if ( sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_ENUM ) {
            final String operator = sfc.getOperator();
            final boolean isValueRequired = OperatorsOracle.isValueRequired( operator );
            if ( isValueRequired ) {
                final Value value = getValue( className,
                                              fieldName,
                                              model,
                                              dmo,
                                              messages,
                                              sfc.getValue() );
                if ( value != null ) {
                    node = new ConstraintNodeImpl( className,
                                                   fieldName,
                                                   operator,
                                                   value );
                }
            } else {
                node = new ConstraintNodeImpl( className,
                                               fieldName );
            }

        } else if ( sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_UNDEFINED ) {
            final String operator = sfc.getOperator();
            final boolean isValueRequired = OperatorsOracle.isValueRequired( operator );
            if ( isValueRequired ) {
                node = new ConstraintNodeImpl( className,
                                               fieldName );
            } else {
                node = new ConstraintNodeImpl( className,
                                               fieldName,
                                               operator,
                                               null );
            }

        } else {
            messages.add( new UnsupportedFieldConstraintTypeParserMessage() );
            return nodes;
        }

        if ( node != null ) {
            if ( sfc.isBound() ) {
                node.setBinding( sfc.getFieldBinding() );
            }
            nodes.add( node );
        }

        return nodes;
View Full Code Here

            this.expr = expr;
        }

        public FieldConstraint asFieldConstraint( final RuleModel m,
                                                  final FactPattern factPattern ) {
            SingleFieldConstraint con = new SingleFieldConstraint();
            con.setConstraintValueType( SingleFieldConstraint.TYPE_PREDICATE );
            con.setValue( expr );
            return con;
        }
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

        private SingleFieldConstraint createSingleFieldConstraint( final RuleModel m,
                                                                   final FactPattern factPattern,
                                                                   String fieldName,
                                                                   final String operator,
                                                                   final String value ) {
            SingleFieldConstraint con = new SingleFieldConstraint();
            fieldName = setFieldBindingOnContraint( factPattern.getFactType(),
                                                    fieldName,
                                                    m,
                                                    con,
                                                    boundParams );
            con.setFieldName( fieldName );
            setOperatorAndValueOnConstraint( m,
                                             operator,
                                             value,
                                             factPattern,
                                             con );

            //Setup parent relationships for SingleFieldConstraints
            for ( FieldConstraint fieldConstraint : factPattern.getFieldConstraints() ) {
                if ( fieldConstraint instanceof SingleFieldConstraint ) {
                    SingleFieldConstraint sfc = (SingleFieldConstraint) fieldConstraint;
                    if ( sfc.getOperator() != null && 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

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.