Skip to content

Commit 215b9cc

Browse files
added FormAwareServiceTask for CMMN and BPMN (#4011)
* added FormAwareServiceTask for CMMN and BPMN * added bpmn and cmmn parse handler * added dedicated ParseHandler form FormAwareServiceTasks
1 parent 706e10f commit 215b9cc

File tree

54 files changed

+2384
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2384
-111
lines changed

modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/constants/BpmnXMLConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public interface BpmnXMLConstants {
8585
public static final String ELEMENT_EVENT_LISTENER = "eventListener";
8686
public static final String ELEMENT_TASK_LISTENER = "taskListener";
8787
public static final String ELEMENT_SCRIPT = "script";
88+
public static final String ELEMENT_FORM_REFERENCE = "formreference";
8889
public static final String ATTRIBUTE_LISTENER_EVENT = "event";
8990
public static final String ATTRIBUTE_LISTENER_EVENTS = "events";
9091
public static final String ATTRIBUTE_LISTENER_ENTITY_TYPE = "entityType";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public class BpmnXMLConverter implements BpmnXMLConstants {
152152
addConverter(new ServiceTaskXMLConverter());
153153
addConverter(new HttpServiceTaskXMLConverter());
154154
addConverter(new CaseServiceTaskXMLConverter());
155+
addConverter(new FormAwareServiceTaskXMLConverter());
155156
addConverter(new SendEventServiceTaskXMLConverter());
156157
addConverter(new ExternalWorkerServiceTaskXMLConverter());
157158
addConverter(new SendTaskXMLConverter());
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.bpmn.converter;
14+
15+
import org.flowable.bpmn.model.BaseElement;
16+
import org.flowable.bpmn.model.FormAwareServiceTask;
17+
18+
/**
19+
* @author Christopher Welsch
20+
*/
21+
public class FormAwareServiceTaskXMLConverter extends ServiceTaskXMLConverter {
22+
23+
@Override
24+
public Class<? extends BaseElement> getBpmnElementType() {
25+
return FormAwareServiceTask.class;
26+
}
27+
}

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.flowable.bpmn.model.ExtensionAttribute;
4242
import org.flowable.bpmn.model.ExtensionElement;
4343
import org.flowable.bpmn.model.ExternalWorkerServiceTask;
44+
import org.flowable.bpmn.model.FormAwareServiceTask;
4445
import org.flowable.bpmn.model.HttpServiceTask;
4546
import org.flowable.bpmn.model.ImplementationType;
4647
import org.flowable.bpmn.model.SendEventServiceTask;
@@ -130,7 +131,19 @@ protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model)
130131
serviceTask = new ExternalWorkerServiceTask();
131132

132133
} else {
133-
serviceTask = new ServiceTask();
134+
String formKey = BpmnXMLUtil.getAttributeValue(ATTRIBUTE_FORM_FORMKEY, xtr);
135+
if (StringUtils.isNotEmpty(formKey)) {
136+
FormAwareServiceTask formAwareServiceTask = new FormAwareServiceTask();
137+
formAwareServiceTask.setFormKey(formKey);
138+
139+
String formFieldValidation = BpmnXMLUtil.getAttributeValue(ATTRIBUTE_FORM_FIELD_VALIDATION, xtr);
140+
if (StringUtils.isNotEmpty(formFieldValidation)) {
141+
formAwareServiceTask.setValidateFormFields(formFieldValidation);
142+
}
143+
serviceTask = formAwareServiceTask;
144+
} else {
145+
serviceTask = new ServiceTask();
146+
}
134147
}
135148

136149
BpmnXMLUtil.addXMLLocation(serviceTask, xtr);
@@ -179,7 +192,6 @@ protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model)
179192
} else {
180193
parseChildElements(getXMLElementName(), serviceTask, model, xtr);
181194
}
182-
183195
return serviceTask;
184196
}
185197

@@ -198,6 +210,9 @@ protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, X
198210
writeHttpServiceTaskAdditionalAttributes((HttpServiceTask) element, model, xtw);
199211

200212
} else {
213+
if (element instanceof FormAwareServiceTask formAwareServiceTask) {
214+
writeFormAwareServiceTaskAdditionalAttributes(formAwareServiceTask, xtw);
215+
}
201216
writeServiceTaskAdditionalAttributes((ServiceTask) element, xtw);
202217
}
203218
}
@@ -273,6 +288,16 @@ protected void writeHttpServiceTaskAdditionalAttributes(HttpServiceTask httpServ
273288
writeServiceTaskAdditionalAttributes(httpServiceTask, xtw);
274289
}
275290

291+
protected void writeFormAwareServiceTaskAdditionalAttributes(FormAwareServiceTask formAwareServiceTask, XMLStreamWriter xtw) throws Exception {
292+
if (StringUtils.isNotEmpty(formAwareServiceTask.getFormKey())) {
293+
writeQualifiedAttribute(ATTRIBUTE_FORM_FORMKEY, formAwareServiceTask.getFormKey(), xtw);
294+
}
295+
296+
if (StringUtils.isNotEmpty(formAwareServiceTask.getValidateFormFields())) {
297+
writeQualifiedAttribute(ATTRIBUTE_FORM_FIELD_VALIDATION, formAwareServiceTask.getValidateFormFields(), xtw);
298+
}
299+
}
300+
276301
protected void writeServiceTaskAdditionalAttributes(ServiceTask element, XMLStreamWriter xtw) throws Exception {
277302
ServiceTask serviceTask = element;
278303

modules/flowable-bpmn-converter/src/main/resources/org/flowable/impl/bpmn/parser/flowable-bpmn-extensions.xsd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<attribute name="formKey" type="string">
5656
<annotation>
5757
<documentation>
58-
Attribute used on a startEvent or a userTask.
58+
Attribute used on a startEvent, userTask or serviceTask.
5959
The value can be anything. The default form support in Flowable
6060
assumes that this is a reference to a form html file used in the deployment
6161
of the process definition. But this key can also be something completely different,
@@ -81,7 +81,7 @@
8181
Allows to specify a custom class that will be called during the parsing
8282
of the form information. This way, it is possible to use custom forms and form handling.
8383
This class must implement the
84-
org.activiti.engine.inpl.form.FormHamdler/StartFormHandler/taskFormHandler interface
84+
org.activiti.engine.impl.form.FormHandler/StartFormHandler/taskFormHandler interface
8585
(specific interface depending on the activity).
8686
</documentation>
8787
</annotation>
@@ -96,8 +96,8 @@
9696
<element name="formProperty">
9797
<annotation>
9898
<documentation>
99-
Subelement of the extensionsElement of activities that support forms.
100-
Allows to specifies properties (!= process variables) for a form. See documentation chapter on
99+
Sub element of the extensionsElement of activities that support forms.
100+
Allows to specify properties (!= process variables) for a form. See documentation chapter on
101101
form properties.
102102
</documentation>
103103
</annotation>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.editor.language.xml;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
import static org.assertj.core.api.Assertions.tuple;
17+
18+
import org.flowable.bpmn.model.BpmnModel;
19+
import org.flowable.bpmn.model.FieldExtension;
20+
import org.flowable.bpmn.model.FlowElement;
21+
import org.flowable.bpmn.model.FormAwareServiceTask;
22+
import org.flowable.editor.language.xml.util.BpmnXmlConverterTest;
23+
24+
class FormAwareServiceTaskConverterTest {
25+
26+
@BpmnXmlConverterTest("formAwareServiceTask.bpmn")
27+
void validateModelWithFormReference(BpmnModel model) {
28+
FlowElement flowElement = model.getMainProcess().getFlowElement("servicetask");
29+
assertThat(flowElement)
30+
.isInstanceOfSatisfying(FormAwareServiceTask.class, formAwareServiceTask -> {
31+
assertThat(formAwareServiceTask.getId()).isEqualTo("servicetask");
32+
assertThat(formAwareServiceTask.getName()).isEqualTo("FormAwareServiceTask");
33+
assertThat(formAwareServiceTask.getImplementation())
34+
.isEqualTo("${delegateExpression}");
35+
assertThat(formAwareServiceTask.getImplementationType())
36+
.isEqualTo("delegateExpression");
37+
assertThat(formAwareServiceTask.getValidateFormFields())
38+
.isEqualTo("true");
39+
assertThat(formAwareServiceTask.getFormKey())
40+
.isEqualTo("someFormKey");
41+
});
42+
}
43+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:design="http://flowable.org/design" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://flowable.org/test" design:palette="flowable-work-process-palette">
3+
4+
<process id="process" name="process1" isExecutable="true">
5+
<endEvent id="end"></endEvent>
6+
<sequenceFlow id="flow1" sourceRef="start" targetRef="servicetask"></sequenceFlow>
7+
<serviceTask id="servicetask" name="FormAwareServiceTask" flowable:delegateExpression="${delegateExpression}" flowable:formKey="someFormKey" flowable:formFieldValidation="true">
8+
9+
</serviceTask>
10+
<startEvent id="start"></startEvent>
11+
<sequenceFlow id="flow2" sourceRef="servicetask" targetRef="end"></sequenceFlow>
12+
</process>
13+
</definitions>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.bpmn.model;
14+
15+
import java.util.List;
16+
17+
/**
18+
* @author Christopher Welsch
19+
*/
20+
public class FormAwareServiceTask extends ServiceTask implements HasValidateFormFields {
21+
22+
protected String validateFormFields;
23+
protected String formKey;
24+
25+
@Override
26+
public String getValidateFormFields() {
27+
return validateFormFields;
28+
}
29+
30+
@Override
31+
public void setValidateFormFields(String validateFormFields) {
32+
this.validateFormFields = validateFormFields;
33+
}
34+
35+
public String getFormKey() {
36+
return formKey;
37+
}
38+
39+
public void setFormKey(String formKey) {
40+
this.formKey = formKey;
41+
}
42+
}

modules/flowable-cmmn-converter/src/main/java/org/flowable/cmmn/converter/TaskXmlConverter.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.flowable.cmmn.model.CasePageTask;
2222
import org.flowable.cmmn.model.CmmnElement;
2323
import org.flowable.cmmn.model.ExternalWorkerServiceTask;
24+
import org.flowable.cmmn.model.FormAwareServiceTask;
2425
import org.flowable.cmmn.model.HttpServiceTask;
2526
import org.flowable.cmmn.model.ImplementationType;
2627
import org.flowable.cmmn.model.ScriptServiceTask;
@@ -52,7 +53,21 @@ protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHe
5253
if (type != null) {
5354

5455
if (Objects.equals(type, ServiceTask.JAVA_TASK)) {
55-
task = convertToJavaServiceTask(xtr, className);
56+
String formKey = xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_FORM_KEY);
57+
ServiceTask serviceTask;
58+
59+
if (StringUtils.isNotEmpty(formKey)) {
60+
FormAwareServiceTask formAwareServiceTask = new FormAwareServiceTask();
61+
formAwareServiceTask.setFormKey(formKey);
62+
formAwareServiceTask.setValidateFormFields(
63+
xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_FORM_FIELD_VALIDATION));
64+
serviceTask = formAwareServiceTask;
65+
} else {
66+
serviceTask = new ServiceTask();
67+
}
68+
69+
convertToJavaServiceTask(xtr, className, serviceTask);
70+
task = serviceTask;
5671

5772
} else if (Objects.equals(type, HttpServiceTask.HTTP_TASK)) {
5873
task = convertToHttpTask(xtr, className);
@@ -83,8 +98,7 @@ protected CmmnElement convert(XMLStreamReader xtr, ConversionHelper conversionHe
8398
return task;
8499
}
85100

86-
protected Task convertToJavaServiceTask(XMLStreamReader xtr, String className) {
87-
ServiceTask serviceTask = new ServiceTask();
101+
protected void convertToJavaServiceTask(XMLStreamReader xtr, String className, ServiceTask serviceTask) {
88102
serviceTask.setType(ServiceTask.JAVA_TASK);
89103

90104
String expression = xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_EXPRESSION);
@@ -110,7 +124,6 @@ protected Task convertToJavaServiceTask(XMLStreamReader xtr, String className) {
110124
serviceTask.setStoreResultVariableAsTransient(
111125
Boolean.parseBoolean(xtr.getAttributeValue(CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE, CmmnXmlConstants.ATTRIBUTE_STORE_RESULT_AS_TRANSIENT)));
112126

113-
return serviceTask;
114127
}
115128

116129
protected Task convertToHttpTask(XMLStreamReader xtr, String className) {

modules/flowable-cmmn-converter/src/main/java/org/flowable/cmmn/converter/export/AbstractServiceTaskExport.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.commons.lang3.StringUtils;
1818
import org.flowable.cmmn.converter.CmmnXmlConverterOptions;
1919
import org.flowable.cmmn.model.CmmnModel;
20+
import org.flowable.cmmn.model.FormAwareServiceTask;
2021
import org.flowable.cmmn.model.HttpServiceTask;
2122
import org.flowable.cmmn.model.ImplementationType;
2223
import org.flowable.cmmn.model.ScriptServiceTask;
@@ -118,4 +119,26 @@ protected Class<? extends ServiceTask> getExportablePlanItemDefinitionClass() {
118119
return ScriptServiceTask.class;
119120
}
120121
}
122+
123+
public static class FormAwareServiceTaskExport extends AbstractServiceTaskExport<FormAwareServiceTask> {
124+
125+
@Override
126+
protected Class<? extends ServiceTask> getExportablePlanItemDefinitionClass() {
127+
return FormAwareServiceTask.class;
128+
}
129+
130+
@Override
131+
public void writePlanItemDefinitionSpecificAttributes(ServiceTask serviceTask, XMLStreamWriter xtw) throws Exception {
132+
super.writePlanItemDefinitionSpecificAttributes(serviceTask, xtw);
133+
FormAwareServiceTask formAwareServiceTask = (FormAwareServiceTask) serviceTask;
134+
if (StringUtils.isNotBlank(formAwareServiceTask.getFormKey())) {
135+
xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_FORM_KEY, formAwareServiceTask.getFormKey());
136+
}
137+
if (StringUtils.isNotBlank(formAwareServiceTask.getValidateFormFields())) {
138+
xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_FORM_FIELD_VALIDATION,
139+
formAwareServiceTask.getValidateFormFields());
140+
}
141+
}
142+
}
143+
121144
}

0 commit comments

Comments
 (0)