Try using eval as a last resort. A better (smaller, more robust) DSL can be designed around facts and their attributes.<br><br>"||" (and "OR") can be used, but setting parentheses in order to get the priority right is difficult. In constraints, you may have to resort to "memberof" or "not memberof".<br>
<br>Your sample isn't self-contained. But I think that the following DSL and the DSLR might give you some ideas how to proceed.<br><br>[keyword][]check that {conditions}= eval( {conditions} )<br>[keyword][]AND = &&<br>
[keyword][]OR = ||<br><br>[when][][Tt]here is an? {entity}= {entity}: {entity}()<br>[when][][Tt]here is at least one {entity}= exists {entity}: {entity}()<br><br>[when][]the {entity:\w+}'s {attr:\w+} = {entity}.get{attr}()<br>
<br>[when][]- with a valid {attr} = {attr}: {attr} != null<br>[when][]- with {attr} not equal to {value} = {attr} != {value}<br>[when][]- eval\( {whatever} \)=eval( {whatever} )<br><br>[when][] {attr:\S+} follows pattern {pattern:\S+} = {attr}.matches( {pattern} )<br>
[when][] {attr:\S+} not equals? {value:\S+} = ! {attr}.equals( {value} )<br>[when][] {attr:\S+} is valid = {attr} != null<br> <br>rule "Rule 5"<br>when<br> There is a Department<br> There is at least one Person<br>
- with name not equal to "xxx"<br> - with a valid subordinate <br> - check that the Person's Id is valid AND the Department's Id follows pattern "I" AND the Department's HeadOfDpt not equal name<br>
then<br>end<br><br>Notice that "-check that..." must be written as a single line.<br><br>-W<br><br><br><br><br><div class="gmail_quote">2011/1/3 maverik j <span dir="ltr"><<a href="mailto:maverikj348@gmail.com">maverikj348@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Hi,</div>
<div> </div>
<div> We are planning to use DSL/DSRL approach with generic DSL template like say</div>
<div><font size="2">
<p align="left">[condition][]The {object} has valid {field}={object}({field} != null )</p>
<p align="left">[condition][]there is object {<u>obj</u>} that = {<u>obj</u>}()</p>
<p align="left">[condition][]- has {<u>attr</u>} equal {<u>val</u>} = {<u>attr</u>} == {<u>val</u>}</p>
<p align="left">[condition][]- has valid {<u>attr</u>} = {<u>attr</u>} != null</p>
<p>[condition][]- and has {<u>attr</u>} equal {value}= && {<u>attr</u>} == {value}</p></font></div>
<div> </div>
<div>But there are quite few of requirements like to have DSL rules that can generate expression as follows:</div>
<div>exists Employee(<br> attribute name not equals "xxx"<br> && the attribute subOrdinate is not null<br> && eval(<br> the attribute $dept.getId() is not null <br> && attribute $dept.getId() follows pattern "I" <br>
&& ( ! (the attribute $dept.getHeadOfDpt() equals name)<br> )<br>)</div>
<div> </div>
<div>I am not sure if this is possible with DSL. Using '-' operator we cannot really add '&&', '||' conditions it by-default expands to ',' separated and conditions. And wirtting generic rules with and/or is not really dynamic to allow any number of expressions in evaluation.</div>
<div> </div>
<div>i am struggling to get this run since long time so any help/thoughts on this would be highly appriciable !!!</div>
<div> </div>
<div>Thanks & Regards,</div>
<div>-Maverik</div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>