Kris,

Thanks for the fast response - the 'return' statement made all the difference - it's working as expected now.

This was code from a simple unit test, so I wasn't initially checking errors after loading the process. After adding the code you suggested, the old process definition (i.e. without the return statement in the split node constraints) failed to parse with the following error:

"This method must return a result of type Object"

 - pretty obvious that a return statement was required. I'll be sure to add the error checking code to all future tests. ;)

Thanks again for your help,

Alan




Kris Verlaenen <kris.verlaenen@cs.kuleuven.be>
Sent by: rules-users-bounces@lists.jboss.org

19/10/2009 16:43
Please respond to
Rules Users List <rules-users@lists.jboss.org>

To
Rules Users List <rules-users@lists.jboss.org>, Alan.Gairey@tessella.com
cc
Subject
Re: [rules-users] How do I configure the constraints for a Split        node in Drools Flow to test the value of a process variable?





Alan,

Your code constraints should look something like:

 return "error".equals(status);

Do you check for errors after loading a process?  Basically, errors
should be detected when trying to parse the given process because the
constraints could not be compiled (at least, that happened when I tried
something similar).

KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
 for (KnowledgeBuilderError error: errors) {
   System.err.println(error);
 }
 throw new IllegalArgumentException("Could not parse knowledge.");
}

If you don't get any errors, could you sent me a self-contained example
that shows this issue, so I can figure out what's going on?

Thx,
Kris

Quoting Alan.Gairey@tessella.com:

> I have a requirement for a simple rule flow containing a "status"
> process
> variable; a work item sets the value of this variable via its Result
>
> Mapping. Following the work item is an XOR Split node, which can go
> to one
> of two following nodes, depending on the value of the status process
>
> variable. The relevant sections from the rule flow definition, as
> currently written, are as follows:
>
>   <header>
>     <variables>
>       <variable name="status" >
>         <type
> name="org.drools.process.core.datatype.impl.type.StringDataType" />
>       </variable>
>       ...
>     </variables>
>   </header>
>
>   <nodes>
>     ...
>     <workItem id="4" name="Test work item" x="352" y="52" width="80"
>
> height="40" >
>       <work name="TestItem" >
>       </work>
>       <mapping type="out" from="status" to="status" />
>     </workItem>
>     ...
>     <split id="9" name="Split" x="464" y="52" width="80" height="40"
>
> type="2" >
>       <constraints>
>         <constraint toNodeId="10" toType="DROOLS_DEFAULT"
> name="error"
> priority="1" type="code" dialect="java"
> >status.equals("error")</constraint>
>         <constraint toNodeId="8" toType="DROOLS_DEFAULT"
> name="success"
> priority="1" type="code" dialect="java"
> >status.equals("success")</constraint>
>       </constraints>
>     </split>
>     ...
>   </nodes>
> The Java code that implements the "TestItem" work item finishes with
> the
> code:
>
>     Map<String, Object> results = new HashMap<String, Object>();
>     results.put("status", status);  // Value of status can be
> "success" or
> "error"
>  
>
ksession.getWorkItemManager().completeWorkItem(stepInstance.getWorkItemId(),
>
> results);
> When I execute this process, no matter what the value of the status
> result
> returned by the work item, the node with ID 8 (the 'success' path)
> always
> executes.
> I hope it's clear what I'm trying to do (i.e. define a process
> variable,
> sets its value using the result from a work item, and then test its
> value
> in a Split node); can anyone help me out as to why it's not working?
>
> (Incidentally, this is Drools v5.1M1.)
> Many thanks,
> Alan




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users