Skip to content

Commit

Permalink
[incubator-kie-issues#1612] Fix BusinessCalendar behavior with incons…
Browse files Browse the repository at this point in the history
…istent (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 <gabriele.cardosi@ibm.com>
  • Loading branch information
Abhitocode and Gabriele-Cardosi authored Dec 9, 2024
1 parent 68b9116 commit 8dde7b8
Show file tree
Hide file tree
Showing 14 changed files with 1,450 additions and 804 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>business date</b> that matches the given
* <code>timeExpression</code>, and the current time.
* See {@link #calculateBusinessTimeAsDate} for <b>business date</b> 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 <code>Date</code> that matches the given <code>timeExpression</code> 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);
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.jbpm.process.core.timer;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Objects;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.jbpm.process.core.constants.CalendarConstants.BUSINESS_CALENDAR_PATH;

public class CalendarBeanFactory {

private static final Logger logger = LoggerFactory.getLogger(CalendarBeanFactory.class);

public static CalendarBean createCalendarBean() {
URL resource = Thread.currentThread().getContextClassLoader().getResource(BUSINESS_CALENDAR_PATH);
if (Objects.nonNull(resource)) {
logger.debug("URL resource: {}", resource);
Properties calendarConfiguration = new Properties();
try (InputStream is = resource.openStream()) {
calendarConfiguration.load(is);
return new CalendarBean(calendarConfiguration);
} catch (IOException e) {
String errorMessage = "Error while loading properties for business calendar";
logger.error(errorMessage, e);
throw new RuntimeException(errorMessage, e);
} catch (IllegalArgumentException e) {
String errorMessage = "Error while populating properties for business calendar";
logger.error(errorMessage, e);
throw e;
}
} else {
String errorMessage = String.format("Missing %s", BUSINESS_CALENDAR_PATH);
logger.error(errorMessage);
throw new RuntimeException(errorMessage);
}
}
}
Loading

0 comments on commit 8dde7b8

Please sign in to comment.