Skip to content

Commit d1a8c91

Browse files
authored
#3884 Expression language support for conditional sequence flow and conditional events (#3889)
* #3884 Expression language support for conditional sequence flow and conditional events * #3884: Use ScriptCondition instead of ScriptEngineExpression * #3884: Move logic to ConditionUtil and leave ScriptCondition unchanged * #3884: Rename sequenceFlowId to elementId. Revert whitespace-only changes. * #3884: Pass the id of the event definition instead of the activity
1 parent 0069d6a commit d1a8c91

26 files changed

Lines changed: 257 additions & 40 deletions

modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/BaseBpmnXMLConverter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ protected void writeConditionalDefinition(Event parentEvent, ConditionalEventDef
597597

598598
if (StringUtils.isNotEmpty(conditionalDefinition.getConditionExpression())) {
599599
xtw.writeStartElement(ELEMENT_CONDITION);
600+
if (conditionalDefinition.getConditionLanguage() != null) {
601+
xtw.writeAttribute(XSI_PREFIX, XSI_NAMESPACE, "type", "tFormalExpression");
602+
BpmnXMLUtil.writeDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_SCRIPT_LANGUAGE, conditionalDefinition.getConditionLanguage(), xtw);
603+
}
600604
xtw.writeCharacters(conditionalDefinition.getConditionExpression());
601605
xtw.writeEndElement();
602606
}

modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/SequenceFlowXMLConverter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javax.xml.stream.XMLStreamWriter;
1717

1818
import org.apache.commons.lang3.StringUtils;
19+
import org.flowable.bpmn.constants.BpmnXMLConstants;
1920
import org.flowable.bpmn.converter.util.BpmnXMLUtil;
2021
import org.flowable.bpmn.model.BaseElement;
2122
import org.flowable.bpmn.model.BpmnModel;
@@ -66,6 +67,9 @@ protected void writeAdditionalChildElements(BaseElement element, BpmnModel model
6667
if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
6768
xtw.writeStartElement(ELEMENT_FLOW_CONDITION);
6869
xtw.writeAttribute(XSI_PREFIX, XSI_NAMESPACE, "type", "tFormalExpression");
70+
if (sequenceFlow.getConditionLanguage() != null) {
71+
BpmnXMLUtil.writeDefaultAttribute(BpmnXMLConstants.ATTRIBUTE_SCRIPT_LANGUAGE, sequenceFlow.getConditionLanguage(), xtw);
72+
}
6973
xtw.writeCData(sequenceFlow.getConditionExpression());
7074
xtw.writeEndElement();
7175
}

modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/child/ConditionExpressionParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ public String getElementName() {
3030

3131
@Override
3232
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
33-
if (!(parentElement instanceof SequenceFlow)) {
33+
if (!(parentElement instanceof SequenceFlow sequenceFlow)) {
3434
return;
3535
}
3636

37-
((SequenceFlow) parentElement).setConditionExpression(xtr.getElementText().trim());
37+
sequenceFlow.setConditionLanguage(xtr.getAttributeValue(null, ATTRIBUTE_SCRIPT_LANGUAGE));
38+
sequenceFlow.setConditionExpression(xtr.getElementText().trim());
3839
}
3940
}

modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/child/ConditionParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public String getElementName() {
3030

3131
@Override
3232
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
33-
if (!(parentElement instanceof ConditionalEventDefinition)) {
33+
if (!(parentElement instanceof ConditionalEventDefinition conditionalEventDefinition)) {
3434
return;
3535
}
3636

37-
((ConditionalEventDefinition) parentElement).setConditionExpression(xtr.getElementText().trim());
37+
conditionalEventDefinition.setConditionLanguage(xtr.getAttributeValue(null, ATTRIBUTE_SCRIPT_LANGUAGE));
38+
conditionalEventDefinition.setConditionExpression(xtr.getElementText().trim());
3839
}
3940

4041
@Override

modules/flowable-bpmn-model/src/main/java/org/flowable/bpmn/model/ConditionalEventDefinition.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public class ConditionalEventDefinition extends EventDefinition {
1919

2020
protected String conditionExpression;
21+
protected String conditionLanguage;
2122

2223
public String getConditionExpression() {
2324
return conditionExpression;
@@ -27,6 +28,14 @@ public void setConditionExpression(String conditionExpression) {
2728
this.conditionExpression = conditionExpression;
2829
}
2930

31+
public String getConditionLanguage() {
32+
return conditionLanguage;
33+
}
34+
35+
public void setConditionLanguage(String conditionLanguage) {
36+
this.conditionLanguage = conditionLanguage;
37+
}
38+
3039
@Override
3140
public ConditionalEventDefinition clone() {
3241
ConditionalEventDefinition clone = new ConditionalEventDefinition();
@@ -37,5 +46,6 @@ public ConditionalEventDefinition clone() {
3746
public void setValues(ConditionalEventDefinition otherDefinition) {
3847
super.setValues(otherDefinition);
3948
setConditionExpression(otherDefinition.getConditionExpression());
49+
setConditionLanguage(otherDefinition.getConditionLanguage());
4050
}
4151
}

modules/flowable-bpmn-model/src/main/java/org/flowable/bpmn/model/SequenceFlow.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
public class SequenceFlow extends FlowElement {
2525

2626
protected String conditionExpression;
27+
protected String conditionLanguage;
2728
protected String sourceRef;
2829
protected String targetRef;
2930
protected String skipExpression;
@@ -60,6 +61,14 @@ public void setConditionExpression(String conditionExpression) {
6061
this.conditionExpression = conditionExpression;
6162
}
6263

64+
public String getConditionLanguage() {
65+
return conditionLanguage;
66+
}
67+
68+
public void setConditionLanguage(String conditionLanguage) {
69+
this.conditionLanguage = conditionLanguage;
70+
}
71+
6372
public String getSourceRef() {
6473
return sourceRef;
6574
}
@@ -123,6 +132,7 @@ public SequenceFlow clone() {
123132
public void setValues(SequenceFlow otherFlow) {
124133
super.setValues(otherFlow);
125134
setConditionExpression(otherFlow.getConditionExpression());
135+
setConditionLanguage(otherFlow.getConditionLanguage());
126136
setSourceRef(otherFlow.getSourceRef());
127137
setTargetRef(otherFlow.getTargetRef());
128138
setSkipExpression(otherFlow.getSkipExpression());

modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/FlowableConditionalEvent.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ public interface FlowableConditionalEvent extends FlowableActivityEvent {
2424
*/
2525
String getConditionExpression();
2626

27+
/**
28+
* @return the scripting language of the condition expression.
29+
*/
30+
String getConditionLanguage();
2731
}

modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/impl/FlowableConditionalEventImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
public class FlowableConditionalEventImpl extends FlowableActivityEventImpl implements FlowableConditionalEvent {
2222

2323
protected String conditionExpression;
24+
protected String conditionLanguage;
2425

2526
public FlowableConditionalEventImpl(FlowableEngineEventType type) {
2627
super(type);
@@ -34,4 +35,12 @@ public String getConditionExpression() {
3435
public void setConditionExpression(String conditionExpression) {
3536
this.conditionExpression = conditionExpression;
3637
}
38+
39+
public String getConditionLanguage() {
40+
return conditionLanguage;
41+
}
42+
43+
public void setConditionLanguage(String conditionLanguage) {
44+
this.conditionLanguage = conditionLanguage;
45+
}
3746
}

modules/flowable-engine/src/main/java/org/flowable/engine/delegate/event/impl/FlowableEventBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public static FlowableMessageEvent createMessageEvent(FlowableEngineEventType ty
368368
return newEvent;
369369
}
370370

371-
public static FlowableConditionalEvent createConditionalEvent(FlowableEngineEventType type, String activityId, String conditionExpression,
371+
public static FlowableConditionalEvent createConditionalEvent(FlowableEngineEventType type, String activityId, String conditionExpression, String conditionLanguage,
372372
String executionId, String processInstanceId, String processDefinitionId) {
373373

374374
FlowableConditionalEventImpl newEvent = new FlowableConditionalEventImpl(type);
@@ -377,6 +377,7 @@ public static FlowableConditionalEvent createConditionalEvent(FlowableEngineEven
377377
newEvent.setProcessDefinitionId(processDefinitionId);
378378
newEvent.setProcessInstanceId(processInstanceId);
379379
newEvent.setConditionExpression(conditionExpression);
380+
newEvent.setConditionLanguage(conditionLanguage);
380381
return newEvent;
381382
}
382383

modules/flowable-engine/src/main/java/org/flowable/engine/impl/Condition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
*/
2323
public interface Condition extends Serializable {
2424

25-
boolean evaluate(String sequenceFlowId, DelegateExecution execution);
25+
boolean evaluate(String elementId, DelegateExecution execution);
2626
}

0 commit comments

Comments
 (0)