<div dir="ltr">Hi Davide,<div><br></div><div>Drools trait functionality is one of the powerful concepts which makes Drools a good candidate for the project. So keep up the good work! :) However I&#39;m not sure if its current level of flexibility would be sufficient for our use case. I&#39;ve checked the documentation, but haven&#39;t really found the term virtual field -- could you please elaborate on this?</div>
<div><br></div><div>Do you think we could somehow hook into the evaluation of the aliases or the &quot;fields&quot; Map? Sometimes you would need slightly more than merely aliasing fields to something else; e.g. calculating values for the purpose of rule processing or extracting a value from a more complex object tree etc. Citing the example -- GoldenCustomer( fields[ &quot;age&quot; ] &gt; 18 ) -- being able to get a reference to the target object and the field map expression &quot;age&quot; would be quite close to what I imagined. Our custom code could then perform the appropriate translation and return the requested value, hiding the fact whether &quot;age&quot; is an actual field in the Customer object itself/retrieved from an encapsulated complex object e.g. replacing expression &quot;customer.personalInformation.birthData.age&quot;/calculated on the flight.          </div>
<div><br></div><div>What do you think?</div><div><br></div><div>Cheers,</div><div>Peter</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-26 17:58 GMT+02:00 Davide Sottara <span dir="ltr">&lt;<a href="mailto:dsotty@gmail.com" target="_blank">dsotty@gmail.com</a>&gt;</span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We are working on the trait framework for cases like this. Essentially,<br>
it allows to use<br>
interfaces when writing rules AND to inject the interfaces dynamically<br>
at runtime,<br>
at the instance level. It relies on transparent proxies which wrap the<br>
data classes<br>
and implement the required interfaces. A simple field aliasing mechanism<br>
is provided<br>
(work in progress). For more complex transformations, &quot;virtual&quot; fields<br>
can be added.<br>
See section 7.7.8 of the manual for more details and let me know if it<br>
can help<br>
with your use case.<br>
Best,<br>
Davide<br>
<div class="HOEnZb"><div class="h5"><br>
On 05/26/2014 09:55 AM, Wolfgang Laun wrote:<br>
&gt; Even a relatively sophisticated transformation would be easier to implement<br>
&gt; and most certainly safer from changes in the unstable Drools API than some<br>
&gt; hook-and-intercept mechanism built into Drools.<br>
&gt;<br>
&gt; Notice that violent structural departure of the model the BUs see from what<br>
&gt; you call &quot;persistence model&quot; might make it impossible for the BUs to come<br>
&gt; up with rules that can be transformed to match the other model at all;<br>
&gt; if it is possible, rules might still incur a heavy performance penalty.<br>
&gt;<br>
&gt; It is (IMHO) a myth that &quot;Rules&quot; is a foolproof way of establishing<br>
&gt; business logic<br>
&gt; independent from the data model and application environment with which<br>
&gt; this logic should be able to cooperate. As long as everything is kept in the<br>
&gt; abstract (i.e., formulated in terms of mathematics) it will look  good, but<br>
&gt; any implementation may throw a spanner in the works, or worse.<br>
&gt;<br>
&gt; -W<br>
&gt;<br>
&gt; On 26/05/2014, Péter Gergely, Horváth &lt;<a href="mailto:h.peter@mailbox.hu">h.peter@mailbox.hu</a>&gt; wrote:<br>
&gt;&gt; Hi Wolfgang,<br>
&gt;&gt;<br>
&gt;&gt; Thank you for your input. You are right that some of the cases could simply<br>
&gt;&gt; be covered by regexp-replace, but I&#39;m afraid, not all of them. Interfaces<br>
&gt;&gt; could also help, but we have a requirement that the business rules should<br>
&gt;&gt; not be tightly coupled to the underlying persistence model. (I understand<br>
&gt;&gt; that some might say this is not ideal, but that is our current situation)<br>
&gt;&gt;<br>
&gt;&gt; I am wondering whether it is possible to hook into Drools engine and<br>
&gt;&gt; intercept field value reference expression evaluations in run time (e.g if<br>
&gt;&gt; &quot;foo.bars&quot; is used in an expression, we could return &quot;foo.barList&quot;) ? By<br>
&gt;&gt; injecting some custom code, we could make the necessary decisions and<br>
&gt;&gt; extract the proper value from an object. Unfortunately these parts of<br>
&gt;&gt; Drools are pretty much undocumented.<br>
&gt;&gt;<br>
&gt;&gt; Regards,<br>
&gt;&gt; Peter<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; 2014-05-26 13:57 GMT+02:00 Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;:<br>
&gt;&gt;<br>
&gt;&gt;&gt; What you describe can be done with /bin/sed.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Notice that the DSL processor doesn&#39;t require you to translate entire<br>
&gt;&gt;&gt; patterns; there is a mechanism for translating &quot;keywords&quot;, which is<br>
&gt;&gt;&gt; just arbitrary tokens to whatever replacement text.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; If a &quot;bar&quot; must be translated to a &quot;barList&quot; in the context of a class<br>
&gt;&gt;&gt; &quot;Foo&quot; but not in any other context, a more sophisticated translation<br>
&gt;&gt;&gt; is required in any case (with /bin/sed still being sufficient if<br>
&gt;&gt;&gt; patterns aren&#39;t split across lines).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Some say that good design makes use of Interfaces, which leaves room<br>
&gt;&gt;&gt; for actual implementations being changed as long as the interfaces are<br>
&gt;&gt;&gt; implemented. Here, note that rules can be written against interface<br>
&gt;&gt;&gt; types.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -W<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On 26/05/2014, Péter Gergely, Horváth &lt;<a href="mailto:h.peter@mailbox.hu">h.peter@mailbox.hu</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; Hi All,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; We are evaluating Drools 6 for our use case, and face challenges where<br>
&gt;&gt;&gt;&gt; we<br>
&gt;&gt;&gt;&gt; would need some ideas from more experienced users of Drools.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; We have an application with a massive code base and a large number of<br>
&gt;&gt;&gt; model<br>
&gt;&gt;&gt;&gt; (entity) classes. We are in the process of moving away from inherited<br>
&gt;&gt;&gt;&gt; legacy technologies and refactoring the old code base. As a part of<br>
&gt;&gt;&gt;&gt; this<br>
&gt;&gt;&gt;&gt; work we would like extract some of the hard-coded business logic to<br>
&gt;&gt;&gt;&gt; external rules, that is why we are looking at Drools as a potential<br>
&gt;&gt;&gt;&gt; solution.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; What we would like to have is some kind of abstraction or mapping<br>
&gt;&gt;&gt;&gt; between<br>
&gt;&gt;&gt;&gt; actual entities and rules the business users can define so that they do<br>
&gt;&gt;&gt; not<br>
&gt;&gt;&gt;&gt; have to know the _exact_ details of the data model (field names,<br>
&gt;&gt;&gt;&gt; precise<br>
&gt;&gt;&gt;&gt; relations etc). This would be important for us so that we can refactor<br>
&gt;&gt;&gt; the<br>
&gt;&gt;&gt;&gt; old model classes without affecting business rules; also it would make<br>
&gt;&gt;&gt; life<br>
&gt;&gt;&gt;&gt; easier for the business users. While IDE support might make refactoring<br>
&gt;&gt;&gt;&gt; easier, we definitely want to have a separation between rules and<br>
&gt;&gt;&gt; entities.<br>
&gt;&gt;&gt;&gt; Given our situation, writing and maintaining &quot;stable&quot; wrapper/adapter<br>
&gt;&gt;&gt;&gt; classes for the sole purpose of rule processing is out of question. I<br>
&gt;&gt;&gt; have<br>
&gt;&gt;&gt;&gt; checked the documentation of Drools DSL support and for me it seems to<br>
&gt;&gt;&gt;&gt; be<br>
&gt;&gt;&gt;&gt; overkill for our use case: we do not really need a custom language, but<br>
&gt;&gt;&gt;&gt; simply an abstraction between rules and the data model classes.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; What I could imagine is a piece of code, (a custom property resolver? -<br>
&gt;&gt;&gt; no<br>
&gt;&gt;&gt;&gt; sure how it is called) which maps property expressions to actual<br>
&gt;&gt;&gt; properties<br>
&gt;&gt;&gt;&gt; based on a custom annotation on the entity class or something like<br>
&gt;&gt;&gt;&gt; that,<br>
&gt;&gt;&gt; so<br>
&gt;&gt;&gt;&gt; that a rule containing &quot;Foo.bars&quot; expression does not have to change<br>
&gt;&gt;&gt;&gt; even<br>
&gt;&gt;&gt;&gt; if we decide to rename &quot;Foo.bars&quot; to &quot;Foo.barList&quot; in the model<br>
&gt;&gt;&gt;&gt; classes.<br>
&gt;&gt;&gt;&gt; (This was just a simple example of a potential use cases)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Could you please share your thoughts on this topic and point me into<br>
&gt;&gt;&gt;&gt; the<br>
&gt;&gt;&gt;&gt; right direction?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Thanks,<br>
&gt;&gt;&gt;&gt; Peter<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; rules-users mailing list<br>
&gt;&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-users mailing list<br>
&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;<br>
<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>
</div></div></blockquote></div><br></div>