-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(broker-core): add support for event-based gateway
* validate and transform event-based gateways * open subscriptions when gateway is activated * close subscriptions when first event is triggered or scope is terminated * uniform the sequence flow step handlers * register the BPMN step processor for all workflow instance events * rename BPMN element transformers from *handler to *transformer
- Loading branch information
Showing
50 changed files
with
853 additions
and
413 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...-model/src/main/java/io/zeebe/model/bpmn/validation/zeebe/EventBasedGatewayValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright © 2017 camunda services GmbH (info@camunda.com) | ||
* | ||
* 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 io.zeebe.model.bpmn.validation.zeebe; | ||
|
||
import io.zeebe.model.bpmn.instance.EventBasedGateway; | ||
import io.zeebe.model.bpmn.instance.EventDefinition; | ||
import io.zeebe.model.bpmn.instance.FlowNode; | ||
import io.zeebe.model.bpmn.instance.IntermediateCatchEvent; | ||
import io.zeebe.model.bpmn.instance.MessageEventDefinition; | ||
import io.zeebe.model.bpmn.instance.SequenceFlow; | ||
import io.zeebe.model.bpmn.instance.TimerEventDefinition; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.camunda.bpm.model.xml.validation.ModelElementValidator; | ||
import org.camunda.bpm.model.xml.validation.ValidationResultCollector; | ||
|
||
public class EventBasedGatewayValidator implements ModelElementValidator<EventBasedGateway> { | ||
|
||
private static final List<Class<? extends EventDefinition>> SUPPORTED_EVENTS = | ||
Arrays.asList(TimerEventDefinition.class, MessageEventDefinition.class); | ||
|
||
private static final String ERROR_UNSUPPORTED_TARGET_NODE = | ||
"Event-based gateway must not have an outgoing sequence flow to other elements than message/timer intermediate catch events."; | ||
|
||
@Override | ||
public Class<EventBasedGateway> getElementType() { | ||
return EventBasedGateway.class; | ||
} | ||
|
||
@Override | ||
public void validate( | ||
EventBasedGateway element, ValidationResultCollector validationResultCollector) { | ||
|
||
final Collection<SequenceFlow> outgoingSequenceFlows = element.getOutgoing(); | ||
|
||
if (outgoingSequenceFlows.size() < 2) { | ||
validationResultCollector.addError( | ||
0, "Event-based gateway must have at least 2 outgoing sequence flows."); | ||
} | ||
|
||
final boolean isValid = | ||
outgoingSequenceFlows.stream().allMatch(this::isValidOutgoingSequenceFlow); | ||
if (!isValid) { | ||
validationResultCollector.addError(0, ERROR_UNSUPPORTED_TARGET_NODE); | ||
} | ||
} | ||
|
||
private boolean isValidOutgoingSequenceFlow(SequenceFlow flow) { | ||
final FlowNode targetNode = flow.getTarget(); | ||
|
||
if (targetNode instanceof IntermediateCatchEvent) { | ||
return isValidEvent((IntermediateCatchEvent) targetNode); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
private boolean isValidEvent(final IntermediateCatchEvent event) { | ||
final Collection<EventDefinition> eventDefinitions = event.getEventDefinitions(); | ||
|
||
if (eventDefinitions.size() != 1) { | ||
return false; | ||
|
||
} else { | ||
final EventDefinition eventDefinition = eventDefinitions.iterator().next(); | ||
return SUPPORTED_EVENTS | ||
.stream() | ||
.anyMatch(e -> e.isAssignableFrom(eventDefinition.getClass())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...el/src/test/java/io/zeebe/model/bpmn/validation/ZeebeEventBasedGatewayValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright © 2017 camunda services GmbH (info@camunda.com) | ||
* | ||
* 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 io.zeebe.model.bpmn.validation; | ||
|
||
import static io.zeebe.model.bpmn.validation.ExpectedValidationResult.expect; | ||
import static java.util.Collections.singletonList; | ||
|
||
import io.zeebe.model.bpmn.Bpmn; | ||
import io.zeebe.model.bpmn.instance.EventBasedGateway; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
public class ZeebeEventBasedGatewayValidationTest extends AbstractZeebeValidationTest { | ||
|
||
@Parameters(name = "{index}: {1}") | ||
public static Object[][] parameters() { | ||
return new Object[][] { | ||
{ | ||
Bpmn.createExecutableProcess("process") | ||
.startEvent() | ||
.eventBasedGateway() | ||
.intermediateCatchEvent() | ||
.timerWithDuration("PT1M") | ||
.done(), | ||
singletonList( | ||
expect( | ||
EventBasedGateway.class, | ||
"Event-based gateway must have at least 2 outgoing sequence flows.")) | ||
}, | ||
{ | ||
Bpmn.createExecutableProcess("process") | ||
.startEvent() | ||
.eventBasedGateway() | ||
.receiveTask() | ||
.message(m -> m.name("this").zeebeCorrelationKey("$.foo")) | ||
.moveToLastGateway() | ||
.receiveTask() | ||
.message(m -> m.name("that").zeebeCorrelationKey("$.foo")) | ||
.done(), | ||
singletonList( | ||
expect( | ||
EventBasedGateway.class, | ||
"Event-based gateway must not have an outgoing sequence flow to other elements than message/timer intermediate catch events.")) | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
broker-core/src/main/java/io/zeebe/broker/workflow/model/element/ExecutableCatchEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Zeebe Broker Core | ||
* Copyright © 2017 camunda services GmbH (info@camunda.com) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package io.zeebe.broker.workflow.model.element; | ||
|
||
import java.time.Duration; | ||
|
||
public interface ExecutableCatchEvent extends ExecutableFlowElement { | ||
|
||
boolean isTimer(); | ||
|
||
boolean isMessage(); | ||
|
||
ExecutableMessage getMessage(); | ||
|
||
Duration getDuration(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.