我是drools的新手。如何根据drools语法(mvel2)正确解析这个逻辑?
rule CAN_LOGIN_TOACCOUNTMASTER
when
c: PermissionCheck( target == "login", action=="can" )
Role(name in ("A", "B", "C", "D", E", "F"))
c.grant();
这种语法适用于带有mvel的drools 4。但是没有使用mvel2的drools 5。
修改 拼写错误是一个复制粘贴问题。
我在JBOSS EAP 6.3中收到以下错误消息
引起:org.drools.rule.InvalidRulePackage:Predicate'name ==“A”|| name ==“B”|| name ==“C”|| name ==“D”|| name ==“E”|| name ==“F”'必须是布尔表达式 [行:132,栏目:8]:[规则名称='CAN_LOGIN_TOACCOUNTMASTER']
at org.drools.rule.Package.checkValidity(Package.java:478) [drools-core-5.3.0.Final.jar:5.3.0.Final]
at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:481) [drools-core-5.3.0.Final.jar:5.3.0.Final]
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:458) [drools-core-5.3.0.Final.jar:5.3.0.Final]
at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:465) [drools-core-5.3.0.Final.jar:5.3.0.Final]
at org.jboss.seam.drools.RuleBase.compileRuleBase(RuleBase.java:121) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_11]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_11]
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
at org.jboss.seam.Component.callComponentMethod(Component.java:2249) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
at org.jboss.seam.Component.callCreateMethod(Component.java:2172) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
at org.jboss.seam.Component.newInstance(Component.java:2132) [jboss-seam-2.2.0.GA.jar:2.2.0.GA]
... 60 more
答案 0 :(得分:1)
rule CAN_LOGIN_TOACCOUNTMASTER
when
c: PermissionCheck( target == "login", action=="can" )
Role(name in ("A", "B", "C", "D", E", "F"))
c.grant();
E
之前缺少引号。then
,这不是一种模式。修改强> 查看抛出异常的代码,假设您在代码中有一些错误。由于以下规则正常,因此假设该名称是类规则中的字符串字段,它必须是您发布的内容不明显的内容。
您是否在规则编制期间检查错误?
如果出现语法错误,请指明正好 Drools版本(5 )并添加错误消息。
编辑正确的解决方案(所有测试和使用5.3.0工作)是:
when
c: PermissionCheck( target == "login", action=="can" )
Role(name in ("A", "B", "C", "D", "E", "F"))
then
或
when
c: PermissionCheck( target == "login", action=="can" )
Role(name == "A" || name == "B" || name == "C" || name == "D" ||
name == "E" || name == "F")
then
或
when
c: PermissionCheck( target == "login", action=="can" )
Role(name == "A" || == "B" || == "C" || == "D" || == "E" || == "F")
then
答案 1 :(得分:-1)
我已使用以下代码
解决了该问题rule CAN_LOGIN_TOACCOUNTMASTER
when
c: PermissionCheck( target == "login", action=="can" )
(Role(name == "A") or Role(name == "B") or Role(name == "C") or
Role(name == "D") or Role(name == "E") or Role(name == "F"))
c.grant();