Skip to content

Commit 064ee1f

Browse files
authored
Added special handling for IDS course titles as per spec (#637)
1 parent 82a9c29 commit 064ee1f

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

api/src/main/java/ca/bc/gov/educ/api/graduation/service/ReportService.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,15 +666,31 @@ private String getAssessmentFinalPercentTranscript(StudentAssessment sA) {
666666

667667
@Generated
668668
private String getCourseNameLogic(StudentCourse sc) {
669-
if (sc.getGenericCourseType() != null && sc.getGenericCourseType().equalsIgnoreCase("I") && StringUtils.isNotBlank(sc.getRelatedCourse()) && StringUtils.isNotBlank(sc.getRelatedLevel()) && StringUtils.isNotBlank(sc.getRelatedCourseName())) {
670-
return "IDS " + sc.getRelatedCourseName();
669+
if (isIndependentDirectedStudiesCourse(sc)) {
670+
if (StringUtils.isNotBlank(sc.getRelatedCourseName())) {
671+
return "IDS " + sc.getRelatedCourseName();
672+
}
673+
674+
String baseCourseTitle = StringUtils.defaultIfBlank(sc.getCustomizedCourseName(), sc.getCourseName());
675+
if (StringUtils.isNotBlank(baseCourseTitle)) {
676+
return StringUtils.startsWithIgnoreCase(baseCourseTitle, "IDS ") ? baseCourseTitle : "IDS " + baseCourseTitle;
677+
}
671678
}
672679
if (StringUtils.isNotBlank(sc.getCustomizedCourseName())) {
673680
return sc.getCustomizedCourseName();
674681
}
675682
return sc.getCourseName();
676683
}
677684

685+
private boolean isIndependentDirectedStudiesCourse(StudentCourse sc) {
686+
return sc != null && (
687+
sc.isIndependentDirectedStudies()
688+
|| StringUtils.equalsIgnoreCase(sc.getGenericCourseType(), "I")
689+
|| StringUtils.startsWithIgnoreCase(sc.getCourseCode(), "IDS")
690+
|| StringUtils.startsWithIgnoreCase(sc.getCourseName(), "Independent Directed Studies")
691+
);
692+
}
693+
678694
private String getValue(Double value) {
679695
return value != null && value != 0.0 ? new DecimalFormat("#").format(value) : "";
680696
}

api/src/test/java/ca/bc/gov/educ/api/graduation/service/ReportServiceTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,49 @@ public void testIsHigherCompletedPercentageHandlesNullsAndComparison() {
183183
assertFalse(bothNullResult);
184184
}
185185

186+
@Test
187+
public void testGetCourseNameLogicForIdsUsesRelatedCourseName() {
188+
StudentCourse idsCourse = StudentCourse.builder()
189+
.genericCourseType("I")
190+
.courseCode("IDS")
191+
.courseName("Independent Directed Studies 12A")
192+
.relatedCourse("MATH")
193+
.relatedLevel("12")
194+
.relatedCourseName("Calculus 12")
195+
.build();
196+
197+
String result = ReflectionTestUtils.invokeMethod(reportService, "getCourseNameLogic", idsCourse);
198+
199+
assertEquals("IDS Calculus 12", result);
200+
}
201+
202+
@Test
203+
public void testGetCourseNameLogicForIdsFallsBackToCourseNameWhenRelatedCourseBlank() {
204+
StudentCourse idsCourse = StudentCourse.builder()
205+
.genericCourseType("I")
206+
.courseCode("IDS")
207+
.courseName("Independent Directed Studies 10A")
208+
.build();
209+
210+
String result = ReflectionTestUtils.invokeMethod(reportService, "getCourseNameLogic", idsCourse);
211+
212+
assertEquals("IDS Independent Directed Studies 10A", result);
213+
}
214+
215+
@Test
216+
public void testGetCourseNameLogicForIdsFallsBackToCustomizedCourseNameWhenRelatedCourseBlank() {
217+
StudentCourse idsCourse = StudentCourse.builder()
218+
.isIndependentDirectedStudies(true)
219+
.courseCode("IDS")
220+
.courseName("Independent Directed Studies 10A")
221+
.customizedCourseName("Marine Studies 12A")
222+
.build();
223+
224+
String result = ReflectionTestUtils.invokeMethod(reportService, "getCourseNameLogic", idsCourse);
225+
226+
assertEquals("IDS Marine Studies 12A", result);
227+
}
228+
186229
@Test
187230
public void testGetStudentsForSchoolYearEndNonGradReportWithMincode() {
188231
List<ReportGradStudentData> gradStudentDataList = createStudentSchoolYearEndData("json/studentSchoolYearEndResponse.json");

0 commit comments

Comments
 (0)