org.drools.verifier.rangeChecks.Variables.drl Maven / Gradle / Ivy
/*
* 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.
*/
package org.drools.verifier.rangeChecks.variables;
//list any import classes here.
import org.drools.verifier.components.*;
import org.drools.verifier.data.VerifierReport;
import org.drools.verifier.report.components.Gap;
import java.util.ArrayList;
import java.util.TreeSet;
import java.text.SimpleDateFormat;
import java.util.Locale;
//declare any global variables here
//global VerifierReport result;
/*
// If all ranges are not checked for a field.
//
// Type: Warning
// Example: in "Rule 1" Something( $value :value ) and Foo( bar > $value )
// and in "Rule 2" Something( $value :value ) and Foo( bar < $value )
// then Foo( bar == Something.value ) is missing.
rule "Range check for variables when restriction is VariableRestriction"
when
# Find a field that is of type variable.
$f :Field( fieldType == Field.VARIABLE )
# Find constraint that matches this field
# Find variable that is on the right side of this constraint i.e. bar > $foo
# Find another variable that points to the same field.
# Find another constraint and check if it continues to check the range for this field.
(
$r :VariableRestriction( fieldId == $f.path, evaluator == ">" )
and
$v1 :Variable( id == $r.variableId )
and
$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.path)
and
not VariableRestriction( fieldId == $f.path, ( evaluator == "==" || == "<=" ),
variableId == $v2.path,
patternIsNot == $r.patternIsNot )
) or (
$r :VariableRestriction( fieldId == $f.path, evaluator == "<" )
and
$v1 :Variable( id == $r.variableId )
and
$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.path)
and
not VariableRestriction( fieldId == $f.path, ( evaluator == "==" || == ">=" ),
variableId == $v2.path,
patternIsNot == $r.patternIsNot )
) or (
$r :VariableRestriction( fieldId == $f.path, evaluator == "<=" )
and
$v1 :Variable( id == $r.variableId )
and
$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.path)
and
not VariableRestriction( fieldId == $f.path, evaluator == ">",
variableId == $v2.path,
patternIsNot == $r.patternIsNot )
) or (
$r :VariableRestriction( fieldId == $f.path, evaluator == ">=" )
and
$v1 :Variable( id == $r.variableId )
and
$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.path)
and
not VariableRestriction( fieldId == $f.path, evaluator == "<",
variableId == $v2.path,
patternIsNot == $r.patternIsNot )
)
$rule :VerifierRule( id == $r.ruleId )
then
Gap gap = new Gap();
gap.setCause($f);
gap.setRuleName($rule.getName());
gap.setEvaluator($r.getEvaluator());
gap.setValue("variable");
insert( gap );
end
*/
© 2015 - 2025 Weber Informatics LLC | Privacy Policy