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

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

There is a newer version: 9.44.0.Final
Show newest version
package org.drools.verifier.rangeChecks.variables;

#list any import classes here.
import org.drools.verifier.components.*;
import org.drools.verifier.dao.VerifierResult;
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 VerifierResult 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.FieldType.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.id, evaluator == ">" )
			and
				$v1 :Variable( id == $r.variableId )
			and
				$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.id)
			and
				not VariableRestriction( fieldId == $f.id, ( evaluator == "==" || == "<=" ), 
														variableId == $v2.id,
														patternIsNot == $r.patternIsNot )
		) or (
				$r :VariableRestriction( fieldId == $f.id, evaluator == "<" )
			and
				$v1 :Variable( id == $r.variableId )
			and
				$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.id)
			and
				not VariableRestriction( fieldId == $f.id, ( evaluator == "==" || == ">=" ), 
														variableId == $v2.id,
														patternIsNot == $r.patternIsNot )
		) or (
				$r :VariableRestriction( fieldId == $f.id, evaluator == "<=" )
			and
				$v1 :Variable( id == $r.variableId )
			and
				$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.id)
			and
				not VariableRestriction( fieldId == $f.id, evaluator == ">", 
														variableId == $v2.id,
														patternIsNot == $r.patternIsNot )
		) or (
				$r :VariableRestriction( fieldId == $f.id, evaluator == ">=" )
			and
				$v1 :Variable( id == $r.variableId )
			and
				$v2 :Variable( objectId == $v1.objectId, objectType == $v1.objectType, id != $v1.id)
			and
				not VariableRestriction( fieldId == $f.id, evaluator == "<", 
														variableId == $v2.id,
														patternIsNot == $r.patternIsNot )
		)
		$rule :VerifierRule( id == $r.ruleId )
	then
		Gap gap = new Gap();
		gap.setCause($f);
		gap.setRuleName($rule.getRuleName());
		gap.setEvaluator($r.getEvaluator());
		gap.setValue("variable");
		insert( gap );
end 
*/




© 2015 - 2025 Weber Informatics LLC | Privacy Policy