<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    methods getConstraint and setConstraint in Split nodes don't work.
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/marbu">Mar Bartolomé</a> in <i>jBPM Development</i> - <a href="https://community.jboss.org/message/740759#740759">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hello everyone! I'm developing my first project with jBPM, and stumbled with a problem I can't find a solution too. I hope you folks can lend me some help <span> :) </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I have a requirement to be able to<strong> change the constraint of connections coming out of a Split node</strong> (splitting XOR gateway) <strong>at runtime</strong>. I have seen that this type of nodes have a setter and getter method for the constraints. However, when I use this methods on a Split node object, it seems that they do nothing!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>For instance, if I load the BPMN2-ExclusiveSplit.bpmn2 example [</span><a class="jive-link-external-small" href="https://github.com/droolsjbpm/jbpm/blob/master/jbpm-examples/src/main/resources/junit/BPMN2-ExclusiveSplit.bpmn2" target="_blank">https://github.com/droolsjbpm/jbpm/blob/master/jbpm-examples/src/main/resources/junit/BPMN2-ExclusiveSplit.bpmn2</a><span>], and create and start a new instance of the process passing it parameters x="First", y="Second" (as in the test class []), everything executes just fine.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><blockquote class="jive-quote"><pre class="jive-pre"><code class="jive-code jive-java"><font color="navy"><b>public</b></font> <font color="navy"><b>void</b></font> testExclusiveSplit() <font color="navy"><b>throws</b></font> Exception <font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160; KnowledgeBase kbase = createKnowledgeBase(<font color="red">"BPMN2-ExclusiveSplit.bpmn2"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ksession.getWorkItemManager().registerWorkItemHandler(<font color="red">"Email"</font>, <font color="navy"><b>new</b></font> SystemOutWorkItemHandler());
&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map&lt;String, Object&gt; params = <font color="navy"><b>new</b></font> HashMap&lt;String, Object&gt;();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; params.put(<font color="red">"x"</font>, <font color="red">"First"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; params.put(<font color="red">"y"</font>, <font color="red">"Second"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; ProcessInstance processInstance = ksession.startProcess(<font color="red">"com.sample.test"</font>, params);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);
&#160;&#160;&#160; <font color="navy">}</font>
</code></pre>
</blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Notice the constraints associated with the gateway in the bpmn2 file mentioned before:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag">&lt;bpmn2:exclusiveGateway id="_D5523729-B575-4A2A-A7AC-D600586865CD" drools:bgcolor="#ffffff" drools:dg="" name="Split" gatewayDirection="Diverging"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;bpmn2:incoming&gt;</span>_50273E3F-9A4D-4C60-957F-5FE65E6F2609<span class="jive-xml-tag">&lt;/bpmn2:incoming&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;bpmn2:outgoing&gt;</span>_DF37882A-350E-43F9-B776-47CC2AFF1CFB<span class="jive-xml-tag">&lt;/bpmn2:outgoing&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;bpmn2:outgoing&gt;</span>_1AECF2F4-884D-49F7-AEF1-6512E7495D80<span class="jive-xml-tag">&lt;/bpmn2:outgoing&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/bpmn2:exclusiveGateway&gt;</span>
 <span class="jive-xml-tag">&lt;bpmn2:sequenceFlow id="_50273E3F-9A4D-4C60-957F-5FE65E6F2609" sourceRef="_CDDCB4BD-7E33-4124-B9E8-7A5276160413" targetRef="_D5523729-B575-4A2A-A7AC-D600586865CD"/&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;bpmn2:sequenceFlow id="_DF37882A-350E-43F9-B776-47CC2AFF1CFB" name="First" sourceRef="_D5523729-B575-4A2A-A7AC-D600586865CD" targetRef="_FC5AEDEA-84F5-4222-A581-1EBF4376B3A7"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag"><span>&lt;bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression" id="_P8LaOLFQEeG9sYc2b7U_cA" language="</span><a class="jive-link-external-small" href="http://www.java.com/java" target="_blank">http://www.java.com/java</a><span>"&gt;</span></span>&lt;![CDATA[return x == <span class="jive-xml-quote">First</span>;]]&gt;<span class="jive-xml-tag">&lt;/bpmn2:conditionExpression&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/bpmn2:sequenceFlow&gt;</span>

&#160;&#160;&#160; <span class="jive-xml-tag">&lt;bpmn2:sequenceFlow id="_1AECF2F4-884D-49F7-AEF1-6512E7495D80" name="Second" sourceRef="_D5523729-B575-4A2A-A7AC-D600586865CD" targetRef="_427976FF-F304-42EE-82CC-D75D4FBE3376"&gt;</span>
&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag"><span>&lt;bpmn2:conditionExpression xsi:type="bpmn2:tFormalExpression" id="_P8LaObFQEeG9sYc2b7U_cA" language="</span><a class="jive-link-external-small" href="http://www.java.com/java" target="_blank">http://www.java.com/java</a><span>"&gt;</span></span>&lt;![CDATA[return x == <span class="jive-xml-quote">Second</span>;]]&gt;<span class="jive-xml-tag">&lt;/bpmn2:conditionExpression&gt;</span>
&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/bpmn2:sequenceFlow&gt;</span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>However!! if I extract the Split node from my process definition, get it's constraints, and try to get all the attributes out of them:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Node[] processNodes = jbpmProcessDefinition.getNodes();
&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"detected "</font>+jbpmProcessDefinition.getNodes().length+<font color="red">" jbpm states"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font>(Node node : processNodes)<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"processing node "</font>+node);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>if</b></font> (node <font color="navy"><b>instanceof</b></font> Split)<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"&#160;&#160;&#160; it's a split node"</font>);
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Split splitNode = (Split) node; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"Split node has type: "</font>+splitNode.getType());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Map&lt;ConnectionRef, Constraint&gt; constraints = splitNode.getConstraints();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy"><b>for</b></font>(ConnectionRef conn : constraints.keySet())<font color="navy">{</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"constraint name: "</font>+constraints.get(conn).getName());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"contraint type: "</font>+constraints.get(conn).getType());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"constraint lang: "</font>+constraints.get(conn).getDialect());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; log.debug(<font color="red">"node constraint: "</font>+constraints.get(conn).getConstraint()+<font color="red">" on connection "</font>+conn.getNodeId());
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
&#160;&#160;&#160;&#160;&#160;&#160; <font color="navy">}</font>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>what I get is this output from the logger:</p><blockquote class="jive-quote"><table><tbody><tr><td style=";">18:54:16,204DEBUG [ProcessDefinition] </td><td style=";">it's a split node</td></tr></tbody></table><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>18:54:16,206DEBUG [ProcessDefinition] Split node has type: 2</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>18:54:16,208DEBUG [ProcessDefinition] constraint name: Second</p><p>18:54:16,208DEBUG [ProcessDefinition] contraint type: null</p><p>18:54:16,209DEBUG [ProcessDefinition] constraint lang: java</p><p>18:54:16,209DEBUG [ProcessDefinition] <strong>node constraint: null </strong>on connection 4</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>18:54:16,210DEBUG [ProcessDefinition] constraint name: First</p><p>18:54:16,210DEBUG [ProcessDefinition] contraint type: null</p><p>18:54:16,210DEBUG [ProcessDefinition] constraint lang: java</p><p>18:54:16,211DEBUG [ProcessDefinition] <strong>node constraint: null </strong>on connection 3</p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>As you can see: everything is loading just fine, but <strong>"apparently" the constraint is not being loaded</strong>!! Notice the "apparently", because <strong>the constraint is in fact getting loaded</strong>, as the process is capable of selecting the correct transition when it reaches the split node, and also: if i change the values of the parameters passed to the process, or the constraints itselves in the bpmn2 file, then jbpm complains when it reaches the split node that none of the constraints evaluates to true. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><pre class="jive-pre"><code class="jive-code jive-java">org.jbpm.workflow.instance.WorkflowRuntimeException: [com.sample.test:1 - Split:2] -- XOR split could not find at least one valid outgoing connection <font color="navy"><b>for</b></font> split Split
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And there's more! If i try to change the constraint in my process instance for a new one using the setConstraint method, then I get a similar behaviour. When I do this, if I then do a getConstraint(), I don't get a null value anymore: I get the constraint string that I have just set. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So "apparently", the constraint has been updated. However, again, this is not true, as when I execute the process instance, the behaviour I obtain is the one of the constraints that are ironed into the bpmn2 file, and the constraints I set manually with setConstraint("..") are being simply ignored, they do not even override the old ones.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><blockquote class="jive-quote"><p>if I do:<strong> connection.getConstraint()&#160; </strong> ---&gt;&#160;&#160; returns null (and SHOULD return ' return x == "First" ', as it is in the bpmn2 file)</p><p>if AFTER that, I do:<strong> connection.setConstraint("return true;"); connection.getConstraint()</strong>&#160;&#160; ---&gt;&#160;&#160; returns 'return true;', as it would be expected</p><p>if AFTER that<strong> the split node containing that constraint gets executed </strong>&#160; ---&gt;&#160; behaves as if the constraint were ' return x == "First" ', and it should't since the constraint has been changed</p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong>So my conclusion is: these two methods are useless! But then, how can I access the ACTUAL constraint? and how can I change it at runtime? </strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span>I found another post commenting that the fluent API has not been recently updated [</span><a class="jive-link-external-small" href="https://community.jboss.org/message/629023#629023#629023" target="_blank">https://community.jboss.org/message/629023#629023</a><span>], and disrecomends it's usage. I don't know if I stumbled upon a failure in the API, but I hope there is a way of getting and setting the constrains at runtime, because I really need this feature!</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks very much in advance for your kind help. Regards!</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/740759#740759">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2035">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>