From 8dde7b8ff5537c850519d21435ae5abfdfcf1186 Mon Sep 17 00:00:00 2001 From: Abhiram Gundala <164050036+Abhitocode@users.noreply.github.com> Date: Mon, 9 Dec 2024 06:30:05 -0500 Subject: [PATCH] [incubator-kie-issues#1612] Fix BusinessCalendar behavior with inconsistent (full/partial) set of properties on `calendar.properties` (#3788) * incubator-kie-issues-1612 * incubator-kie-issues-1612 * incubator-kie-issues-1612 * [incubator-kie-issues#1612] TODO setup * [incubator-kie-issues#1612] Separating different concerns in different classes: CalendarBean is responsible of calendar.properties file. BusinessCalendarImpl is responsible of working time evaluation * incubator-kie-issues-1612 * [incubator-kie-issues#1612] Example test * incubator-kie-issues-1612 * incubator-kie-issues-1612 * [incubator-kie-issues#1612] Extend test coverage. Minor refactoring related to it. * incubator-kie-issues-1612 * [incubator-kie-issues#1612] Comment on tests * [incubator-kie-issues#1612] Minor fixes * [incubator-kie-issues#1612] Extend test coverage. Minor refactoring related to it. * [incubator-kie-issues#1612] Minor refactoring * incubator-kie-issues-1612 * [incubator-kie-issues#1612] Fixing tests. Including incubator-kie-issues#1648 fix * [incubator-kie-issues#1612] WIP - implementing nightly hour * [incubator-kie-issues#1612] WIP - Simplify test - moving tested methods to static * [incubator-kie-issues#1612] WIP - Cleanup * [incubator-kie-issues#1612] Working tests. * incubator-kie-issues-1612 * incubator-kie-issues-1612 * incubator-kie-issues-1612 * [incubator-kie-issues#1612] Fixed logging * [incubator-kie-issues#1612] Fixed minute/second reset on calendarRolling * [incubator-kie-issues#1612] Fixed assertiont JUnit5 -> assertj * [incubator-kie-issues#1612] Fixed test * incubator-kie-issues-1612 * incubator-kie-issues-1612 * [incubator-kie-issues#1612] Avoid minute/second reset on rolling hour, since the minute/second management is based on "add" operation * [incubator-kie-issues#1612] Fix naming * [incubator-kie-issues#1612] Add minute / second test/fix * [incubator-kie-issues#1612] Extend test coverage * updated logging * logger update * logger update --------- Co-authored-by: Gabriele-Cardosi --- .../kie/kogito/calendar/BusinessCalendar.java | 13 +- .../core/timer/BusinessCalendarImpl.java | 622 ++++++++-------- .../jbpm/process/core/timer/CalendarBean.java | 399 ++++++++++ .../core/timer/CalendarBeanFactory.java | 60 ++ .../core/timer/BusinessCalendarImplTest.java | 696 +++++++----------- .../core/timer/CalendarBeanFactoryTest.java | 45 ++ .../process/core/timer/CalendarBeanTest.java | 297 ++++++++ .../src/test/resources/calendar.properties | 20 + .../src/test/resources/logback-test.xml | 1 + ... => BusinessCalendarTimerProcessTest.java} | 24 +- ...sinessCalendarProducerQuarkusTemplate.java | 2 +- ...usinessCalendarProducerSpringTemplate.java | 2 +- ...sinessCalendarProducerQuarkusTemplate.java | 36 - ...usinessCalendarProducerSpringTemplate.java | 37 - 14 files changed, 1450 insertions(+), 804 deletions(-) create mode 100644 jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/CalendarBean.java create mode 100644 jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/CalendarBeanFactory.java create mode 100644 jbpm/jbpm-flow/src/test/java/org/jbpm/process/core/timer/CalendarBeanFactoryTest.java create mode 100644 jbpm/jbpm-flow/src/test/java/org/jbpm/process/core/timer/CalendarBeanTest.java create mode 100644 jbpm/jbpm-flow/src/test/resources/calendar.properties rename jbpm/jbpm-tests/src/test/java/org/jbpm/bpmn2/calendar/{BusinessCalendarTest.java => BusinessCalendarTimerProcessTest.java} (82%) delete mode 100644 kogito-codegen-modules/kogito-codegen-processes/src/test/resources/class-templates/producer/BusinessCalendarProducerQuarkusTemplate.java delete mode 100644 kogito-codegen-modules/kogito-codegen-processes/src/test/resources/class-templates/producer/BusinessCalendarProducerSpringTemplate.java diff --git a/api/kogito-api/src/main/java/org/kie/kogito/calendar/BusinessCalendar.java b/api/kogito-api/src/main/java/org/kie/kogito/calendar/BusinessCalendar.java index 6e15a6cc0e6..45ecce21bd4 100644 --- a/api/kogito-api/src/main/java/org/kie/kogito/calendar/BusinessCalendar.java +++ b/api/kogito-api/src/main/java/org/kie/kogito/calendar/BusinessCalendar.java @@ -27,18 +27,21 @@ public interface BusinessCalendar { /** - * Calculates given time expression into duration in milliseconds based on calendar configuration. - * + * Returns the difference, in milliseconds, between the business date that matches the given + * timeExpression, and the current time. + * See {@link #calculateBusinessTimeAsDate} for business date calculation + * * @param timeExpression time expression that is supported by business calendar implementation. * @return duration expressed in milliseconds */ - public long calculateBusinessTimeAsDuration(String timeExpression); + long calculateBusinessTimeAsDuration(String timeExpression); /** - * Calculates given time expression into target date based on calendar configuration. + * Returns the first Date that matches the given timeExpression and falls + * into the business calendar working hours. * * @param timeExpression time expression that is supported by business calendar implementation. * @return date when given time expression will match in the future */ - public Date calculateBusinessTimeAsDate(String timeExpression); + Date calculateBusinessTimeAsDate(String timeExpression); } diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/BusinessCalendarImpl.java b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/BusinessCalendarImpl.java index b22f48cbb35..280cc3f6e3f 100755 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/BusinessCalendarImpl.java +++ b/jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/BusinessCalendarImpl.java @@ -18,48 +18,37 @@ */ package org.jbpm.process.core.timer; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.SimpleDateFormat; import java.time.Duration; import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.List; import java.util.Objects; -import java.util.Properties; import java.util.TimeZone; import java.util.regex.Matcher; import org.jbpm.util.PatternConstants; import org.kie.kogito.calendar.BusinessCalendar; -import org.kie.kogito.timer.SessionClock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.jbpm.process.core.constants.CalendarConstants.BUSINESS_CALENDAR_PATH; - /** * Default implementation of BusinessCalendar interface that is configured with properties. * Following are supported properties: * - * + * * Format
- * + * * Holidays can be given in two formats: *