From 68f573e3b02e01357a7e7326f067a1e2a906fb04 Mon Sep 17 00:00:00 2001 From: arybakov Date: Mon, 24 Jun 2024 12:14:41 -0600 Subject: [PATCH] GRAD2-2799-P3 GRAD Incident: REGALG is creating SCCP certificates for students with future completion dates- edit summary P3 GRAD Incident: REGALG is creating SCCP certificates for students with future completion dates --- .../gradstudent/util/EducGradStudentApiUtils.java | 14 +++++++++++--- .../util/GradLocalDateDeserializer.java | 3 ++- .../util/GradLocalDateTimeDeserializer.java | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiUtils.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiUtils.java index 240c0cc7..b6df8faf 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/EducGradStudentApiUtils.java @@ -13,6 +13,7 @@ import java.time.Period; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.util.Calendar; import java.util.Date; public class EducGradStudentApiUtils { @@ -107,10 +108,10 @@ public static HttpHeaders getHeaders (String accessToken) public static String parsingTraxDate(String sessionDate) { String actualSessionDate = sessionDate + "/01"; - Date temp = new Date(); + Date temp; String sDates = null; try { - temp = EducGradStudentApiUtils.parseDate(actualSessionDate, "yyyy/MM/dd"); + temp = toLastDayOfMonth(EducGradStudentApiUtils.parseDate(actualSessionDate, "yyyy/MM/dd")); sDates = EducGradStudentApiUtils.formatDate(temp, EducGradStudentApiConstants.DEFAULT_DATE_FORMAT); } catch (ParseException pe) { logger.error("ERROR: {}", pe.getMessage()); @@ -136,7 +137,7 @@ public static Date parsingProgramCompletionDate(String sessionDate) { Date temp; Date sDate = null; try { - temp = EducGradStudentApiUtils.parseDate(actualSessionDate, EducGradStudentApiConstants.DATE_FORMAT); + temp = toLastDayOfMonth(EducGradStudentApiUtils.parseDate(actualSessionDate, EducGradStudentApiConstants.DATE_FORMAT)); String sDates = EducGradStudentApiUtils.formatDate(temp, EducGradStudentApiConstants.DATE_FORMAT); sDate = EducGradStudentApiUtils.parseDate(sDates, EducGradStudentApiConstants.DATE_FORMAT); } catch (ParseException pe) { @@ -188,4 +189,11 @@ public static GradStatusEventPayloadDTO transform(GraduationStudentRecordEntity .build(); } + private static Date toLastDayOfMonth(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); + return cal.getTime(); + } + } diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java index 6ab38ded..388ac7e1 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateDeserializer.java @@ -13,6 +13,7 @@ import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import static ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants.SECOND_DEFAULT_DATE_FORMAT; @@ -40,7 +41,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser if(slashCount > 0) { formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); } - return LocalDate.parse(dateAsString, formatter); + return LocalDate.parse(dateAsString, formatter).with(TemporalAdjusters.lastDayOfMonth()); } else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) { long timestamp = jsonParser.getValueAsLong(); return LocalDate.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()); diff --git a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java index 8d2ae1e9..459630ac 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/gradstudent/util/GradLocalDateTimeDeserializer.java @@ -14,6 +14,7 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import static ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants.*; @@ -41,7 +42,7 @@ public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext d if(slashCount > 0) { formatter = DateTimeFormatter.ofPattern(SECOND_DEFAULT_DATE_FORMAT); } - return LocalDateTime.parse(dateAsString, formatter); + return LocalDateTime.parse(dateAsString, formatter).with(TemporalAdjusters.lastDayOfMonth()); } else if(jsonParser.hasToken(JsonToken.VALUE_NUMBER_INT)) { long timestamp = jsonParser.getValueAsLong(); return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());