Drools allows for fact duplication default. Thus rules
riskBrancher1
and
riskBrancher2
requires additional condition that checks if a given
Rating/MatchingAssessor
already exists:
rule "riskBrancher1"
when
RiskBrancher($clientname : Client, $risklevel : RiskLevel)
LoanRequest(Client == $clientname, $amountask : AmountAsk, AmountAsk < $risklevel)
not(MatchingAssessor(Client == $clientname, AmountAsk == $amountask))
then
insert(new MatchingAssessor($clientname, $amountask));
//System.out.println("For client " + $clientname + ": The asked amount is less than risk level: asked = " + $amountask + ", risk = " + $risklevel);
end
rule "riskBrancher2"
when
RiskBrancher($clientname : Client, $risklevel : RiskLevel, $ratingmin : RatingMin)
LoanRequest(Client == $clientname, $amountask : AmountAsk, AmountAsk >= $risklevel)
not(RatingAssessor(Client == $clientname, AmountAsk == $amountask, RatingMin == $ratingmin))
then
insert(new RatingAssessor($clientname, $amountask, $ratingmin));
//System.out.println("For client " + $clientname + ": The asked amount is greater or equal than/to risk level: asked = " + $amountask + ", risk = " + $risklevel);
end