org.drools.verifier.rangeChecks.Dates.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.
*/
//created on: 7.6.2007
package org.drools.verifier.rangeChecks.dates;
//list any import classes here.
import org.drools.core.base.evaluators.Operator;
import org.drools.verifier.components.*;
import org.drools.verifier.data.VerifierReport;
import org.drools.verifier.report.components.Gap;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
//declare any global variables here
global VerifierReport 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"
@verifying_scopes(["knowledge-package", "decision-table"])
when
$f :Field(
fieldType == Field.DATE
)
// Foo( bar > "27-Oct-2007" )
$r :DateRestriction(
fieldPath == $f.path,
operator == Operator.GREATER
)
// Check if Foo( bar == "27-Oct-2007" || <= "27-Oct-2007" ) is missing.
not DateRestriction(
fieldPath == $f.path,
( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
value == $r.value
)
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"
@verifying_scopes(["knowledge-package", "decision-table"])
when
$f :Field( fieldType == Field.DATE )
// Foo( bar > "27-Oct-2007" )
$r :DateRestriction(
fieldPath == $f.path,
operator == Operator.LESS
)
// Check if Foo( bar == "27-Oct-2007" || <= "27-Oct-2007" ) is missing.
not DateRestriction(
fieldPath == $f.path,
( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
value == $r.value
)
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"
@verifying_scopes(["knowledge-package", "decision-table"])
when
$f :Field( fieldType == Field.DATE )
// Foo( bar == "27-Oct-2007" )
$r :DateRestriction(
fieldPath == $f.path,
( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL )
)
// Check if Foo( bar > "27-Oct-2007" || >= "27-Oct-2007" ) is missing.
not DateRestriction(
fieldPath == $f.path,
( operator == Operator.GREATER || == Operator.GREATER_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
value == $r.value
)
// Check if Foo( bar == "28-Oct-2007" || >= "28-Oct-2007" ) is missing.
not DateRestriction(
fieldPath == $f.path,
( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( checkDates( value, $r.getValue(), 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"
@verifying_scopes(["knowledge-package", "decision-table"])
when
$f :Field( fieldType == Field.DATE )
// Foo( bar == "27-Oct-2007" )
$r :DateRestriction(
fieldPath == $f.path,
( operator == Operator.EQUAL || == Operator.GREATER_OR_EQUAL )
)
// Check if Foo( bar < "27-Oct-2007" || <= "27-Oct-2007" ) is missing.
not DateRestriction(
fieldPath == $f.path,
( operator == Operator.LESS || == Operator.LESS_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( value.equals($r.getValue()) )
)
// Check if Foo( bar == "26-Oct-2007" || <= "26-Oct-2007" ) is missing.
not DateRestriction(
fieldPath == $f.path,
( operator == Operator.EQUAL || == Operator.LESS_OR_EQUAL ),
patternIsNot == $r.patternIsNot,
eval( checkDates( value, $r.getValue(), false ) )
)
then
Gap gap = new Gap( $f, Operator.LESS, $r );
result.add( gap );
insert( gap );
end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy