TSK-1224: refactor the configuration of the custom holidays
This commit is contained in:
parent
df4fd17264
commit
d7562b53a3
|
@ -10,7 +10,6 @@ import java.sql.Connection;
|
|||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -32,9 +31,11 @@ import pro.taskana.common.api.LoggerUtils;
|
|||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.api.TaskanaRole;
|
||||
import pro.taskana.common.api.exceptions.SystemException;
|
||||
import pro.taskana.common.api.exceptions.WrongCustomHolidayFormatException;
|
||||
import pro.taskana.common.internal.TaskanaEngineImpl;
|
||||
import pro.taskana.common.internal.configuration.DB;
|
||||
import pro.taskana.common.internal.configuration.DbSchemaCreator;
|
||||
import pro.taskana.common.internal.util.CustomHoliday;
|
||||
import pro.taskana.common.internal.configuration.SecurityVerifier;
|
||||
|
||||
/**
|
||||
|
@ -73,6 +74,10 @@ public class TaskanaEngineConfiguration {
|
|||
// TASKANA_SCHEMA_VERSION
|
||||
private static final String DEFAULT_SCHEMA_NAME = "TASKANA";
|
||||
|
||||
private static final String TASKANA_CUSTOM_HOLIDAY = "taskana.custom.holidays";
|
||||
private static final String TASKANA_CUSTOM_HOLIDAY_SEPERATOR = ";";
|
||||
private static final String TASKANA_CUSTOM_HOLIDAY_DAY_MONTH_SEPERATOR = "\\.";
|
||||
|
||||
// Taskana properties file
|
||||
protected String propertiesFileName = TASKANA_PROPERTIES;
|
||||
|
||||
|
@ -97,8 +102,8 @@ public class TaskanaEngineConfiguration {
|
|||
protected Map<String, List<String>> classificationCategoriesByTypeMap = new HashMap<>();
|
||||
// Properties for the monitor
|
||||
private boolean germanPublicHolidaysEnabled;
|
||||
private List<LocalDate> customHolidays;
|
||||
// Properties for generalo job execution
|
||||
private List<CustomHoliday> customHolidays = new ArrayList<>();
|
||||
// Properties for general job execution
|
||||
private int jobBatchSize = 100;
|
||||
private int maxNumberOfJobRetries = 3;
|
||||
// Properties for the cleanup job
|
||||
|
@ -176,6 +181,7 @@ public class TaskanaEngineConfiguration {
|
|||
initClassificationTypes(props);
|
||||
initClassificationCategories(props);
|
||||
initGermanHolidaysEnabled(props);
|
||||
initCustomHolidays(props);
|
||||
}
|
||||
|
||||
public static DataSource createDefaultDataSource() {
|
||||
|
@ -254,12 +260,12 @@ public class TaskanaEngineConfiguration {
|
|||
this.germanPublicHolidaysEnabled = germanPublicHolidaysEnabled;
|
||||
}
|
||||
|
||||
public List<LocalDate> getCustomHolidays() {
|
||||
public List<CustomHoliday> getCustomHolidays() {
|
||||
return customHolidays;
|
||||
}
|
||||
|
||||
public void setCustomHolidays(List<LocalDate> customHolidays) {
|
||||
this.customHolidays = customHolidays;
|
||||
public void setCustomHolidays(List<CustomHoliday> customHolidays) {
|
||||
customHolidays.forEach(this.customHolidays::add);
|
||||
}
|
||||
|
||||
public Map<TaskanaRole, Set<String>> getRoleMap() {
|
||||
|
@ -540,6 +546,34 @@ public class TaskanaEngineConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
private void initCustomHolidays(Properties props) {
|
||||
if (props.getProperty(TASKANA_CUSTOM_HOLIDAY) != null) {
|
||||
Arrays.asList(
|
||||
props.getProperty(TASKANA_CUSTOM_HOLIDAY).split(TASKANA_CUSTOM_HOLIDAY_SEPERATOR))
|
||||
.forEach(
|
||||
entry -> {
|
||||
try {
|
||||
customHolidays.add(createCustomHolidayFromPropsEntry(entry));
|
||||
} catch (WrongCustomHolidayFormatException e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private CustomHoliday createCustomHolidayFromPropsEntry(String customHolidayEntry)
|
||||
throws WrongCustomHolidayFormatException {
|
||||
String[] parts = customHolidayEntry.split(TASKANA_CUSTOM_HOLIDAY_DAY_MONTH_SEPERATOR);
|
||||
if (parts.length == 2) {
|
||||
return CustomHoliday.of(Integer.valueOf(parts[0]), Integer.valueOf(parts[1]));
|
||||
}
|
||||
throw new WrongCustomHolidayFormatException(
|
||||
String.format(
|
||||
"Wrong format fpr custom holiday entry %s! The format should be 'dd.MM' "
|
||||
+ "i.e. 01.05 for the first of may.",
|
||||
customHolidayEntry));
|
||||
}
|
||||
|
||||
private HashSet<String> getTokensWithCollection(String str, String rolesSeparator) {
|
||||
return Collections.list(new StringTokenizer(str, rolesSeparator)).stream()
|
||||
.map(token -> String.valueOf(token).toLowerCase().trim())
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package pro.taskana.common.api.exceptions;
|
||||
|
||||
public class WrongCustomHolidayFormatException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -7644923780787018797L;
|
||||
|
||||
public WrongCustomHolidayFormatException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WrongCustomHolidayFormatException(
|
||||
String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public WrongCustomHolidayFormatException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public WrongCustomHolidayFormatException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public WrongCustomHolidayFormatException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package pro.taskana.common.internal.util;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class CustomHoliday {
|
||||
|
||||
private final Integer day;
|
||||
private final Integer month;
|
||||
|
||||
public Integer getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public Integer getMonth() {
|
||||
return month;
|
||||
}
|
||||
|
||||
public CustomHoliday(Integer day, Integer month) {
|
||||
super();
|
||||
this.day = day;
|
||||
this.month = month;
|
||||
}
|
||||
|
||||
public static CustomHoliday of(Integer day, Integer month) {
|
||||
return new CustomHoliday(day, month);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(day, month);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof CustomHoliday)) {
|
||||
return false;
|
||||
}
|
||||
CustomHoliday other = (CustomHoliday) obj;
|
||||
return Objects.equals(day, other.day) && Objects.equals(month, other.month);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomHoliday [day=" + day + ", month=" + month + "]";
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ import pro.taskana.common.api.exceptions.SystemException;
|
|||
public final class WorkingDaysToDaysConverter {
|
||||
|
||||
private static boolean germanHolidaysEnabled;
|
||||
private static Set<LocalDate> customHolidays = new HashSet<>();
|
||||
private static Set<CustomHoliday> customHolidays = new HashSet<>();
|
||||
private Instant referenceDate;
|
||||
private LocalDate easterSunday;
|
||||
|
||||
|
@ -77,7 +77,7 @@ public final class WorkingDaysToDaysConverter {
|
|||
germanHolidaysEnabled = germanPublicHolidaysEnabled;
|
||||
}
|
||||
|
||||
public static void setCustomHolidays(List<LocalDate> holidays) {
|
||||
public static void setCustomHolidays(List<CustomHoliday> holidays) {
|
||||
customHolidays = new HashSet<>(holidays == null ? Collections.emptyList() : holidays);
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public final class WorkingDaysToDaysConverter {
|
|||
return true;
|
||||
}
|
||||
// Custom holidays that can be configured in the TaskanaEngineConfiguration
|
||||
return customHolidays.contains(date);
|
||||
return customHolidays.contains(CustomHoliday.of(date.getDayOfMonth(), date.getMonthValue()));
|
||||
}
|
||||
|
||||
public boolean isGermanHoliday(LocalDate date) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import pro.taskana.TaskanaEngineConfiguration;
|
||||
import pro.taskana.common.api.TaskanaEngine;
|
||||
import pro.taskana.common.internal.util.CustomHoliday;
|
||||
|
||||
/** Test of configuration. */
|
||||
class TaskanaEngineTestConfigurationTest {
|
||||
|
@ -22,4 +23,19 @@ class TaskanaEngineTestConfigurationTest {
|
|||
|
||||
assertThat(te).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomHolidayInitialisationWithTaskanaProprtiesFile() throws SQLException {
|
||||
DataSource ds = TaskanaEngineTestConfiguration.getDataSource();
|
||||
TaskanaEngineConfiguration taskEngineConfiguration =
|
||||
new TaskanaEngineConfiguration(
|
||||
ds,
|
||||
false,
|
||||
false,
|
||||
"/custom_holiday_taskana.properties",
|
||||
"|",
|
||||
TaskanaEngineTestConfiguration.getSchemaName());
|
||||
assertThat(taskEngineConfiguration.getCustomHolidays()).contains(CustomHoliday.of(31, 7));
|
||||
assertThat(taskEngineConfiguration.getCustomHolidays()).contains(CustomHoliday.of(16, 12));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ class WorkingDaysToDaysConverterTest {
|
|||
@BeforeAll
|
||||
static void setup() {
|
||||
WorkingDaysToDaysConverter.setGermanPublicHolidaysEnabled(true);
|
||||
LocalDate dayOfReformation = LocalDate.of(2018, 10, 31);
|
||||
LocalDate allSaintsDays = LocalDate.of(2018, 11, 1);
|
||||
CustomHoliday dayOfReformation = CustomHoliday.of(31, 10);
|
||||
CustomHoliday allSaintsDays = CustomHoliday.of(1, 11);
|
||||
WorkingDaysToDaysConverter.setCustomHolidays(Arrays.asList(dayOfReformation, allSaintsDays));
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package pro.taskana.monitor.internal;
|
|||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -11,6 +10,7 @@ import org.junit.jupiter.api.BeforeAll;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import pro.taskana.common.api.exceptions.InvalidArgumentException;
|
||||
import pro.taskana.common.internal.util.CustomHoliday;
|
||||
import pro.taskana.common.internal.util.WorkingDaysToDaysConverter;
|
||||
import pro.taskana.monitor.api.reports.header.TimeIntervalColumnHeader;
|
||||
import pro.taskana.monitor.internal.preprocessor.WorkingDaysToDaysReportConverter;
|
||||
|
@ -21,8 +21,8 @@ class WorkingDaysToDaysReportConverterTest {
|
|||
@BeforeAll
|
||||
static void setup() {
|
||||
WorkingDaysToDaysConverter.setGermanPublicHolidaysEnabled(true);
|
||||
LocalDate dayOfReformation = LocalDate.of(2018, 10, 31);
|
||||
LocalDate allSaintsDays = LocalDate.of(2018, 11, 1);
|
||||
CustomHoliday dayOfReformation = CustomHoliday.of(31, 10);
|
||||
CustomHoliday allSaintsDays = CustomHoliday.of(1, 11);
|
||||
WorkingDaysToDaysConverter.setCustomHolidays(Arrays.asList(dayOfReformation, allSaintsDays));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
taskana.roles.user=group1 | group2|teamlead_1 | teamlead_2 |user_1_1| user_1_1| user_1_2| user_2_1| user_2_2| max|elena|simone
|
||||
taskana.roles.Admin=name=konrad,Organisation=novatec|admin
|
||||
taskana.roles.businessadmin=max|Moritz|businessadmin
|
||||
taskana.roles.monitor=john|teamlead_2 | monitor
|
||||
taskana.domains=Domain_A , DOMAIN_B
|
||||
taskana.classification.types=TASK , document
|
||||
taskana.classification.categories.task=EXTERNAL, manual, autoMAtic, Process
|
||||
taskana.classification.categories.document=EXTERNAL
|
||||
taskana.jobs.maxRetries=3
|
||||
taskana.jobs.batchSize=50
|
||||
taskana.jobs.cleanup.runEvery=P1D
|
||||
taskana.jobs.cleanup.firstRunAt=2018-07-25T08:00:00Z
|
||||
taskana.jobs.cleanup.minimumAge=P14D
|
||||
taskana.german.holidays.enabled=true
|
||||
taskana.custom.holidays=31.07;16.12
|
Loading…
Reference in New Issue