org.drools.verifier.rangeChecks.Dates.drl Maven / Gradle / Ivy
#created on: 7.6.2007
package org.drools.verifier.rangeChecks.dates;
#list any import classes here.
import org.drools.base.evaluators.Operator;
import org.drools.verifier.components.*;
import org.drools.verifier.dao.VerifierResult;
import org.drools.verifier.report.components.Gap;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.drools.verifier.dao.VerifierResult;
#declare any global variables here
global VerifierResult result;
function boolean checkDates(Date d1, Date d2, boolean up) {
Calendar c1 = new GregorianCalendar();
c1.setTime(d1);
Calendar c2 = new GregorianCalendar();
c2.setTime(d2);
c2.roll( Calendar.DATE, up );
return ( 0 == c1.compareTo( c2 ) );
}
# If all ranges are not checked for a field.
#
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar > "27-Oct-2007" )
# and in Foo( <= "27-Oct-2007" || == "27-Oct-2007" ) is missing.
#
rule "Range check for dates, if smaller than or equal is missing"
when
$f :Field( fieldType == Field.FieldType.DATE )
# Foo( bar > "27-Oct-2007" )
$r :LiteralRestriction(
fieldId == $f.id,
operator == Operator.GREATER
)
# Check if Foo( bar == "27-Oct-2007" || <= "27-Oct-2007" ) is missing.
not LiteralRestriction(
fieldId == $f.id,
( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( dateValue.equals($r.getDateValue()) )
)
then
Gap gap = new Gap( $f, Operator.LESS_OR_EQUAL, $r );
result.add( gap );
insert( gap );
end
# If all ranges are not checked for a field.
#
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar < "27-Oct-2007" )
# and in Foo( >= "27-Oct-2007" || == "27-Oct-2007" ) is missing.
#
rule "Range check for dates, if greater than or equal is missing"
when
$f :Field( fieldType == Field.FieldType.DATE )
# Foo( bar > "27-Oct-2007" )
$r :LiteralRestriction(
fieldId == $f.id,
operator == Operator.LESS
)
# Check if Foo( bar == "27-Oct-2007" || <= "27-Oct-2007" ) is missing.
not LiteralRestriction(
fieldId == $f.id,
( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( dateValue.equals($r.getDateValue()) )
)
then
Gap gap = new Gap( $f, Operator.GREATER_OR_EQUAL, $r );
result.add( gap );
insert( gap );
end
# If all ranges are not checked for a field.
#
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar == "27-Oct-2007" || bar <= "27-Oct-2007" )
# and no Foo( bar > "27-Oct-2007" || >= "27-Oct-2007" || >= "28-Oct-2007" || == "28-Oct-2007" )
# then Foo( bar > "27-Oct-2007" ) is missing.
#
rule "Range check for dates, equal and greater than"
when
$f :Field( fieldType == Field.FieldType.DATE )
# Foo( bar == "27-Oct-2007" )
$r :LiteralRestriction(
fieldId == $f.id,
( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL )
)
# Check if Foo( bar > "27-Oct-2007" || >= "27-Oct-2007" ) is missing.
not LiteralRestriction(
fieldId == $f.id,
( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( dateValue.equals($r.getDateValue()) )
)
# Check if Foo( bar == "28-Oct-2007" || >= "28-Oct-2007" ) is missing.
not LiteralRestriction(
fieldId == $f.id,
( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( checkDates( dateValue, $r.getDateValue(), true ) )
)
then
Gap gap = new Gap( $f, Operator.GREATER, $r );
result.add( gap );
insert( gap );
end
# If all ranges are not checked for a field.
#
# Type: Warning
# Dependencies: None
# Example: in "Rule 1" Foo( bar == "27-Oct-2007" || bar >= "27-Oct-2007" )
# and no Foo( bar < "27-Oct-2007" || <= "27-Oct-2007" || <= "26-Oct-2007" || == "26-Oct-2007" )
# then Foo( bar < "27-Oct-2007" ) is missing.
#
rule "Range check for dates, equal and smaller than"
when
$f :Field( fieldType == Field.FieldType.DATE )
# Foo( bar == "27-Oct-2007" )
$r :LiteralRestriction(
fieldId == $f.id,
( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL )
)
# Check if Foo( bar < "27-Oct-2007" || <= "27-Oct-2007" ) is missing.
not LiteralRestriction(
fieldId == $f.id,
( operator == Operator.LESS || == Operator.LESS_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( dateValue.equals($r.getDateValue()) )
)
# Check if Foo( bar == "26-Oct-2007" || <= "26-Oct-2007" ) is missing.
not LiteralRestriction(
fieldId == $f.id,
( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( checkDates( dateValue, $r.getDateValue(), false ) )
)
then
Gap gap = new Gap( $f, Operator.LESS, $r );
result.add( gap );
insert( gap );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy