<html><body><div>Hi Wolfgang,</div><div><br></div><div>Thanks for that pointer. I'm still seeing errors when I use the import, but it's working when I call CloneMessage.cloneMessage. Which is good enough for me. :)</div><div><br></div><div>In case you're curious (or if anyone else is), I have knocked up a test project in github:</div><div style="padding-left: 24px; "><a href="https://github.com/gratiartis/scattercode-drools-scenarios">https://github.com/gratiartis/scattercode-drools-scenarios</a></div><div><br></div><div>... although you do need Maven installed to run it. Some folks hate that, but I'm a fan.</div><div><br></div><div>The 2 test cases I have been evaluating are here:</div><div><a href="https://github.com/gratiartis/scattercode-drools-scenarios/tree/master/src/test/java/uk/co/scattercode/drools/scenarios/functionimport">https://github.com/gratiartis/scattercode-drools-scenarios/tree/master/src/test/java/uk/co/scattercode/drools/scenarios/functionimport</a>
</div><div><br></div><div>Hopefully having that set up should make it quicker for me to demo such issues in the future.</div><div><br></div><div>Many thanks for the assistance.</div><div><br></div><div>Steve</div><div><br><br>On Jun 19, 2012, at 02:38 PM, Wolfgang Laun &lt;wolfgang.laun@gmail.com&gt; wrote:<br><br></div><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch">In 5.4.0 (and 5.3.0) using an<br> import function x.y.CloneMessage.cloneMessage<br> lets me compile the MVEL version even with separate files all into the<br> same package (as in your post). Without this import, using<br> CloneMessage.cloneMessage(...)<br> works for me, also both versions.<br> <br> HTH<br> -W<br> <br> <br> On 19/06/2012, Stephen Masters &lt;<a href="mailto:stephen.masters@me.com" data-mce-href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>&gt; wrote:<br> &gt; My understanding from the docs is that the DRL functions are converted into<br> &gt; helper classes, which can be imported with "import function<br> &gt; mypackage.CloneMessage.cloneMessage", although it's not clear what that<br> &gt; 'class name' (?) in the middle refers to. Maybe the generated helper class?<br> &gt; However, if the function is in your current package the import is<br> &gt; automatically derived for you. Hence no import statements in my tests. Which<br> &gt; is nice. :)<br> &gt;<br> &gt; I just tried combining them in a single file, and it still fails for the<br> &gt; same reason. I'm still on 5.3.1 at the moment, so I think this might be a<br> &gt; new item for my list of reasons to roll up my sleeves and upgrade.<br> &gt;<br> &gt; Thanks for taking a look,<br> &gt;<br> &gt; Steve<br> &gt;<br> &gt;<br> &gt; On Jun 19, 2012, at 01:42 PM, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com" data-mce-href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt; wrote:<br> &gt;<br> &gt; It works (5.4.0) with both, Java and MVEL, if all is in the same DRL file.<br> &gt;<br> &gt; I'm somewhat surprised that "import" should work for DRL functions,<br> &gt; but I may have missed some development. But your snippets don't show a<br> &gt; DRL import statement?<br> &gt;<br> &gt; -W<br> &gt;<br> &gt;<br> &gt; On 19/06/2012, Stephen Masters &lt;<a href="mailto:stephen.masters@me.com" data-mce-href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>&gt; wrote:<br> &gt;&gt; Okay Wolfgang ... you asked for it. Here's a version which takes it pretty<br> &gt;&gt; much to the minimum.<br> &gt;&gt;<br> &gt;&gt; The error I see is "Unable to resolve method using strict-mode:<br> &gt;&gt; mypackage.CloneMessage.cloneMessage(mypackage.Message)"<br> &gt;&gt;<br> &gt;&gt; However, the error is only seen when I use mvel dialect. The working Java<br> &gt;&gt; dialect rule is also included below.<br> &gt;&gt;<br> &gt;&gt; Note that when I re-wrote the example function to take a common type such<br> &gt;&gt; as<br> &gt;&gt; String as argument, then the mvel version worked. It's when the argument<br> &gt;&gt; is<br> &gt;&gt; a declared type that it fails.<br> &gt;&gt;<br> &gt;&gt; Thanks for taking a look,<br> &gt;&gt;<br> &gt;&gt; Steve<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; file - MessageFact.drl<br> &gt;&gt;<br> &gt;&gt; package mypackage<br> &gt;&gt;<br> &gt;&gt; declare Message<br> &gt;&gt; Text: String<br> &gt;&gt; end<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; file - CloneMessage.drl<br> &gt;&gt;<br> &gt;&gt; package mypackage<br> &gt;&gt;<br> &gt;&gt; function Message cloneMessage(Message originalMessage) {<br> &gt;&gt;<br> &gt;&gt; Message newMessage = new Message();<br> &gt;&gt; newMessage.setText(originalMessage.getText());<br> &gt;&gt; return newMessage;<br> &gt;&gt;<br> &gt;&gt; }<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; file - SayHelloRuleJava.drl<br> &gt;&gt;<br> &gt;&gt; package mypackage<br> &gt;&gt;<br> &gt;&gt; rule "Say hello"<br> &gt;&gt; dialect "java"<br> &gt;&gt; lock-on-active true<br> &gt;&gt; when<br> &gt;&gt; # Always<br> &gt;&gt; then<br> &gt;&gt; Message originalMessage = new Message();<br> &gt;&gt; originalMessage.setText("Hello, World!");<br> &gt;&gt;<br> &gt;&gt; Message clonedMessage = cloneMessage(originalMessage);<br> &gt;&gt;<br> &gt;&gt; insert(clonedMessage);<br> &gt;&gt; end<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; file - SayHelloRuleMvel.drl<br> &gt;&gt;<br> &gt;&gt; package mypackage<br> &gt;&gt;<br> &gt;&gt; rule "Say hello"<br> &gt;&gt; dialect "mvel"<br> &gt;&gt; lock-on-active true<br> &gt;&gt; when<br> &gt;&gt; # Always<br> &gt;&gt; then<br> &gt;&gt; Message originalMessage = new Message();<br> &gt;&gt; originalMessage.Text = "Hello, World!";<br> &gt;&gt;<br> &gt;&gt; Message clonedMessage = cloneMessage(originalMessage);<br> &gt;&gt;<br> &gt;&gt; insert(clonedMessage);<br> &gt;&gt; end<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; On Jun 19, 2012, at 12:27 PM, Wolfgang Laun &lt;<a href="mailto:wolfgang.laun@gmail.com" data-mce-href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>&gt;<br> &gt;&gt; wrote:<br> &gt;&gt;<br> &gt;&gt; Can you please provide an example where and how you import and use a<br> &gt;&gt; DRL function so that it works/doesn't work with MVEL/Java?<br> &gt;&gt;<br> &gt;&gt; -W<br> &gt;&gt;<br> &gt;&gt;<br> &gt;&gt; On 19/06/2012, Stephen Masters &lt;<a href="mailto:stephen.masters@me.com" data-mce-href="mailto:stephen.masters@me.com">stephen.masters@me.com</a>&gt; wrote:<br> &gt;&gt;&gt; Hi folks,<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Is it possible to refer to DRL functions from a DRL when the dialect is<br> &gt;&gt;&gt; mvel?<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; I have been working on unit tests for a rule that were consistently<br> &gt;&gt;&gt; failing<br> &gt;&gt;&gt; due to not being able to find the function that should be imported.<br> &gt;&gt;&gt; Having<br> &gt;&gt;&gt; tried various formats (the documentation is rather unhelpful here) for<br> &gt;&gt;&gt; the<br> &gt;&gt;&gt; import, I thought I'd see what happened if I just switched to the Java<br> &gt;&gt;&gt; dialect. Suddenly it worked without even needing an import statement.<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Unfortunately, this forces me to switch from the neat ...<br> &gt;&gt;&gt; newFact.Property = otherFact.Property<br> &gt;&gt;&gt; ... to the rather ugly Java-style<br> &gt;&gt;&gt; newFact.setProperty(otherFact.getProperty())<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; So I would quite like to know if there is an undocumented (or<br> &gt;&gt;&gt; well-hidden-documented) mechanism for using functions when in mvel<br> &gt;&gt;&gt; dialect.<br> &gt;&gt;&gt; Or am I stuck with switching to Java?<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Thanks in advance for any pointers anybody can provide,<br> &gt;&gt;&gt;<br> &gt;&gt;&gt; Steve<br> &gt;&gt; _______________________________________________<br> &gt;&gt; rules-users mailing list<br> &gt;&gt; <a href="mailto:rules-users@lists.jboss.org" data-mce-href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br> &gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" data-mce-href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br> &gt;&gt;<br> &gt; _______________________________________________<br> &gt; rules-users mailing list<br> &gt; <a href="mailto:rules-users@lists.jboss.org" data-mce-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" data-mce-href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br> &gt;<br> _______________________________________________<br> rules-users mailing list<br> <a href="mailto:rules-users@lists.jboss.org" data-mce-href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br> <a href="https://lists.jboss.org/mailman/listinfo/rules-users" data-mce-href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></div></div></blockquote></div></body></html>