0

I am new to drools and I am trying to create some rules for a project. I had been able to create a couple of rules but I have found difficulty to fire the below rules so any help would be valuable and much appreciated. I have been trying for more than a day to fire the below rules and I have tried multiple combinations with no success. The model is a huge object with multiple properties so I could not provide it.

In the below rule the "header.totalGrossMassMeasure" is a bigDecimal value. It is produced from xsd with xjc plugin. I would like to check its format to be a decimal number that has 16 digits overall with maximum of 6 decimal digits I know the regex is a bit bulky but form testing it here it seems to works. However it can not get fired. Any suggestions?

rule "007"
no-loop
when 
 $msg : Declaration( header.totalGrossMassMeasure.toString() matches "^([0-
 9]{10}(\\.[0-9]{1,6})?)$|^([0-9]{11}(\\.[0-9]{1,5})?)$|^([0-9]{12}(\\.[0-9]
 {1,4})?)$|^([0-9]{13}(\\.[0-9]{1,3})?)$|^([0-9]{14}(\\.[0-9]{1,2})?)$|^([0-
 9]{15}(\\.[0-9]{1})?)$|^([0-9]{16})$")
 result : ValidationResult()
 then
 RulesValidationError error = new RulesValidationError();
 error.setRuleName("007");
 error.setErrorType(ErrorType.INCORECT_VALUE);
 result.getErrorsList().add(error);
 end
IsidIoan
  • 403
  • 2
  • 5
  • 13
  • The text of your question and the regular expression contradict the statements in the consequence where an error is registered if the pattern (that agrees with the text) matches. – laune Nov 18 '17 at 15:30
  • Apparently the range is "...has *at most* 16 digits overall with a maximum of 6 decimal digits" – laune Nov 18 '17 at 15:32
  • @laune yes you are right I did not stated correctly. The number should have overall 16 digits, where there could be 6 maximum decimal digits. Sorry for my english and thanks for pointing it out. Apparently I have made stupid mistake. Btw how I could change the rule to check numbers that do not match the regexp? – IsidIoan Nov 18 '17 at 15:42
  • @laune I believe something like not matches would do the job.? – IsidIoan Nov 18 '17 at 15:57
  • That's right: not matches should do the trick. (If this strange value range excluding, for instance, 123456789 is really what you need.) – laune Nov 18 '17 at 16:03
  • @laune tested and it works. thank you for your time. – IsidIoan Nov 18 '17 at 16:11

0 Answers0