diff --git a/modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/child/VariableListenerEventDefinitionParser.java b/modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/child/VariableListenerEventDefinitionParser.java index bc07aeed387..02dbb8779e6 100644 --- a/modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/child/VariableListenerEventDefinitionParser.java +++ b/modules/flowable-bpmn-converter/src/main/java/org/flowable/bpmn/converter/child/VariableListenerEventDefinitionParser.java @@ -43,7 +43,7 @@ public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, Bp String variableName = xtr.getAttributeValue(null, ATTRIBUTE_VARIABLE_NAME); if (StringUtils.isEmpty(variableName)) { - throw new FlowableException("variable name is required for variable listener with activity id " + parentElement.getId()); + LOGGER.warn("variable name is required for variable listener with activity id {}", parentElement.getId()); } eventDefinition.setVariableName(variableName); diff --git a/modules/flowable-bpmn-converter/src/test/java/org/flowable/editor/language/xml/VariableListenerEventDefinitionParserTest.java b/modules/flowable-bpmn-converter/src/test/java/org/flowable/editor/language/xml/VariableListenerEventDefinitionParserTest.java new file mode 100644 index 00000000000..28c4d1ddbe9 --- /dev/null +++ b/modules/flowable-bpmn-converter/src/test/java/org/flowable/editor/language/xml/VariableListenerEventDefinitionParserTest.java @@ -0,0 +1,39 @@ +/* Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.flowable.editor.language.xml; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.flowable.bpmn.constants.BpmnXMLConstants.ELEMENT_EVENT_VARIABLELISTENERDEFINITION; + +import org.flowable.bpmn.model.BpmnModel; +import org.flowable.bpmn.model.EventSubProcess; +import org.flowable.bpmn.model.FlowElement; +import org.flowable.bpmn.model.StartEvent; +import org.flowable.editor.language.xml.util.BpmnXmlConverterTest; + +class VariableListenerEventDefinitionParserTest { + + @BpmnXmlConverterTest("missingVariableListenerVariableName.bpmn") + void validateModel(BpmnModel model) { + + FlowElement flowElement = model.getMainProcess().getFlowElement("eventSubProcess"); + assertThat(flowElement).isInstanceOf(EventSubProcess.class); + EventSubProcess subProcess = (EventSubProcess) flowElement; + assertThat(subProcess.getId()).isEqualTo("eventSubProcess"); + flowElement = subProcess.getFlowElement("variableListenerStartEvent"); + assertThat(flowElement).isInstanceOf(StartEvent.class); + StartEvent startEvent = (StartEvent) flowElement; + assertThat(startEvent.getId()).isEqualTo("variableListenerStartEvent"); + assertThat(startEvent.getExtensionElements().get(ELEMENT_EVENT_VARIABLELISTENERDEFINITION)).isNull(); + } +} diff --git a/modules/flowable-bpmn-converter/src/test/resources/missingVariableListenerVariableName.bpmn b/modules/flowable-bpmn-converter/src/test/resources/missingVariableListenerVariableName.bpmn new file mode 100644 index 00000000000..5767c97604d --- /dev/null +++ b/modules/flowable-bpmn-converter/src/test/resources/missingVariableListenerVariableName.bpmn @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-engine/src/test/java/org/flowable/standalone/validation/DefaultProcessValidatorTest.java b/modules/flowable-engine/src/test/java/org/flowable/standalone/validation/DefaultProcessValidatorTest.java index 2dcfe13237f..141501c7583 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/standalone/validation/DefaultProcessValidatorTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/standalone/validation/DefaultProcessValidatorTest.java @@ -422,6 +422,26 @@ void testMailTask() { tuple(Problems.MAIL_TASK_NO_RECIPIENT, "No recipient is defined on the mail activity", "sendMailWithoutanything", false) ); } + + @Test + public void testEventSubProcessWithoutVariableName() throws Exception { + + InputStream xmlStream = this.getClass().getClassLoader() + .getResourceAsStream("org/flowable/engine/test/validation/missingVariableEventListenerVariableName.xml"); + XMLInputFactory xif = XMLInputFactory.newInstance(); + InputStreamReader in = new InputStreamReader(xmlStream, StandardCharsets.UTF_8); + XMLStreamReader xtr = xif.createXMLStreamReader(in); + BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr); + assertThat(bpmnModel).isNotNull(); + + List allErrors = processValidator.validate(bpmnModel); + assertThat(allErrors).hasSize(1); + ValidationError error = allErrors.get(0); + assertThat(error.getProblem()).isEqualTo(Problems.EVENT_SUBPROCESS_INVALID_START_EVENT_VARIABLE_NAME); + assertThat(error.getDefaultDescription()).isEqualTo("variable name is required for variable listener with activity id variableListenerStartEvent"); + + } + protected void assertCommonProblemFieldForActivity(ValidationError error) { assertProcessElementError(error); diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/validation/missingVariableEventListenerVariableName.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/validation/missingVariableEventListenerVariableName.xml new file mode 100644 index 00000000000..0f487a5d46a --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/validation/missingVariableEventListenerVariableName.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/Problems.java b/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/Problems.java index f5926e81d0d..02da32da9e0 100644 --- a/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/Problems.java +++ b/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/Problems.java @@ -90,6 +90,7 @@ public interface Problems { String SUBPROCESS_START_EVENT_EVENT_DEFINITION_NOT_ALLOWED = "flowable-subprocess-start-event-event-definition-not-allowed"; String EVENT_SUBPROCESS_INVALID_START_EVENT_DEFINITION = "flowable-event-subprocess-invalid-start-event-definition"; + String EVENT_SUBPROCESS_INVALID_START_EVENT_VARIABLE_NAME = "flowable-event-subprocess-invalid-start-event-variable-name"; String EVENT_SUBPROCESS_BOUNDARY_EVENT = "flowable-event-subprocess-boundary-event"; String BOUNDARY_EVENT_NO_EVENT_DEFINITION = "flowable-boundary-event-no-event-definition"; diff --git a/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/impl/EventSubprocessValidator.java b/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/impl/EventSubprocessValidator.java index 648fa205b38..e95f9495e90 100644 --- a/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/impl/EventSubprocessValidator.java +++ b/modules/flowable-process-validation/src/main/java/org/flowable/validation/validator/impl/EventSubprocessValidator.java @@ -14,6 +14,7 @@ import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.flowable.bpmn.model.BoundaryEvent; import org.flowable.bpmn.model.BpmnModel; import org.flowable.bpmn.model.ConditionalEventDefinition; @@ -56,6 +57,12 @@ protected void executeValidation(BpmnModel bpmnModel, Process process, List