[rules-users] How do I configure the constraints for a Split node in Drools Flow to test the value of a process variable?

Kris Verlaenen kris.verlaenen at cs.kuleuven.be
Mon Oct 19 11:33:30 EDT 2009


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 at 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



More information about the rules-users mailing list