Skip to content

Commit

Permalink
Merge pull request #487 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 040d160 + acc2e70 commit fb004cf
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 53 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-rule-engine-api</artifactId>
<version>1.8.57</version>
<version>1.8.58</version>
<name>educ-grad-rule-engine-api</name>
<description>Rule Engine API for GRAD team</description>

Expand Down
18 changes: 18 additions & 0 deletions api/src/main/java/ca/bc/gov/educ/api/ruleengine/rule/BaseRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ca.bc.gov.educ.api.ruleengine.rule;

import java.util.Calendar;
import java.util.Date;

public abstract class BaseRule implements Rule {

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 @@ -38,6 +38,11 @@ public RuleData fire() {
List<GradRequirement> requirementsMet = new ArrayList<>();
List<GradRequirement> requirementsNotMet = new ArrayList<>();

List<CourseRequirement> courseRequirements = ruleProcessorData.getCourseRequirements();
if(courseRequirements == null) {
courseRequirements = new ArrayList<>();
}

List<StudentCourse> courseList = RuleProcessorRuleUtils.getUniqueStudentCourses(
obj.getStudentCoursesOptionalProgram(), ruleProcessorData.isProjected());
List<OptionalProgramRequirement> careerProgramRulesMatch = obj.getOptionalProgramRules()
Expand All @@ -57,8 +62,16 @@ public RuleData fire() {
while (studentCourseIterator.hasNext()) {

StudentCourse sc = studentCourseIterator.next();
for(OptionalProgramRequirement pR:careerProgramRulesMatch) {
if((pR.getOptionalProgramRequirementCode().getRequiredLevel() == null || pR.getOptionalProgramRequirementCode().getRequiredLevel().trim().compareTo("") == 0) && (sc.getWorkExpFlag() != null && sc.getWorkExpFlag().equalsIgnoreCase("Y"))) {
List<CourseRequirement> matchedCourseRequirements = courseRequirements.stream()
.filter(cr -> sc.getCourseCode().compareTo(cr.getCourseCode()) == 0
&& sc.getCourseLevel().compareTo(cr.getCourseLevel()) == 0)
.toList();

for(OptionalProgramRequirement pR:careerProgramRulesMatch) {
long matchedCount = matchedCourseRequirements.stream()
.filter(cr -> cr.getRuleCode().getCourseRequirementCode().compareTo(pR.getOptionalProgramRequirementCode().getOptProReqCode()) == 0)
.count();
if(matchedCount > 0 && (pR.getOptionalProgramRequirementCode().getRequiredLevel() == null || pR.getOptionalProgramRequirementCode().getRequiredLevel().trim().compareTo("") == 0)) {
requiredCredits = Integer.parseInt(pR.getOptionalProgramRequirementCode().getRequiredCredits());
if (totalCredits + sc.getCredits() <= requiredCredits) {
totalCredits += sc.getCredits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class ExcludeAfterProgramCutoffRule implements Rule {
public class ExcludeAfterProgramCutoffRule extends BaseRule implements Rule {
private static Logger logger = LoggerFactory.getLogger(ExcludeAfterProgramCutoffRule.class);

@Autowired
Expand All @@ -40,7 +40,7 @@ public RuleData fire() {

String sessionDate = studentCourse.getSessionDate() + "/01";
try {
Date temp = RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd");
Date temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd"));
sessionDate = RuleEngineApiUtils.formatDate(temp, "yyyy-MM-dd");
} catch (ParseException pe) {
logger.error("ERROR: {}",pe.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.bc.gov.educ.api.ruleengine.dto.RuleData;
import ca.bc.gov.educ.api.ruleengine.dto.RuleProcessorData;
import ca.bc.gov.educ.api.ruleengine.dto.StudentCourse;
import ca.bc.gov.educ.api.ruleengine.util.RuleEngineApiUtils;
import ca.bc.gov.educ.api.ruleengine.util.RuleProcessorRuleUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -12,13 +13,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

@Data
@Component
@NoArgsConstructor
@AllArgsConstructor
public class ExcludeValidationCoursesRule implements Rule {
public class ExcludeValidationCoursesRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(ExcludeValidationCoursesRule.class);

Expand All @@ -33,8 +36,14 @@ public RuleData fire() {

for (StudentCourse studentCourse : studentCourseList) {
String sessionDate = studentCourse.getSessionDate() + "/01";
try {
Date temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd"));
sessionDate = RuleEngineApiUtils.formatDate(temp, "yyyy/MM/dd");
} catch (ParseException pe) {
logger.error("ERROR: {}",pe.getMessage());
}
String cName = studentCourse.getCourseCode()+studentCourse.getCourseLevel();
if (studentCourse.getProvExamCourse().compareTo("Y")==0 && sessionDate.equalsIgnoreCase("2005/06/01") && (cName.compareTo("SS11") == 0
if (studentCourse.getProvExamCourse().compareTo("Y")==0 && sessionDate.equalsIgnoreCase("2005/06/30") && (cName.compareTo("SS11") == 0
|| cName.compareTo("SCH11") == 0
|| cName.compareTo("FNS12") == 0)) {
studentCourse.setValidationCourse(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class IncompleteCoursesRule implements Rule {
public class IncompleteCoursesRule extends BaseRule implements Rule {
private static Logger logger = LoggerFactory.getLogger(IncompleteCoursesRule.class);

@Autowired
Expand All @@ -36,7 +36,7 @@ public RuleData fire() {
String sessionDate = studentCourse.getSessionDate() + "/01";

try {
Date temp = RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd");
Date temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd"));
sessionDate = RuleEngineApiUtils.formatDate(temp, "yyyy-MM-dd");
} catch (ParseException pe) {
logger.error("ERROR: {}" , pe.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class MatchCreditsRule implements Rule {
public class MatchCreditsRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(MatchCreditsRule.class);

Expand Down Expand Up @@ -140,7 +140,7 @@ public void splitSortStudentCourses(List<StudentCourse> studentCourses, Date adu
String courseSessionDate = sc.getSessionDate() + "/01";
Date temp = null;
try {
temp = RuleEngineApiUtils.parseDate(courseSessionDate, "yyyy/MM/dd");
temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(courseSessionDate, "yyyy/MM/dd"));
} catch (ParseException e) {
logger.debug(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class MinAdultCoursesRule implements Rule {
public class MinAdultCoursesRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(MinAdultCoursesRule.class);

Expand Down Expand Up @@ -66,7 +66,7 @@ public RuleData fire() {
String courseSessionDate = sc.getSessionDate() + "/01";
Date temp = null;
try {
temp = RuleEngineApiUtils.parseDate(courseSessionDate, "yyyy/MM/dd");
temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(courseSessionDate, "yyyy/MM/dd"));
} catch (ParseException e) {
logger.debug(e.getMessage());
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public RuleData fire() {
String courseSessionDate = sc.getSessionDate() + "/01";
Date temp = null;
try {
temp = RuleEngineApiUtils.parseDate(courseSessionDate, "yyyy/MM/dd");
temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(courseSessionDate, "yyyy/MM/dd"));
} catch (ParseException e) {
logger.debug(e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class RegistrationsDuplicateAssmtRule implements Rule {
public class RegistrationsDuplicateAssmtRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(RegistrationsDuplicateAssmtRule.class);

Expand All @@ -44,8 +44,8 @@ public RuleData fire() {
&& !studentAssessmentsList.get(i).isDuplicate()
&& !studentAssessmentsList.get(j).isDuplicate()) {
try {
Date sessionDate1 = RuleEngineApiUtils.parseDate(studentAssessmentsList.get(i).getSessionDate() + "/01", "yyyy/MM/dd");
Date sessionDate2 = RuleEngineApiUtils.parseDate(studentAssessmentsList.get(j).getSessionDate() + "/01", "yyyy/MM/dd");
Date sessionDate1 = toLastDayOfMonth(RuleEngineApiUtils.parseDate(studentAssessmentsList.get(i).getSessionDate() + "/01", "yyyy/MM/dd"));
Date sessionDate2 = toLastDayOfMonth(RuleEngineApiUtils.parseDate(studentAssessmentsList.get(j).getSessionDate() + "/01", "yyyy/MM/dd"));
String sDate1 = RuleEngineApiUtils.formatDate(sessionDate1, RuleEngineApiConstants.DEFAULT_DATE_FORMAT);
String sDate2 = RuleEngineApiUtils.formatDate(sessionDate2, RuleEngineApiConstants.DEFAULT_DATE_FORMAT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class RegistrationsDuplicateCrseRule implements Rule {
public class RegistrationsDuplicateCrseRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(RegistrationsDuplicateCrseRule.class);

Expand All @@ -37,8 +37,10 @@ public RuleData fire() {
boolean inProgressCourse2 = false;
boolean isCompletedCourse1 = false;
boolean isCompletedCourse2 = false;
for (int i = 0; i < studentCourseList.size() - 1; i++) {

studentCourseList.sort(Comparator.comparing(StudentCourse::getCourseCode));

for (int i = 0; i < studentCourseList.size() - 1; i++) {
for (int j = i + 1; j < studentCourseList.size(); j++) {
if (studentCourseList.get(i).getCourseCode().equals(studentCourseList.get(j).getCourseCode())
&& !studentCourseList.get(i).isDuplicate()
Expand All @@ -51,8 +53,8 @@ public RuleData fire() {
continue;
}
try {
Date sessionDate1 = RuleEngineApiUtils.parseDate(studentCourseList.get(i).getSessionDate() + "/01", "yyyy/MM/dd");
Date sessionDate2 = RuleEngineApiUtils.parseDate(studentCourseList.get(j).getSessionDate() + "/01", "yyyy/MM/dd");
Date sessionDate1 = toLastDayOfMonth(RuleEngineApiUtils.parseDate(studentCourseList.get(i).getSessionDate() + "/01", "yyyy/MM/dd"));
Date sessionDate2 = toLastDayOfMonth(RuleEngineApiUtils.parseDate(studentCourseList.get(j).getSessionDate() + "/01", "yyyy/MM/dd"));
String sDate1 = RuleEngineApiUtils.formatDate(sessionDate1, RuleEngineApiConstants.DEFAULT_DATE_FORMAT);
String sDate2 = RuleEngineApiUtils.formatDate(sessionDate2, RuleEngineApiConstants.DEFAULT_DATE_FORMAT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class RegistrationsFailedCrseRule implements Rule {
public class RegistrationsFailedCrseRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(RegistrationsFailedCrseRule.class);

Expand All @@ -36,7 +36,7 @@ public RuleData fire() {
boolean inProgressCourse = false;
for (StudentCourse studentCourse : studentCourseList) {
try {
Date sessionDate = RuleEngineApiUtils.parseDate(studentCourse.getSessionDate() + "/01", "yyyy/MM/dd");
Date sessionDate = toLastDayOfMonth(RuleEngineApiUtils.parseDate(studentCourse.getSessionDate() + "/01", "yyyy/MM/dd"));
String sDate = RuleEngineApiUtils.formatDate(sessionDate, RuleEngineApiConstants.DEFAULT_DATE_FORMAT);
String today = RuleEngineApiUtils.formatDate(cal.getTime(), RuleEngineApiConstants.DEFAULT_DATE_FORMAT);
int diff = RuleEngineApiUtils.getDifferenceInMonths(sDate,today);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Component
@NoArgsConstructor
@AllArgsConstructor
public class RegistrationsRule implements Rule {
public class RegistrationsRule extends BaseRule implements Rule {

private static Logger logger = LoggerFactory.getLogger(RegistrationsRule.class);

Expand All @@ -37,7 +37,7 @@ public RuleData fire() {
String sessionDate = studentCourse.getSessionDate() + "/01";

try {
Date temp = RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd");
Date temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(sessionDate, "yyyy/MM/dd"));
sessionDate = RuleEngineApiUtils.formatDate(temp, "yyyy-MM-dd");
} catch (ParseException pe) {
logger.error("ERROR: {}",pe.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

public class RuleEngineApiUtils {
Expand Down Expand Up @@ -50,7 +47,7 @@ public static Date parsingTraxDate(String sessionDate) {
Date temp;
Date sDate = null;
try {
temp = RuleEngineApiUtils.parseDate(actualSessionDate, RuleEngineApiConstants.DATE_FORMAT);
temp = toLastDayOfMonth(RuleEngineApiUtils.parseDate(actualSessionDate, RuleEngineApiConstants.DATE_FORMAT));
String sDates = RuleEngineApiUtils.formatDate(temp, RuleEngineApiConstants.DATE_FORMAT);
sDate = RuleEngineApiUtils.parseDate(sDates, RuleEngineApiConstants.DATE_FORMAT);
} catch (ParseException pe) {
Expand Down Expand Up @@ -140,12 +137,12 @@ public static List<OptionalProgramRequirement> getCloneOptionalProgramRule(List<

public static boolean checkDateForRestrictedCourses(String startDate,String endDate,String currentSessionDate) {
try {
Date sDate = parseDate(startDate+"/01",RuleEngineApiConstants.DATE_FORMAT);
Date sDate = toLastDayOfMonth(parseDate(startDate+"/01",RuleEngineApiConstants.DATE_FORMAT));
if(endDate != null) {
Date eDate = parseDate(endDate + "/01", RuleEngineApiConstants.DATE_FORMAT);
return parseDate(currentSessionDate + "/01", RuleEngineApiConstants.DATE_FORMAT).after(sDate) && parseDate(currentSessionDate + "/01", "yyyy/MM/dd").before(eDate);
Date eDate = toLastDayOfMonth(parseDate(endDate + "/01", RuleEngineApiConstants.DATE_FORMAT));
return toLastDayOfMonth(parseDate(currentSessionDate + "/01", RuleEngineApiConstants.DATE_FORMAT)).after(sDate) && toLastDayOfMonth(parseDate(currentSessionDate + "/01", "yyyy/MM/dd")).before(eDate);
}else {
return parseDate(currentSessionDate + "/01", RuleEngineApiConstants.DATE_FORMAT).after(sDate);
return toLastDayOfMonth(parseDate(currentSessionDate + "/01", RuleEngineApiConstants.DATE_FORMAT)).after(sDate);
}
} catch (ParseException e) {
logger.error(ERROR_MSG,e.getMessage());
Expand All @@ -159,9 +156,9 @@ public static boolean compareCourseSessionDates(String sessionDate1,String sessi
sessionDate2 = sessionDate2 + "/01";

try {
Date temp1 = RuleEngineApiUtils.parseDate(sessionDate1, "yyyy/MM/dd");
Date temp1 = toLastDayOfMonth(RuleEngineApiUtils.parseDate(sessionDate1, "yyyy/MM/dd"));
sessionDate1 = RuleEngineApiUtils.formatDate(temp1, "yyyy-MM-dd");
Date temp2 = RuleEngineApiUtils.parseDate(sessionDate2, "yyyy/MM/dd");
Date temp2 = toLastDayOfMonth(RuleEngineApiUtils.parseDate(sessionDate2, "yyyy/MM/dd"));
sessionDate2 = RuleEngineApiUtils.formatDate(temp2, "yyyy-MM-dd");
} catch (ParseException pe) {
logger.error("ERROR: {}",pe.getMessage());
Expand All @@ -179,8 +176,18 @@ public static boolean compareCourseSessionDates(String sessionDate1,String sessi
// Courses with both finalLG(Letter Grade) & finalPercentage have some values
public static boolean isCompletedCourse(String finalGrade, Double finalPercentage) {
if (finalGrade != null && finalPercentage != null) {
return !"".equalsIgnoreCase(finalGrade.trim()) && finalPercentage.compareTo(0.0) > 0;
return !"".equalsIgnoreCase(finalGrade.trim()) && finalPercentage.compareTo(0.0D) > 0;
}
return false;
}

static 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 @@ -11,6 +11,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -162,8 +163,9 @@ public static String getGradDate(List<StudentCourse> studentCourses) {

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("Error {}",e.getMessage());
Expand Down Expand Up @@ -193,4 +195,14 @@ public static void updateCourseLevelForCLC(List<StudentCourse> studentCourses, S
}
});
}

static 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;
}
}
Loading

0 comments on commit fb004cf

Please sign in to comment.