Skip to content

Commit

Permalink
Trying to resolve duplicate code failure from sonar code quality.
Browse files Browse the repository at this point in the history
Trying to resolve duplicate code failure from sonar code quality.
  • Loading branch information
infstar committed Dec 7, 2023
1 parent 0382d1a commit d345131
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ public RuleData fire() {
courseList.sort(Comparator.comparing(StudentCourse::getCourseLevel).reversed()
.thenComparing(StudentCourse::getCompletedCoursePercentage).reversed());

List<ProgramRequirement> gradProgramRulesMatch = ruleProcessorData.getGradProgramRules()
.stream()
.filter(gradProgramRule -> "M".compareTo(gradProgramRule.getProgramRequirementCode().getRequirementTypeCode().getReqTypeCode()) == 0
&& "Y".compareTo(gradProgramRule.getProgramRequirementCode().getActiveRequirement()) == 0
&& "C".compareTo(gradProgramRule.getProgramRequirementCode().getRequirementCategory()) == 0)
.collect(Collectors.toList());
List<ProgramRequirement> gradProgramRulesMatch = RuleEngineApiUtils.getMatchProgramRules(ruleProcessorData.getGradProgramRules());

if (courseList.isEmpty()) {
logger.warn("!!!Empty list sent to Match Credit 1986 Rule for processing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ public RuleData fire() {
courseList.sort(Comparator.comparing(StudentCourse::getCourseLevel)
.thenComparing(StudentCourse::getCompletedCoursePercentage, Comparator.reverseOrder()));

List<ProgramRequirement> gradProgramRulesMatch = ruleProcessorData.getGradProgramRules()
.stream()
.filter(gradProgramRule -> "M".compareTo(gradProgramRule.getProgramRequirementCode().getRequirementTypeCode().getReqTypeCode()) == 0
&& "Y".compareTo(gradProgramRule.getProgramRequirementCode().getActiveRequirement()) == 0
&& "C".compareTo(gradProgramRule.getProgramRequirementCode().getRequirementCategory()) == 0)
.collect(Collectors.toList());
List<ProgramRequirement> gradProgramRulesMatch = RuleEngineApiUtils.getMatchProgramRules(ruleProcessorData.getGradProgramRules());

if (courseList.isEmpty()) {
logger.warn("!!!Empty list sent to Match Credit 1996 Rule for processing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public RuleData fire() {
requiredCredits = Integer.parseInt(gradProgramRule.getProgramRequirementCode().getRequiredCredits().trim()); // list

// 1st: minGrade12CreditCourses
Pair<Integer, Integer> counts = handleStudentCourses(gradProgramRule, requiredCredits, minCreditGrade12Courses, totalCredits, ldCourseCounter, true);
Pair<Integer, Integer> counts = processCourse(gradProgramRule, requiredCredits, minCreditGrade12Courses, totalCredits, ldCourseCounter, true);
totalCredits = counts.getLeft();
ldCourseCounter = counts.getRight();

// 2nd: the rest of courses + (minGrade12CreditCourses with leftOverCredit > 0)
counts = handleStudentCourses(gradProgramRule, requiredCredits, tempStudentCourseList, totalCredits, ldCourseCounter, false);
counts = processCourse(gradProgramRule, requiredCredits, tempStudentCourseList, totalCredits, ldCourseCounter, false);
totalCredits = counts.getLeft();

AlgorithmSupportRule.checkCredits1996(totalCredits,requiredCredits,gradProgramRule,ruleProcessorData);
Expand All @@ -78,8 +78,8 @@ public RuleData fire() {
return ruleProcessorData;
}

private Pair<Integer, Integer> handleStudentCourses(ProgramRequirement gradProgramRule, Integer requiredCredits, List<StudentCourse> studentCourses,
Integer totalCredits, Integer ldCourseCounter, boolean onlyMinGrade12CreditCourses) {
private Pair<Integer, Integer> processCourse(ProgramRequirement gradProgramRule, Integer requiredCredits, List<StudentCourse> studentCourses,
Integer totalCredits, Integer ldCourseCounter, boolean onlyMinGrade12CreditCourses) {
for (StudentCourse sc : studentCourses) {
if ((sc.isUsedInMatchRule() || sc.isUsedInMinCreditRule())
&& (sc.getLeftOverCredits() != null && sc.getLeftOverCredits() > 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
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.stream.Collectors;

public class RuleEngineApiUtils {

Expand Down Expand Up @@ -112,6 +114,18 @@ public static List<ProgramRequirement> getCloneProgramRule(List<ProgramRequireme
return Collections.emptyList();

}

public static List<ProgramRequirement> getMatchProgramRules(List<ProgramRequirement> gradProgramRules) {
if (gradProgramRules.isEmpty()) {
return new ArrayList<>();
}
return gradProgramRules.stream()
.filter(gradProgramRule -> "M".compareTo(gradProgramRule.getProgramRequirementCode().getRequirementTypeCode().getReqTypeCode()) == 0
&& "Y".compareTo(gradProgramRule.getProgramRequirementCode().getActiveRequirement()) == 0
&& "C".compareTo(gradProgramRule.getProgramRequirementCode().getRequirementCategory()) == 0)
.collect(Collectors.toList());
}

public static List<OptionalProgramRequirement> getCloneOptionalProgramRule(List<OptionalProgramRequirement> rules) {
ObjectMapper mapper = new ObjectMapper();
try {
Expand Down

0 comments on commit d345131

Please sign in to comment.