From e302cf6910244ba579137c4b5729e02629476863 Mon Sep 17 00:00:00 2001 From: Alexander Rybakov <83988488+arybakov-cgi@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:03:00 -0600 Subject: [PATCH] Fix date parse for yyyy-MM-ddTHH:mm:ss pattern (#215) * Fix date parse for yyyy-MM-ddTHH:mm:ss pattern * Fix Date format when T present * Fix Date format when T present --- .../gov/educ/api/distribution/model/dto/Student.java | 9 +++++---- .../model/dto/StudentCredentialDistribution.java | 4 ++++ .../educ/api/distribution/process/MergeProcess.java | 4 +++- .../util/GradLocalDateTimeDeserializer.java | 10 ++++++++-- 4 files changed, 20 insertions(+), 7 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 902c8ac6..520760e6 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 @@ -5,8 +5,8 @@ import java.io.Serializable; import java.time.LocalDate; -import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Objects; @@ -19,7 +19,7 @@ public class Student implements Serializable { private String gender; private String citizenship; private LocalDate birthdate; - private LocalDateTime lastUpdateDate; + private Date lastUpdateDate; private Address address; private String grade; private String gradProgram; @@ -101,11 +101,12 @@ public void setBirthdate(LocalDate value) { this.birthdate = value; } - public LocalDateTime getLastUpdateDate() { + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss") + public Date getLastUpdateDate() { return lastUpdateDate; } - public void setLastUpdateDate(LocalDateTime lastUpdateDate) { + public void setLastUpdateDate(Date lastUpdateDate) { this.lastUpdateDate = 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 7d779ecd..bfadf356 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 @@ -28,4 +28,8 @@ public class StudentCredentialDistribution { private String program; private String studentGrade; private List nonGradReasons; + + public LocalDateTime getLastUpdateDate() { + return lastUpdateDate == null ? LocalDateTime.now() : lastUpdateDate; + } } diff --git a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java index d519af3b..d0840d17 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java +++ b/api/src/main/java/ca/bc/gov/educ/api/distribution/process/MergeProcess.java @@ -18,7 +18,9 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.sql.Date; import java.time.LocalDate; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -218,7 +220,7 @@ private Student prepareStudentObj(StudentCredentialDistribution scd, List 10 && dateAsString.contains("/") && dateAsString.contains(" ")) { + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.length() <= 19 && dateAsString.contains("/") && dateAsString.contains(" ")) { 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(" ")) { + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 10 && dateAsString.length() <= 19 && dateAsString.contains("-") && dateAsString.contains(" ")) { formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT); return LocalDateTime.parse(dateAsString, formatter); + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 19 && dateAsString.contains("/") && dateAsString.contains("T")) { + formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_TIME_FORMAT); + return LocalDateTime.parse(StringUtils.replace(StringUtils.substringBefore(dateAsString, "."), "T", " "), formatter); + } else if(StringUtils.isNotBlank(dateAsString) && dateAsString.length() > 19 && dateAsString.contains("-") && dateAsString.contains("T")) { + formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FORMAT); + return LocalDateTime.parse(StringUtils.replace(StringUtils.substringBefore(dateAsString, "."), "T", " "), formatter); } else if(StringUtils.isNotBlank(dateAsString)) { return LocalDateTime.parse(dateAsString, formatter); }