Mar Bartolomé [
https://community.jboss.org/people/marbu] created the discussion
"Re: methods getConstraint and setConstraint in Split nodes don't work."
To view the discussion, visit:
https://community.jboss.org/message/740934#740934
--------------------------------------------------------------
Ok, I made some more findings on my own.
Seems that whenever a split node get parsed (in org.jbpm.compiler.ProcessBuilderImpl), for
every constraint it contains, a new drools rule is created, with the constraint
condition:
private String createSplitRule(Process process,
Connection connection,
String constraint) {
return
"rule \"RuleFlow-Split-" + process.getId() + "-" +
((org.jbpm.workflow.core.Node) connection.getFrom()).getUniqueId() +
"-" +
((org.jbpm.workflow.core.Node) connection.getTo()).getUniqueId() +
"-" +
connection.getToType() + "\" \n" +
" ruleflow-group \"DROOLS_SYSTEM\" \n" +
" when \n" +
" " + constraint + "\n" +
" then \n" +
"end \n\n";
}
Then, when the node gets later evaluated at runtime, (at
org.jbpm.workflow.instance.node.SplitInstance) the constraints get evaluated, with an
or.jbpm.process.instance.impl.RuleConstraintEvaluator. This evaluation returns true if the
drools rule created at parse time is active.
So, efectively, the setConstraint method does absolutely nothing, as the evaluation only
depends on the drools rule, and this doesn't get modified at all.
HOWEVER! notice how in the createSplitRule method, it actually uses the text in the
constraint to add it as a drools rule. This text seems that should in fact be present in
the constraints in the split node, or the call to evaluate done in ProcessBuilderImpl
could not work:
private void generateRules(Node[] nodes, Process process, StringBuffer builder) {
for ( int i = 0; i < nodes.length; i++ ) {
if ( nodes[i] instanceof Split ) {
Split split = (Split) nodes[i];
if ( split.getType() == Split.TYPE_XOR || split.getType() == Split.TYPE_OR
) {
for ( Connection connection : split.getDefaultOutgoingConnections() )
{
Constraint constraint = split.getConstraint( connection );
if ( "rule".equals( constraint.getType() ) ) {
builder.append( createSplitRule( process,
connection,
split.getConstraint(
connection ).getConstraint() ) );
}
}
}
This connection, I reckon, is set at parse time in org.jbpm.bpmn2.xml.ProcessHandler, and
it's obtained from a SequenceFlow object, wich is a direct mapping of a bpmn2 sequence
flow (and completely inaccessible once the parsing is done, I assume).
for (SequenceFlow connection: connections) {
[ ... ]
if (source instanceof Split) {
Split split = (Split) source;
Constraint constraint = new ConstraintImpl();
[ ... ]
if (connection.getExpression() != null) {
constraint.setConstraint(connection.getExpression());
}
[ ... ]
split.addConstraint(
new ConnectionRef(target.getId(),
NodeImpl.CONNECTION_DEFAULT_TYPE),
constraint);
}
What I still don't undestand is how the getConstraint() method at Split is returning
null, if it seems reasonable that it should at least contain the constraint text (or else,
the drools rule wouldn't get created, and the constraint wouldn't be evaluated at
runtime).
Please, any help would be appreciated.
--------------------------------------------------------------
Reply to this message by going to Community
[
https://community.jboss.org/message/740934#740934]
Start a new discussion in jBPM Development at Community
[
https://community.jboss.org/choose-container!input.jspa?contentType=1&...]