-
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(bpmn-model): enable non-interrupting time cycle boundary events
- allow different support levels for boundary events - refactor event definition validations to their respective validators - add utility classes to parse repeating time intervals
- Loading branch information
Showing
13 changed files
with
695 additions
and
96 deletions.
There are no files selected for viewing
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
106 changes: 106 additions & 0 deletions
106
bpmn-model/src/main/java/io/zeebe/model/bpmn/util/time/Interval.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,106 @@ | ||
/* | ||
* 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.util.time; | ||
|
||
import java.time.Duration; | ||
import java.time.Period; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.Objects; | ||
|
||
/** Combines {@link java.time.Period}, and {@link java.time.Duration} */ | ||
public class Interval { | ||
private final Period period; | ||
private final Duration duration; | ||
|
||
public Interval(Period period, Duration duration) { | ||
this.period = period; | ||
this.duration = duration; | ||
} | ||
|
||
public Period getPeriod() { | ||
return period; | ||
} | ||
|
||
public Duration getDuration() { | ||
return duration; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (!(o instanceof Interval)) { | ||
return false; | ||
} | ||
|
||
final Interval interval = (Interval) o; | ||
return Objects.equals(getPeriod(), interval.getPeriod()) | ||
&& Objects.equals(getDuration(), interval.getDuration()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getPeriod(), getDuration()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (period.isZero()) { | ||
return duration.toString(); | ||
} | ||
|
||
if (duration.isZero()) { | ||
return period.toString(); | ||
} | ||
|
||
return period.toString() + duration.toString().substring(1); | ||
} | ||
|
||
/** | ||
* Only supports a subset of ISO8601, combining both period and duration. | ||
* | ||
* @param text ISO8601 conforming interval expression | ||
* @return parsed interval | ||
*/ | ||
public static Interval parse(String text) { | ||
final int timeOffset = text.lastIndexOf("T"); | ||
final Period period; | ||
final Duration duration; | ||
|
||
// to remain consistent with normal duration parsing which requires a duration to start with P | ||
if (text.charAt(0) != 'P') { | ||
throw new DateTimeParseException("Must start with P", text, 0); | ||
} | ||
|
||
if (timeOffset > 0) { | ||
duration = Duration.parse(String.format("P%S", text.substring(timeOffset))); | ||
} else { | ||
duration = Duration.ZERO; | ||
} | ||
|
||
if (timeOffset == -1) { | ||
period = Period.parse(text); | ||
} else if (timeOffset > 1) { | ||
period = Period.parse(text.substring(0, timeOffset)); | ||
} else { | ||
period = Period.ZERO; | ||
} | ||
|
||
return new Interval(period, duration); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
bpmn-model/src/main/java/io/zeebe/model/bpmn/util/time/RepeatingInterval.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,109 @@ | ||
/* | ||
* 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.util.time; | ||
|
||
import java.time.format.DateTimeParseException; | ||
import java.util.Objects; | ||
|
||
public class RepeatingInterval { | ||
public static final String INTERVAL_DESGINATOR = "/"; | ||
public static final int INFINITE = -1; | ||
|
||
private final int repetitions; | ||
private final Interval interval; | ||
|
||
public RepeatingInterval(int repetitions, Interval interval) { | ||
this.repetitions = repetitions; | ||
this.interval = interval; | ||
} | ||
|
||
public int getRepetitions() { | ||
return repetitions; | ||
} | ||
|
||
public Interval getInterval() { | ||
return interval; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
|
||
if (!(o instanceof RepeatingInterval)) { | ||
return false; | ||
} | ||
|
||
final RepeatingInterval repeatingInterval = (RepeatingInterval) o; | ||
|
||
return getRepetitions() == repeatingInterval.getRepetitions() | ||
&& Objects.equals(getInterval(), repeatingInterval.getInterval()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getRepetitions(), getInterval()); | ||
} | ||
|
||
public static RepeatingInterval parse(String text) { | ||
return parse(text, INTERVAL_DESGINATOR); | ||
} | ||
|
||
/** | ||
* Parses a repeating interval as two parts, separated by a given interval designator. | ||
* | ||
* <p>The first part describes how often the interval should be repeated, and the second part is | ||
* the interval itself; see {@link Interval#parse(String)} for more on parsing the interval. | ||
* | ||
* <p>The repeating part is conform to the following format: R[0-9]* | ||
* | ||
* <p>If given an interval with, e.g. the interval designator is not present in the text, it is | ||
* assumed implicitly that the interval is meant to be repeated infinitely. | ||
* | ||
* @param text text to parse | ||
* @param intervalDesignator the separator between the repeating and interval texts | ||
* @return a RepeatingInterval based on the given text | ||
*/ | ||
public static RepeatingInterval parse(String text, String intervalDesignator) { | ||
final int intervalDesignatorOffset = text.indexOf(intervalDesignator); | ||
int repetitions = INFINITE; | ||
final Interval interval; | ||
|
||
if (text.charAt(0) != 'R') { | ||
throw new DateTimeParseException("Repetition spec must start with R", text, 0); | ||
} | ||
|
||
if (intervalDesignatorOffset == -1 || intervalDesignatorOffset == text.length() - 1) { | ||
throw new DateTimeParseException("No interval given", text, intervalDesignatorOffset); | ||
} | ||
|
||
final String intervalText = text.substring(intervalDesignatorOffset + 1); | ||
interval = Interval.parse(intervalText); | ||
|
||
if (intervalDesignatorOffset > 1) { | ||
final String repetitionsText = text.substring(1, intervalDesignatorOffset); | ||
|
||
try { | ||
repetitions = Integer.parseInt(repetitionsText); | ||
} catch (NumberFormatException e) { | ||
throw new DateTimeParseException("Cannot parse repetitions count", repetitionsText, 1, e); | ||
} | ||
} | ||
|
||
return new RepeatingInterval(repetitions, interval); | ||
} | ||
} |
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
75 changes: 0 additions & 75 deletions
75
bpmn-model/src/main/java/io/zeebe/model/bpmn/validation/zeebe/CatchEventValidator.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.