diff --git a/api/src/main/java/ca/bc/gov/educ/grad/report/dto/impl/TranscriptCourseImpl.java b/api/src/main/java/ca/bc/gov/educ/grad/report/dto/impl/TranscriptCourseImpl.java index befef943..91d111f6 100644 --- a/api/src/main/java/ca/bc/gov/educ/grad/report/dto/impl/TranscriptCourseImpl.java +++ b/api/src/main/java/ca/bc/gov/educ/grad/report/dto/impl/TranscriptCourseImpl.java @@ -18,6 +18,7 @@ package ca.bc.gov.educ.grad.report.dto.impl; import ca.bc.gov.educ.grad.report.model.transcript.TranscriptCourse; +import org.apache.commons.lang3.StringUtils; import java.util.Objects; import java.util.logging.Logger; @@ -240,20 +241,17 @@ public boolean courseEquals(final TranscriptCourse compareCourse) { @Override public boolean compareCourse(final TranscriptCourse compareCourse) { - final int interimPercentage = getInt(this.getInterimMark()); - final int finalPercentage = getInt(this.getFinalPercent()); - final int compareFinalPercentage = getInt(compareCourse.getFinalPercent()); - final int compareInterimPercentage = getInt(compareCourse.getInterimMark()); + // Interim % should only be looked at if the courses do not have a final LG + final int percentage = StringUtils.isBlank(this.getFinalLetterGrade())? getInt(this.getInterimMark()) : getInt(this.getFinalPercent()); + final int comparePercentage = StringUtils.isBlank(compareCourse.getFinalLetterGrade())? getInt(compareCourse.getInterimMark()) : getInt(compareCourse.getFinalPercent()); // Removes duplication of courses by comparing and finding course with - //highest percentage. - boolean replaceCourse = ((interimPercentage < compareFinalPercentage - && finalPercentage < compareFinalPercentage - && compareFinalPercentage != 0) - || (finalPercentage < compareInterimPercentage - && finalPercentage != 0 - && compareInterimPercentage != 0)); - return replaceCourse; + // highest percentage. + return percentage <= comparePercentage && comparePercentage != 0; + } + + public boolean isCompletedCourseUsedForGrad() { + return StringUtils.isNotBlank(this.finalLetterGrade) && StringUtils.isNotBlank(this.requirement); } /** diff --git a/api/src/main/java/ca/bc/gov/educ/grad/report/model/transcript/TranscriptCourse.java b/api/src/main/java/ca/bc/gov/educ/grad/report/model/transcript/TranscriptCourse.java index bcf73bc5..c413a742 100644 --- a/api/src/main/java/ca/bc/gov/educ/grad/report/model/transcript/TranscriptCourse.java +++ b/api/src/main/java/ca/bc/gov/educ/grad/report/model/transcript/TranscriptCourse.java @@ -178,4 +178,10 @@ public interface TranscriptCourse { * @return true when compareCourse has highest marks. */ boolean compareCourse(final TranscriptCourse compareCourse); + + /** + * Check this course is completed and used for graduation + * @return + */ + boolean isCompletedCourseUsedForGrad(); } diff --git a/api/src/main/java/ca/bc/gov/educ/grad/report/service/impl/StudentTranscriptServiceImpl.java b/api/src/main/java/ca/bc/gov/educ/grad/report/service/impl/StudentTranscriptServiceImpl.java index 5f8b6b22..1787947a 100644 --- a/api/src/main/java/ca/bc/gov/educ/grad/report/service/impl/StudentTranscriptServiceImpl.java +++ b/api/src/main/java/ca/bc/gov/educ/grad/report/service/impl/StudentTranscriptServiceImpl.java @@ -48,6 +48,7 @@ import java.time.LocalDate; import java.util.*; import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; import java.util.logging.Logger; @@ -710,12 +711,13 @@ private List filterCourses(final List result private TranscriptCourse getInterimCourse( TranscriptCourse course, final List results) { - //Check for dulicate courses + //Check for duplicate courses for (final TranscriptCourse compareCourse : results) { //Check and compare two courses for duplication and if required //replace course based on requirement. if (course.courseEquals(compareCourse) - && course.compareCourse(compareCourse)) { + && !course.isCompletedCourseUsedForGrad() + && course.compareCourse(compareCourse) ) { course = compareCourse; } }