This is an automated email from the ASF dual-hosted git repository.
pefernan pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-runtimes.git
The following commit(s) were added to refs/heads/main by this push:
new d838551099 [incubator-kie-issues#2230] Fix deadlines parsing errors
(#4177)
d838551099 is described below
commit d838551099a75bdff177ba21b0544e78dd480cc3
Author: Martin Weiler <[email protected]>
AuthorDate: Thu Feb 19 03:57:19 2026 -0700
[incubator-kie-issues#2230] Fix deadlines parsing errors (#4177)
* [incubator-kie-issues#2230] Fix deadlines parsing errors
* Handle minutes(m) and months(M)
---------
Co-authored-by: Jozef Marko <[email protected]>
---
.../kogito/usertask/impl/model/DeadlineHelper.java | 33 ++++++++++++++--
.../usertask/impl/model/DeadlineHelperTest.java | 46 +++++++++++++++++++++-
2 files changed, 74 insertions(+), 5 deletions(-)
diff --git
a/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/DeadlineHelper.java
b/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/DeadlineHelper.java
index 8218a8e978..18b86f0667 100644
---
a/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/DeadlineHelper.java
+++
b/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/DeadlineHelper.java
@@ -29,6 +29,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Matcher;
@@ -130,10 +131,23 @@ public class DeadlineHelper {
private static Collection<ScheduleInfo> getReassignmentSchedule(String
timeStr) {
ScheduleInfo info = new ScheduleInfo();
- if (!timeStr.startsWith("PT")) {
- timeStr = "PT" + timeStr;
+ // Check if it's a shorthand duration (e.g., "1m", "2h")
+ Duration shorthandDuration = parseShorthandDuration(timeStr);
+ if (shorthandDuration != null) {
+ info.setDuration(shorthandDuration);
+ } else if (!timeStr.startsWith("PT") && !timeStr.startsWith("P")) {
+ // If not already prefixed with P or PT, determine which prefix to
use
+ // Check if it contains time components (H, M, S) or date
components (Y, W, D)
+ // Note: M is ambiguous (could be months or minutes), so we check
for T presence
+ if (timeStr.contains("T") || timeStr.matches(".*[0-9]+[HMS].*")) {
+ timeStr = "PT" + timeStr;
+ } else {
+ timeStr = "P" + timeStr;
+ }
+ info.setDuration(parseDuration(timeStr));
+ } else {
+ info.setDuration(parseDuration(timeStr));
}
- info.setDuration(Duration.parse(timeStr));
return Collections.singletonList(info);
}
@@ -254,7 +268,11 @@ public class DeadlineHelper {
Matcher matcher = shorthandDurationPattern.matcher(timeStr);
if (matcher.matches()) {
long value = Long.parseLong(matcher.group(1));
- String unitInput = matcher.group(2).toLowerCase();
+ String unitInput = matcher.group(2);
+ // Only convert to lowercase if it's not 'm' or 'M' (to
distinguish minutes from months)
+ if (!Objects.equals(unitInput, "m") && !Objects.equals(unitInput,
"M")) {
+ unitInput = unitInput.toLowerCase();
+ }
DurationUnit unit = DurationUnit.fromString(unitInput);
if (unit == null) {
throw new IllegalArgumentException("Unknown shorthand duration
unit: " + unitInput);
@@ -295,6 +313,13 @@ public class DeadlineHelper {
return Duration.ofDays(value * 7);
}
},
+ MONTHS("M") {
+ @Override
+ Duration toDuration(long value) {
+ // Convert months to Duration using Period
+ return getDuration(Period.ofMonths((int) value),
Duration.ZERO);
+ }
+ },
YEARS("y") {
@Override
Duration toDuration(long value) {
diff --git
a/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java
b/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java
index 550f52633f..92de0084a3 100644
---
a/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java
+++
b/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java
@@ -239,7 +239,7 @@ public class DeadlineHelperTest {
}
@Test
- public void testReassignment() {
+ public void testReassignmentShorthandMinutes() {
Collection<DeadlineInfo<Reassignment>> reassignments =
DeadlineHelper.parseReassignments(
"[users:Pepe,Pepa|groups:Admin,Managers]@[1m]");
assertThat(reassignments).hasSize(1);
@@ -249,6 +249,50 @@ public class DeadlineHelperTest {
assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofMinutes(1));
}
+ @Test
+ public void testReassignmentMinutes() {
+ Collection<DeadlineInfo<Reassignment>> reassignments =
DeadlineHelper.parseReassignments(
+ "[users:Pepe,Pepa|groups:Admin,Managers]@[PT1M]");
+ assertThat(reassignments).hasSize(1);
+ DeadlineInfo<Reassignment> reassignment =
reassignments.iterator().next();
+
assertThat(reassignment.getNotification().getPotentialUsers()).containsExactlyInAnyOrder("Pepe",
"Pepa");
+
assertThat(reassignment.getNotification().getPotentialGroups()).containsExactlyInAnyOrder("Admin",
"Managers");
+
assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofMinutes(1));
+ }
+
+ @Test
+ public void testReassignmentWithDateBasedDuration() {
+ Collection<DeadlineInfo<Reassignment>> reassignments =
DeadlineHelper.parseReassignments(
+ "[users:John,Jane|groups:Admins]@[365D]");
+ assertThat(reassignments).hasSize(1);
+ DeadlineInfo<Reassignment> reassignment =
reassignments.iterator().next();
+
assertThat(reassignment.getNotification().getPotentialUsers()).containsExactlyInAnyOrder("John",
"Jane");
+
assertThat(reassignment.getNotification().getPotentialGroups()).containsExactlyInAnyOrder("Admins");
+
assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofDays(365));
+ }
+
+ @Test
+ public void testReassignmentShorthandMonths() {
+ Collection<DeadlineInfo<Reassignment>> reassignments =
DeadlineHelper.parseReassignments(
+ "[users:John,Jane|groups:Admins]@[7M]");
+ assertThat(reassignments).hasSize(1);
+ DeadlineInfo<Reassignment> reassignment =
reassignments.iterator().next();
+
assertThat(reassignment.getNotification().getPotentialUsers()).containsExactlyInAnyOrder("John",
"Jane");
+
assertThat(reassignment.getNotification().getPotentialGroups()).containsExactlyInAnyOrder("Admins");
+
assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(DeadlineHelper.getDuration(Period.ofMonths(7),
Duration.ZERO));
+ }
+
+ @Test
+ public void testReassignmentMonths() {
+ Collection<DeadlineInfo<Reassignment>> reassignments =
DeadlineHelper.parseReassignments(
+ "[users:John,Jane|groups:Admins]@[P7M]");
+ assertThat(reassignments).hasSize(1);
+ DeadlineInfo<Reassignment> reassignment =
reassignments.iterator().next();
+
assertThat(reassignment.getNotification().getPotentialUsers()).containsExactlyInAnyOrder("John",
"Jane");
+
assertThat(reassignment.getNotification().getPotentialGroups()).containsExactlyInAnyOrder("Admins");
+
assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(DeadlineHelper.getDuration(Period.ofMonths(7),
Duration.ZERO));
+ }
+
private void assertEqualsDate(ZonedDateTime expectedDate, ZonedDateTime
calculatedDate) {
assertThat(calculatedDate.toInstant().getEpochSecond()).isEqualTo(expectedDate.toInstant().getEpochSecond());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]