From c06d80c40996cd857cdc1c18490a0cdb31f03025 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 16:09:35 -0600 Subject: [PATCH 1/4] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../api/distribution/util/GradLocalDateTimeDeserializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java index 9fd27d4d..557ed808 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java @@ -55,7 +55,7 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d formatter = DateTimeFormatter.ofPattern("yyyy/MM/ddTHH:mm:ss.000+00:00"); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains("T")) { - formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss"); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDateTime.parse(dateAsString, formatter); From 6e35206cbb4768afef06981b33e447e50973520f Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 16:59:49 -0600 Subject: [PATCH 2/4] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../java/ca/bc/gov/educ/api/distribution/model/dto/Student.java | 1 - .../distribution/model/dto/StudentCredentialDistribution.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/Student.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/Student.java index 38af766d..902c8ac6 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/Student.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/Student.java @@ -101,7 +101,6 @@ public void setBirthdate(LocalDate value) { this.birthdate = value; } - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") public LocalDateTime getLastUpdateDate() { return lastUpdateDate; } diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java index 39f01803..4e1e6a6d 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java @@ -2,7 +2,6 @@ import ca.bc.gov.educ.api.distribution.util.GradLocalDateDeserializer; import ca.bc.gov.educ.api.distribution.util.GradLocalDateSerializer; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.Data; @@ -30,7 +29,6 @@ public class StudentCredentialDistribution { @JsonDeserialize(using = GradLocalDateDeserializer.class) @JsonSerialize(using = GradLocalDateSerializer.class) private LocalDate programCompletionDate; - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") private LocalDateTime lastUpdateDate; private String honoursStanding; private String program; From 290b401c0c1f1205d8b19ff574679df124847c13 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 17:22:34 -0600 Subject: [PATCH 3/4] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../model/dto/StudentCredentialDistribution.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java index 4e1e6a6d..7d779ecd 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentCredentialDistribution.java @@ -1,9 +1,5 @@ package ca.bc.gov.educ.api.distribution.model.dto; -import ca.bc.gov.educ.api.distribution.util.GradLocalDateDeserializer; -import ca.bc.gov.educ.api.distribution.util.GradLocalDateSerializer; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.Data; import java.time.LocalDate; @@ -26,8 +22,6 @@ public class StudentCredentialDistribution { private String legalMiddleNames; private String legalLastName; private String studentCitizenship; - @JsonDeserialize(using = GradLocalDateDeserializer.class) - @JsonSerialize(using = GradLocalDateSerializer.class) private LocalDate programCompletionDate; private LocalDateTime lastUpdateDate; private String honoursStanding; From 36a7b0120cbb4f021d11df046fa405da7f7532d2 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jul 2023 22:04:36 -0600 Subject: [PATCH 4/4] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern --- .../model/dto/StudentSearchRequest.java | 6 +++--- .../util/EducDistributionApiConstants.java | 4 +++- .../util/EducDistributionApiUtils.java | 4 ++-- .../util/GradLocalDateDeserializer.java | 6 ++++-- .../util/GradLocalDateTimeDeserializer.java | 18 +++++++----------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java index ef883173..27d659be 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/model/dto/StudentSearchRequest.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Component; import java.io.Serializable; -import java.time.LocalDate; +import java.util.Date; import java.util.List; @Data @@ -24,9 +24,9 @@ public class StudentSearchRequest implements Serializable { private List programs; @JsonFormat(pattern = "yyyy-MM-dd") - LocalDate gradDateFrom; + Date gradDateFrom; @JsonFormat(pattern = "yyyy-MM-dd") - LocalDate gradDateTo; + Date gradDateTo; Boolean validateInput; String localDownload; diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiConstants.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiConstants.java index ef00e8da..343a28b3 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiConstants.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiConstants.java @@ -22,7 +22,9 @@ public class EducDistributionApiConstants { public static final String POST_DISTRIBUTION = "/zipandupload"; //Default Date format constants public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; - public static final String SECONDARY_DATE_FORMAT = "yyyy/MM/dd"; + public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String SECOND_DEFAULT_DATE_FORMAT = "yyyy/MM/dd"; + public static final String SECOND_DEFAULT_DATE_TIME_FORMAT = "yyyy/MM/dd HH:mm:ss"; //Grad2-1931 - mchintha public static final String DATE_FORMAT_YYYYMMDD = "yyyyMMdd"; public static final String TMP_DIR = "/tmp"; diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiUtils.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiUtils.java index a7f31bb9..3e65f0b9 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/EducDistributionApiUtils.java @@ -178,7 +178,7 @@ public static String parsingDateForCertificate(String sessionDate) { String actualSessionDate = sessionDate + "/01"; String sDates = null; try { - Date temp = parseDate(actualSessionDate, EducDistributionApiConstants.SECONDARY_DATE_FORMAT); + Date temp = parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT); sDates = formatDate(temp, EducDistributionApiConstants.DEFAULT_DATE_FORMAT); } catch (ParseException pe) { logger.error(ERROR,pe.getMessage()); @@ -190,7 +190,7 @@ public static Date parsingTraxDate(String sessionDate) { String actualSessionDate = sessionDate + "/01"; Date sDate = null; try { - Date temp = EducDistributionApiUtils.parseDate(actualSessionDate, EducDistributionApiConstants.SECONDARY_DATE_FORMAT); + Date temp = EducDistributionApiUtils.parseDate(actualSessionDate, EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT); String sDates = EducDistributionApiUtils.formatDate(temp, EducDistributionApiConstants.DEFAULT_DATE_FORMAT); sDate = EducDistributionApiUtils.parseDate(sDates, EducDistributionApiConstants.DEFAULT_DATE_FORMAT); } catch (ParseException pe) { diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateDeserializer.java index 1fb5e445..c71aa917 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateDeserializer.java @@ -12,6 +12,8 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import static ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants.SECOND_DEFAULT_DATE_FORMAT; + public class GradLocalDateDeserializer extends StdDeserializer { public GradLocalDateDeserializer() { @@ -30,7 +32,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser dateAsString = dateAsString + "/01"; } if(slashCount > 0) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); } return LocalDate.parse(dateAsString, formatter); } else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) { @@ -39,7 +41,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("-")) { return LocalDate.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); return LocalDate.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDate.parse(dateAsString, formatter); diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java index 557ed808..ebd75d6a 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/util/GradLocalDateTimeDeserializer.java @@ -13,6 +13,8 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import static ca.bc.gov.educ.api.distribution.util.EducDistributionApiConstants.*; + public class GradLocalDateTimeDeserializer extends StdDeserializer { public GradLocalDateTimeDeserializer() { @@ -31,31 +33,25 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d dateAsString = dateAsString + "/01"; } if(slashCount > 0) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); } return LocalDateTime.parse(dateAsString, formatter); } else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) { long timestamp = jsonParser.getValueAsLong(); return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("-")) { - formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT); LocalDate localDate = LocalDate.parse(dateAsString, formatter); return localDate.atStartOfDay(); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() == 10 && dateAsString.contains("/")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); LocalDate localDate = LocalDate.parse(dateAsString, formatter); return localDate.atStartOfDay(); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains(" ")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"); + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_TIME_FORMAT); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains(" ")) { - formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - return LocalDateTime.parse(dateAsString, formatter); - } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("/") && dateAsString.contains("T")) { - formatter = DateTimeFormatter.ofPattern("yyyy/MM/ddTHH:mm:ss.000+00:00"); - return LocalDateTime.parse(dateAsString, formatter); - } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.contains("-") && dateAsString.contains("T")) { - formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddTHH:mm:ss"); + formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT); return LocalDateTime.parse(dateAsString, formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDateTime.parse(dateAsString, formatter);