Skip to content

Commit

Permalink
Merge pull request #536 from bcgov/grad-release
Browse files Browse the repository at this point in the history
Grad release 1.22
  • Loading branch information
githubmamatha authored Jul 9, 2024
2 parents 66d9dc4 + d2691ee commit 8281d64
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>ca.bc.gov.educ</groupId>
<artifactId>educ-grad-algorithm-api</artifactId>
<version>1.8.35</version>
<version>1.8.36</version>
<name>educ-grad-algorithm-api</name>
<description>Graduation Algorithm API for GRAD team</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ private boolean isGradDatePast() {
if (StringUtils.isBlank(gradDate)) {
return false;
}
String gradDateStr = gradDate.length() < 10? gradDate + "/01" : gradDate;
String gradDateStr = gradDate.length() < 10 ? gradDate + "/01" : gradDate;
log.debug("GradMessageRequest: Grad Date = {}", gradDateStr);
SimpleDateFormat dateFormat = new SimpleDateFormat(gradDate.length() < 10? GradAlgorithmAPIConstants.SECONDARY_DATE_FORMAT : GradAlgorithmAPIConstants.DEFAULT_DATE_FORMAT);
try {
Date dt = dateFormat.parse(gradDateStr);
Calendar calGradDate = Calendar.getInstance();
calGradDate.setTime(dt);
calGradDate.set(Calendar.DAY_OF_MONTH, calGradDate.getActualMaximum(Calendar.DAY_OF_MONTH));
Calendar now = Calendar.getInstance();
now.setTime(new Date());
return calGradDate.before(now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.time.LocalDate;
import java.time.Month;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -336,7 +337,7 @@ private void getMainMessageForNonGrad(GradMessageRequest gradMessageRequest, Str
private String formatGradDate(String gradDate) {
try {
String formatDate = StringUtils.contains(gradDate, "/") ? StringUtils.replace(gradDate + "/01", "/", "-") : gradDate;
LocalDate currentDate = LocalDate.parse(formatDate);
LocalDate currentDate = LocalDate.parse(formatDate).with(TemporalAdjusters.lastDayOfMonth());
Month month = currentDate.getMonth();
int year = currentDate.getYear();
return month.getDisplayName(TextStyle.FULL, Locale.ENGLISH) + " " + year;
Expand Down Expand Up @@ -375,8 +376,9 @@ private String getLastSessionDate(List<StudentCourse> studentCourses, List<Stude

for (StudentCourse studentCourse : studentCourses) {
try {
if (dateFormat.parse(studentCourse.getSessionDate() + "/01").compareTo(gradDate) > 0) {
gradDate = dateFormat.parse(studentCourse.getSessionDate() + "/01");
Date dateToCompare = toLastDayOfMonth(dateFormat.parse(studentCourse.getSessionDate() + "/01"));
if (dateToCompare.compareTo(gradDate) > 0) {
gradDate = dateToCompare;
}
} catch (ParseException e) {
logger.debug(e.getMessage());
Expand All @@ -385,8 +387,9 @@ private String getLastSessionDate(List<StudentCourse> studentCourses, List<Stude

for (StudentAssessment studentAssessment : studentAssessments) {
try {
if (dateFormat.parse(studentAssessment.getSessionDate() + "/01").compareTo(gradDate) > 0) {
gradDate = dateFormat.parse(studentAssessment.getSessionDate() + "/01");
Date dateToCompare = toLastDayOfMonth(dateFormat.parse(studentAssessment.getSessionDate() + "/01"));
if (dateToCompare.compareTo(gradDate) > 0) {
gradDate = dateToCompare;
}
} catch (ParseException e) {
logger.debug(e.getMessage());
Expand Down Expand Up @@ -490,7 +493,8 @@ private void setCoursesForHypotheticalPass(List<StudentCourse> studentCourses, S
if (basisSessionDate != null && !studentCourses.isEmpty()) {
for (StudentCourse studentCourse : studentCourses) {
try {
if (dateFormat.parse(studentCourse.getSessionDate() + "/01").compareTo(basisSessionDate) >= 0) {
Date dateToCompare = toLastDayOfMonth(dateFormat.parse(studentCourse.getSessionDate() + "/01"));
if (dateToCompare.compareTo(basisSessionDate) >= 0) {
logger.debug("Student Course [{}/{}] Session Date [{}] - Hypothetically passed", studentCourse.getCourseCode(), studentCourse.getCourseLevel(), studentCourse.getSessionDate());
studentCourse.setCompletedCourseLetterGrade("P");
}
Expand Down Expand Up @@ -527,7 +531,7 @@ private void sortCoursesBasedOnProgram(String program, List<StudentCourse> stude
String courseSessionDate = sc.getSessionDate() + "/01";
Date temp = null;
try {
temp = GradAlgorithmApiUtils.parseDate(courseSessionDate, SECONDARY_DATE_FORMAT);
temp = toLastDayOfMonth(GradAlgorithmApiUtils.parseDate(courseSessionDate, SECONDARY_DATE_FORMAT));
} catch (ParseException e) {
logger.debug(e.getMessage());
}
Expand Down Expand Up @@ -837,4 +841,13 @@ private String getCareerProgramNames(RuleProcessorData ruleProcessorData) {
return null;
}

Date toLastDayOfMonth(Date date) {
if(date != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
return cal.getTime();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class APIUtils {

private static final Logger logger = LoggerFactory.getLogger(APIUtils.class);
Expand Down Expand Up @@ -47,19 +42,6 @@ public static <T> String getJSONStringFromObject(T inputObject) {
return json;
}

public static String parsingTraxDate(String pcDate) {
String actualPCDate = pcDate + "/01";
Date gradDate=null;
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
try {
gradDate = dateFormat.parse(actualPCDate);
} catch (ParseException e) {
logger.debug("ERROR {}",e.getLocalizedMessage());
}
dateFormat = new SimpleDateFormat("yyyy-MM-dd");
return dateFormat.format(gradDate);
}

/**
* Remove characters from the CourseLevel if any (Example: 12A -> 12, 12B -> 12, etc..)
* and Convert Course level into an integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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.gradalgorithm.util.GradAlgorithmAPIConstants.SECONDARY_DATE_FORMAT;

Expand All @@ -30,7 +31,7 @@ public LocalDate deserialize(JsonParser jsonParser, DeserializationContext deser
if(slashCount > 0) {
formatter = DateTimeFormatter.ofPattern(SECONDARY_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());
Expand Down

0 comments on commit 8281d64

Please sign in to comment.