Mismatched input in rule

450 views
Skip to first unread message

Dejan Janković

unread,
Aug 14, 2019, 9:50:31 AM8/14/19
to Drools Setup
Hello guys,

I have a problem when I try to add a rule into the KieBase. I am using 7.22.0.Final version of Drools.
Drools Java code for adding new rule is show below:

 kieFileSystem.write("src/main/resources/rules/" + rule.getName() + ".drl", rule.getDrlFile());
 KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll();
 kieContainer = kieServices.newKieContainer(kieRepository.getDefaultReleaseId());

Example of DRL which is causing me this problem is: 

package rules 
import com.myproject.web.dto.ruleengine.RuleExecutionOutputDTO
global com.myproject.domain.CustomerCDO customer
global com.myproject.domain.ContactPersonCDO contactPerson
dialect "mvel"
rule "TENANT01_EXM_Dejan"
when
customer.getAddress1() != "Belgrade 11" && contactPerson.getEmail() str[endsWith] "gmail.com
then
RuleExecutionOutputDTO $ruleExecutionOutput = new RuleExecutionOutputDTO();
$ruleExecutionOutput.setApproverRoleId(7)
end

Error occurs when I try to build this new rule and to add it into the KieContainer:

[ERROR] org.drools.compiler.kie.builder.impl.KieProject - Unable to build KieBaseModel:defaultKieBase
[ERR 102] Line 19:23 mismatched input '!=' in rule "TENANT01_EXM_Dejan"
[0,0]: Parser returned a null Package

I don't know why Drools engine is complaining about "!=" sign, when it is allowed by a documentation that I followed:
https://docs.jboss.org/drools/release/7.12.0.Final/drools-docs/html_single/

It is complaining also about "str[endsWith]", although by the documentation it is a valid operator for drl syntax.

Do you have any idea why I constantly get this error?

Thank you very much in advance.

Regards,
Dejan Jankovic



Mario Fusco

unread,
Aug 14, 2019, 12:11:22 PM8/14/19
to drools...@googlegroups.com
Hi Dejan,

the compiler error message is indeed quite misleading but in reality the compiler is not complaining about the != operator neither the str[endsWIth] one, but by the fact that those constraint should be part of a pattern matching expression. In general you shouldn't pattern matching on globals but against facts inserted into the working memory. However since you're using globals you should wrap those constraints inside an eval

eval( customer.getAddress1() != "Belgrade 11" && contactPerson.getEmail() str[endsWith] "gmail.com)

I hope this helps,
Mario


--
You received this message because you are subscribed to the Google Groups "Drools Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/afe32d3f-e0d8-48a5-9aa3-7874ed4424bd%40googlegroups.com.

Dejan Janković

unread,
Aug 15, 2019, 5:21:13 AM8/15/19
to Drools Setup
Hey Mario,

Thank you very much. 

When I placed my condition into the "eval( )", then Drools reported me an error with str operator, in a moment of adding that rule into the KieBase.
Obviously, the way how DRL is validated is different when using globals to establish conditions, which is not recommended.

When I insert "customer" and "contractPerson" as facts (imports), then I don't have any problems with adding that version of DRL into the KieBase.

Thank you for your answer once again. 

I'll change my code in this manner, and I hope I will not have any more questions. :)

Regards,
Dejan


Dana srijeda, 14. kolovoza 2019. u 18:11:22 UTC+2, korisnik Mario Fusco napisao je:
Hi Dejan,

the compiler error message is indeed quite misleading but in reality the compiler is not complaining about the != operator neither the str[endsWIth] one, but by the fact that those constraint should be part of a pattern matching expression. In general you shouldn't pattern matching on globals but against facts inserted into the working memory. However since you're using globals you should wrap those constraints inside an eval

eval( customer.getAddress1() != "Belgrade 11" && contactPerson.getEmail() str[endsWith] "gmail.com)

I hope this helps,
Mario


To unsubscribe from this group and stop receiving emails from it, send an email to drools...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages