All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.verifier.rangeChecks.NumberPatterns.drl Maven / Gradle / Ivy

There is a newer version: 9.44.0.Final
Show newest version
/*
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#created on: 7.6.2007
package org.drools.verifier.rangeChecks.patterns;

#list any import classes here.
import org.drools.base.evaluators.Operator;

import org.drools.verifier.components.*;
import org.drools.verifier.report.components.MissingNumberPattern;
import org.drools.verifier.report.components.Cause;
import org.drools.verifier.FindMissingNumber;

import org.drools.verifier.data.VerifierReport;

import java.util.ArrayList;
import java.util.List;

#declare any global variables here
global VerifierReport result;

#
# If all pattern ranges are not checked for a field.
# 
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar == 10 ) and in "Rule 2" Foo( bar == 20 ) and in "Rule 3" Foo( bar == 40 )
#                     then Foo( bar == 30 ) is missing.
rule "Range check for number patterns"
    @verifying_scopes("knowledge-package", "decision-table")
    when
        $f :Field(
            ( fieldType == Field.INT || == Field.DOUBLE )
        )
        (
            # Where pattern is false.
            $list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
                from collect(
                    LiteralRestriction(
                        fieldId == $f.id,
                        patternIsNot == false,
                        operator == Operator.EQUAL
                    )
                )
        ) or (
            # Where pattern is true.
            $list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
                from collect(
                    LiteralRestriction(
                        fieldId == $f.path,
                        patternIsNot == true,
                        operator =valueator.EQUAL
                    )
                )
        )
    then
        Number number = FindMissingNumber.testForPattern( $list );
        if( number != null ){
            MissingNumberPattern mnp = new MissingNumberPattern( $f, Operator.EQUAL, $f.getFieldType(), number.toString() );
            result.add( mnp );
        }
end

#
# If all pattern ranges are not checked for a field.
# 
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar == 10 ) and in "Rule 2" Foo( bar == 20 ) and in "Rule 3" Foo( bar == 40 )
#                     then Foo( bar == 30 ) is missing.
rule "Range check for number patterns, !="
    @verifying_scopes("knowledge-package", "decision-table")
    when
        $f :Field(
            ( fieldType == Field.INT || == Field.DOUBLE )
        )
        (
            # Where pattern is false.
            $list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
                from collect(
                    LiteralRestriction(
                        fieldId == $f.path,
                        patternIsNot == false,
                        operator == Operator.NOT_EQUAL
                    )
                )
        ) or (
            # Where pattern is false.
            $list :ArrayList( size > FindMissingNumber.MIN_NUMBER_OF_RESTRICTIONS )
                from collect(
                    LiteralRestriction(
                        fieldId == $f.path,
                        pavaluesNot == true,
                        operator == Operator.NOT_EQUAL
                    )
                )
        )
    then
        Number number = FindMissingNumber.testForPattern( $list );
        if( number != null ){
            MissingNumberPattern mnp = new MissingNumberPattern( $f, Operator.NOT_EQUAL, $f.getFieldType(), number.toString() );
            result.add( mnp );
        }
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy