diff --git a/Kitodo/src/main/java/org/kitodo/constants/StringConstants.java b/Kitodo-API/src/main/java/org/kitodo/constants/StringConstants.java similarity index 86% rename from Kitodo/src/main/java/org/kitodo/constants/StringConstants.java rename to Kitodo-API/src/main/java/org/kitodo/constants/StringConstants.java index 8e4e36800ca..39e4f79428f 100644 --- a/Kitodo/src/main/java/org/kitodo/constants/StringConstants.java +++ b/Kitodo-API/src/main/java/org/kitodo/constants/StringConstants.java @@ -17,4 +17,7 @@ public class StringConstants { public static final String SEMICOLON_DELIMITER = "; "; public static final String EDIT_FORM_SAVE = "editForm:save"; + // patterns + public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java index c50b4e139a0..7e0d564054e 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/elasticsearch/index/type/BaseType.java @@ -11,6 +11,8 @@ package org.kitodo.data.elasticsearch.index.type; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -138,7 +140,7 @@ private void getAdditionalProperties(Map jsonObject, BaseBean pr */ String getFormattedDate(Date date) { if (Objects.nonNull(date)) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); return dateFormat.format(date); } return ""; diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProcessTypeTest.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProcessTypeTest.java index 723b9e04c63..9aca8a84c6a 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProcessTypeTest.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProcessTypeTest.java @@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -260,7 +261,7 @@ public void shouldCreateDocuments() { } private String formatDate(Date date) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); return dateFormat.format(date); } } diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProjectTypeTest.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProjectTypeTest.java index 7781395d82a..e8d0abc0b0c 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProjectTypeTest.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/ProjectTypeTest.java @@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -338,7 +339,7 @@ public void shouldCreateSecondDocument() throws Exception { @Test public void shouldCreateThirdDocument() throws Exception { ProjectType processType = new ProjectType(); - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); Project project = prepareData().get(2); Map actual = processType.createDocument(project); diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/TemplateTypeTest.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/TemplateTypeTest.java index 3cbc65603bb..a36b6b946a9 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/TemplateTypeTest.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/elasticsearch/index/type/TemplateTypeTest.java @@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -195,7 +196,7 @@ public void shouldCreateDocuments() { } private String formatDate(Date date) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); return dateFormat.format(date); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/BaseForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/BaseForm.java index a516d1538b9..7fbec408037 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/BaseForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/BaseForm.java @@ -11,6 +11,8 @@ package org.kitodo.production.forms; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; + import java.io.Serializable; import java.text.DateFormat; import java.text.MessageFormat; @@ -364,7 +366,7 @@ public void saveSelectedColumns() { */ public String getFormattedDate(Date date) { if (Objects.nonNull(date)) { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); return dateFormat.format(date); } return ""; diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java b/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java index 31a610378ab..c30b3480447 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/Helper.java @@ -11,6 +11,8 @@ package org.kitodo.production.helper; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; + import java.io.PrintWriter; import java.io.StringWriter; import java.security.SecureRandom; @@ -398,7 +400,7 @@ public static String getDateAsFormattedString(Date date) { if (Objects.isNull(date)) { return "-"; } else { - DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_FORMAT); return dateFormat.format(date); } } @@ -416,12 +418,12 @@ public static Date parseDateFromFormattedString(String date) { return null; } try { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT); LocalDateTime localDate = LocalDateTime.parse(date, formatter); Instant instant = localDate.toInstant(ZoneOffset.UTC); return Date.from(instant); } catch (DateTimeParseException e) { - logger.info("invalid date format (yyyy-MM-dd HH:mm:ss) for date string: '" + date + "'"); + logger.info("invalid date format '{}' for date string: '{}'", DEFAULT_DATE_FORMAT, date); return null; } } diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/WikiFieldHelper.java b/Kitodo/src/main/java/org/kitodo/production/helper/WikiFieldHelper.java index 88743c88421..711cf55d53a 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/WikiFieldHelper.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/WikiFieldHelper.java @@ -11,6 +11,8 @@ package org.kitodo.production.helper; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -131,7 +133,7 @@ private static Task getCurrentTask(Property property) throws DAOException { } private static Date getCreationDate(Property property) throws ParseException { - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(property.getValue().substring(1, 20)); + return new SimpleDateFormat(DEFAULT_DATE_FORMAT).parse(property.getValue().substring(1, 20)); } private static String getWikiFieldMessage(String message) { diff --git a/Kitodo/src/main/java/org/kitodo/production/security/SecuritySession.java b/Kitodo/src/main/java/org/kitodo/production/security/SecuritySession.java index 0ad7b6caafe..9d3daefd9c9 100644 --- a/Kitodo/src/main/java/org/kitodo/production/security/SecuritySession.java +++ b/Kitodo/src/main/java/org/kitodo/production/security/SecuritySession.java @@ -11,6 +11,8 @@ package org.kitodo.production.security; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; + import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -73,7 +75,7 @@ public LocalDateTime getLastRequest() { * @return The lastRequest. */ public String getLastRequestAsString() { - return lastRequest.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + return lastRequest.format(DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT)); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java index 41df944dec9..a03adc2f06a 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java @@ -14,6 +14,7 @@ import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery; import static org.elasticsearch.index.query.QueryBuilders.nestedQuery; +import static org.kitodo.constants.StringConstants.DEFAULT_DATE_FORMAT; import static org.kitodo.data.database.enums.CorrectionComments.NO_CORRECTION_COMMENTS; import static org.kitodo.data.database.enums.CorrectionComments.NO_OPEN_CORRECTION_COMMENTS; import static org.kitodo.data.database.enums.CorrectionComments.OPEN_CORRECTION_COMMENTS; @@ -2223,7 +2224,7 @@ public static String getPropertyValue(ProcessDTO process, String propertyName) { */ public static String getProcessDuration(ProcessDTO process) { String creationDateTimeString = process.getCreationDate(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT); LocalDateTime createLocalDate = LocalDateTime.parse(creationDateTimeString, formatter); Duration duration = Duration.between(createLocalDate, LocalDateTime.now()); return String.format("%sd; %sh", duration.toDays(),