diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/SchoolGradeCodes.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/SchoolGradeCodes.java index c887e95d9..102493fdd 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/SchoolGradeCodes.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/SchoolGradeCodes.java @@ -165,4 +165,26 @@ public static List getGrades10toSU() { codes.add(SECONDARY_UNGRADED.getCode()); return codes; } + + public static List getNonIndependentSchoolGrades() { + List codes = new ArrayList<>(); + codes.add(KINDFULL.getCode()); + codes.add(GRADE01.getCode()); + codes.add(GRADE02.getCode()); + codes.add(GRADE03.getCode()); + codes.add(GRADE04.getCode()); + codes.add(GRADE05.getCode()); + codes.add(GRADE06.getCode()); + codes.add(GRADE07.getCode()); + codes.add(ELEMUNGR.getCode()); + codes.add(GRADE08.getCode()); + codes.add(GRADE09.getCode()); + codes.add(GRADE10.getCode()); + codes.add(GRADE11.getCode()); + codes.add(GRADE12.getCode()); + codes.add(SECONDARY_UNGRADED.getCode()); + codes.add(GRADUATED_ADULT.getCode()); + codes.add(HOMESCHOOL.getCode()); + return codes; + } } diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/CsfFrenchHeadcountHelper.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/CsfFrenchHeadcountHelper.java index c90fa79d4..3dd31fd2e 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/CsfFrenchHeadcountHelper.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/CsfFrenchHeadcountHelper.java @@ -1,9 +1,11 @@ package ca.bc.gov.educ.studentdatacollection.api.helpers; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes; import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.School; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.*; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; @@ -32,7 +34,14 @@ public CsfFrenchHeadcountHelper(SdcSchoolCollectionRepository sdcSchoolCollectio headcountMethods = getHeadcountMethods(); sectionTitles = getSelectionTitles(); rowTitles = getRowTitles(); - gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } + + public void setGradeCodes(Optional school) { + if(school.isPresent() && (school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDEPEND.getCode()) || school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDP_FNS.getCode()))) { + gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } else { + gradeCodes = SchoolGradeCodes.getNonIndependentSchoolGrades(); + } } public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, List headcountHeaderList) { UUID previousCollectionID = getPreviousSeptemberCollectionID(sdcSchoolCollectionEntity); diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EllHeadcountHelper.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EllHeadcountHelper.java index 29b7e6b39..cc959c9a8 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EllHeadcountHelper.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EllHeadcountHelper.java @@ -1,5 +1,6 @@ package ca.bc.gov.educ.studentdatacollection.api.helpers; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes; import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository; @@ -56,7 +57,14 @@ public EllHeadcountHelper( headcountMethods = getHeadcountMethods(); sectionTitles = getSelectionTitles(); rowTitles = getRowTitles(); - gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } + + public void setGradeCodes(Optional school) { + if(school.isPresent() && (school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDEPEND.getCode()) || school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDP_FNS.getCode()))) { + gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } else { + gradeCodes = SchoolGradeCodes.getNonIndependentSchoolGrades(); + } } public void setComparisonValues( diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EnrollmentHeadcountHelper.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EnrollmentHeadcountHelper.java index d88212cc4..35dfb8078 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EnrollmentHeadcountHelper.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/EnrollmentHeadcountHelper.java @@ -1,9 +1,11 @@ package ca.bc.gov.educ.studentdatacollection.api.helpers; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes; import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.School; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.EnrollmentHeadcountResult; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountHeader; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountHeaderColumn; @@ -42,9 +44,15 @@ public EnrollmentHeadcountHelper(SdcSchoolCollectionRepository sdcSchoolCollecti headcountMethods = getHeadcountMethods(); sectionTitles = getSelectionTitles(); rowTitles = getRowTitles(); - gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); } + public void setGradeCodes(Optional school) { + if(school.isPresent() && (school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDEPEND.getCode()) || school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDP_FNS.getCode()))) { + gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } else { + gradeCodes = SchoolGradeCodes.getNonIndependentSchoolGrades(); + } + } public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, List headcountHeaderList) { UUID previousCollectionID = getPreviousSeptemberCollectionID(sdcSchoolCollectionEntity); diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/FrenchHeadcountHelper.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/FrenchHeadcountHelper.java index 49ad8e509..2a7c783fb 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/FrenchHeadcountHelper.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/FrenchHeadcountHelper.java @@ -1,10 +1,12 @@ package ca.bc.gov.educ.studentdatacollection.api.helpers; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes; import ca.bc.gov.educ.studentdatacollection.api.exception.StudentDataCollectionAPIRuntimeException; import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.School; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.FrenchHeadcountHeaderResult; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.FrenchHeadcountResult; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountHeader; @@ -48,7 +50,14 @@ public FrenchHeadcountHelper(SdcSchoolCollectionRepository sdcSchoolCollectionRe headcountMethods = getHeadcountMethods(); sectionTitles = getSelectionTitles(); rowTitles = getRowTitles(); - gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } + + public void setGradeCodes(Optional school) { + if(school.isPresent() && (school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDEPEND.getCode()) || school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDP_FNS.getCode()))) { + gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } else { + gradeCodes = SchoolGradeCodes.getNonIndependentSchoolGrades(); + } } public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, List headcountHeaderList) { diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/SpecialEdHeadcountHelper.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/SpecialEdHeadcountHelper.java index 1d95f0e58..202392c64 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/SpecialEdHeadcountHelper.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/helpers/SpecialEdHeadcountHelper.java @@ -1,10 +1,12 @@ package ca.bc.gov.educ.studentdatacollection.api.helpers; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes; import ca.bc.gov.educ.studentdatacollection.api.exception.StudentDataCollectionAPIRuntimeException; import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository; import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.School; import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.*; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; @@ -60,7 +62,14 @@ public SpecialEdHeadcountHelper(SdcSchoolCollectionRepository sdcSchoolCollectio headcountMethods = getHeadcountMethods(); sectionTitles = getSelectionTitles(); rowTitles = getRowTitles(); - gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } + + public void setGradeCodes(Optional school) { + if(school.isPresent() && (school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDEPEND.getCode()) || school.get().getSchoolCategoryCode().equalsIgnoreCase(SchoolCategoryCodes.INDP_FNS.getCode()))) { + gradeCodes = Arrays.stream(SchoolGradeCodes.values()).map(SchoolGradeCodes::getCode).toList(); + } else { + gradeCodes = SchoolGradeCodes.getNonIndependentSchoolGrades(); + } } public void setComparisonValues(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, List headcountHeaderList) { diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/SdcSchoolCollectionStudentHeadcountService.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/SdcSchoolCollectionStudentHeadcountService.java index e1bcd4ef3..ed6851467 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/SdcSchoolCollectionStudentHeadcountService.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/SdcSchoolCollectionStudentHeadcountService.java @@ -29,9 +29,11 @@ public class SdcSchoolCollectionStudentHeadcountService { public SdcSchoolCollectionStudentHeadcounts getEnrollmentHeadcounts(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, boolean compare) { var sdcSchoolCollectionID = sdcSchoolCollectionEntity.getSdcSchoolCollectionID(); - + Optional school = this.restUtils.getSchoolBySchoolID(String.valueOf(sdcSchoolCollectionEntity.getSchoolID())); + enrollmentHeadcountHelper.setGradeCodes(school); List collectionRawData = sdcSchoolCollectionStudentRepository.getEnrollmentHeadcountsBySchoolId(sdcSchoolCollectionID); HeadcountResultsTable collectionData = enrollmentHeadcountHelper.convertHeadcountResults(collectionRawData); + List headcountHeaderList = Arrays.asList(enrollmentHeadcountHelper.getStudentsHeadcountTotals(collectionData), enrollmentHeadcountHelper.getGradesHeadcountTotals(collectionData)); if (compare) { enrollmentHeadcountHelper.setComparisonValues(sdcSchoolCollectionEntity, headcountHeaderList); @@ -48,6 +50,7 @@ public SdcSchoolCollectionStudentHeadcounts getFrenchHeadcounts(SdcSchoolCollect HeadcountResultsTable collectionData; if(school.isPresent() && school.get().getSchoolReportingRequirementCode().equals(SchoolReportingRequirementCodes.CSF.getCode())) { List collectionRawData; + csfFrenchHeadcountHelper.setGradeCodes(school); collectionRawData = sdcSchoolCollectionStudentRepository.getCsfFrenchHeadcountsBySchoolId(sdcSchoolCollectionID); headcountHeaderList = csfFrenchHeadcountHelper.getHeaders(sdcSchoolCollectionID); collectionData = csfFrenchHeadcountHelper.convertHeadcountResults(collectionRawData); @@ -56,6 +59,7 @@ public SdcSchoolCollectionStudentHeadcounts getFrenchHeadcounts(SdcSchoolCollect } } else { List collectionRawData; + frenchHeadcountHelper.setGradeCodes(school); collectionRawData = sdcSchoolCollectionStudentRepository.getFrenchHeadcountsBySchoolId(sdcSchoolCollectionID); headcountHeaderList = frenchHeadcountHelper.getHeaders(sdcSchoolCollectionID); collectionData = frenchHeadcountHelper.convertHeadcountResults(collectionRawData); @@ -63,6 +67,7 @@ public SdcSchoolCollectionStudentHeadcounts getFrenchHeadcounts(SdcSchoolCollect frenchHeadcountHelper.setComparisonValues(sdcSchoolCollectionEntity, headcountHeaderList); } } + return SdcSchoolCollectionStudentHeadcounts.builder().headcountHeaders(headcountHeaderList).headcountResultsTable(collectionData).build(); } @@ -90,6 +95,8 @@ public SdcSchoolCollectionStudentHeadcounts getIndigenousHeadcounts(SdcSchoolCol public SdcSchoolCollectionStudentHeadcounts getEllHeadcounts(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, boolean compare) { var sdcSchoolCollectionID = sdcSchoolCollectionEntity.getSdcSchoolCollectionID(); + Optional school = this.restUtils.getSchoolBySchoolID(String.valueOf(sdcSchoolCollectionEntity.getSchoolID())); + ellHeadcountHelper.setGradeCodes(school); List collectionRawData = sdcSchoolCollectionStudentRepository.getEllHeadcountsBySchoolId(sdcSchoolCollectionID); @@ -104,6 +111,8 @@ public SdcSchoolCollectionStudentHeadcounts getEllHeadcounts(SdcSchoolCollection public SdcSchoolCollectionStudentHeadcounts getSpecialEdHeadcounts(SdcSchoolCollectionEntity sdcSchoolCollectionEntity, boolean compare) { var sdcSchoolCollectionID = sdcSchoolCollectionEntity.getSdcSchoolCollectionID(); + Optional school = this.restUtils.getSchoolBySchoolID(String.valueOf(sdcSchoolCollectionEntity.getSchoolID())); + specialEdHeadcountHelper.setGradeCodes(school); List result = sdcSchoolCollectionStudentRepository.getSpecialEdHeadcountsBySchoolId(sdcSchoolCollectionID); HeadcountResultsTable headcountResultsTable = specialEdHeadcountHelper.convertHeadcountResults(result); diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/SdcSchoolCollectionStudentControllerTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/SdcSchoolCollectionStudentControllerTest.java index d8b8faa97..aa61fca41 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/SdcSchoolCollectionStudentControllerTest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/SdcSchoolCollectionStudentControllerTest.java @@ -44,9 +44,7 @@ import static ca.bc.gov.educ.studentdatacollection.api.struct.v1.Condition.AND; import static ca.bc.gov.educ.studentdatacollection.api.struct.v1.Condition.OR; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.*; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; @@ -931,6 +929,52 @@ void testGetSdcSchoolCollectionStudentHeadcounts_enrollmentHeadcounts() throws E } + @Test + void testGetSdcSchoolCollectionStudentHeadcountsForINDEPENDSchool_enrollmentHeadcounts() throws Exception { + var collection = collectionRepository.save(createMockCollectionEntity()); + var school = this.createMockSchool(); + school.setSchoolCategoryCode("INDEPEND"); + when(this.restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(school)); + var firstSchool = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school.getSchoolId()), UUID.fromString(school.getDistrictId())); + firstSchool.setUploadDate(null); + firstSchool.setUploadFileName(null); + var secondSchool = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school.getSchoolId()), UUID.fromString(school.getDistrictId())); + secondSchool.setUploadDate(null); + secondSchool.setUploadFileName(null); + secondSchool.setCreateDate(LocalDateTime.of(Year.now().getValue() - 1, Month.SEPTEMBER, 7, 0, 0)); + sdcSchoolCollectionRepository.saveAll(Arrays.asList(firstSchool, secondSchool)); + + + final File file = new File( + Objects.requireNonNull(this.getClass().getClassLoader().getResource("sdc-school-students-test-data.json")).getFile() + ); + final List entities = new ObjectMapper().readValue(file, new TypeReference<>() { + }); + var models = entities.stream().map(SdcSchoolCollectionStudentMapper.mapper::toSdcSchoolStudentEntity).toList(); + var students = IntStream.range(0, models.size()) + .mapToObj(i -> { + if (i % 2 == 0) { + models.get(i).setSdcSchoolCollection(secondSchool); + } else { + models.get(i).setSdcSchoolCollection(firstSchool); + } + return models.get(i); + }) + .toList(); + + sdcSchoolCollectionStudentRepository.saveAll(students); + + this.mockMvc + .perform(get(URL.BASE_URL_SCHOOL_COLLECTION_STUDENT + "/" + URL.HEADCOUNTS + "/" + firstSchool.getSdcSchoolCollectionID()) + .with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_SDC_SCHOOL_COLLECTION_STUDENT"))) + .param("type", "enrollment") + .param("compare", "true") + .contentType(APPLICATION_JSON)) + .andDo(print()) + .andExpect(MockMvcResultMatchers.jsonPath("$.headcountResultsTable.headers", not(hasItemInArray("KH")))); + + } + @Test void testGetSdcSchoolCollectionStudentHeadcounts_frenchHeadcounts() throws Exception { var collection = collectionRepository.save(createMockCollectionEntity()); @@ -994,6 +1038,67 @@ void testGetSdcSchoolCollectionStudentHeadcounts_frenchHeadcounts() throws Excep .andExpect(MockMvcResultMatchers.jsonPath("$.headcountHeaders[1].title", equalTo("Early French Immersion"))) .andExpect(MockMvcResultMatchers.jsonPath("$.headcountHeaders[1].columns.['Not Reported'].currentValue", equalTo("4"))) .andExpect(MockMvcResultMatchers.jsonPath("$.headcountHeaders[1].columns.['Reported'].comparisonValue", equalTo("0"))); + } + + @Test + void testGetSdcSchoolCollectionStudentHeadcountsForINDP_FNSSchool_frenchHeadcounts() throws Exception { + var collection = collectionRepository.save(createMockCollectionEntity()); + var school = this.createMockSchool(); + school.setSchoolCategoryCode("INDP_FNS"); + school.setSchoolReportingRequirementCode(SchoolReportingRequirementCodes.REGULAR.getCode()); + when(this.restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(school)); + var firstSchool = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school.getSchoolId()), UUID.fromString(school.getDistrictId())); + firstSchool.setUploadDate(null); + firstSchool.setUploadFileName(null); + var secondSchool = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school.getSchoolId()), UUID.fromString(school.getDistrictId())); + secondSchool.setUploadDate(null); + secondSchool.setUploadFileName(null); + secondSchool.setCreateDate(LocalDateTime.of(Year.now().getValue() - 1, Month.SEPTEMBER, 7, 0, 0)); + sdcSchoolCollectionRepository.saveAll(Arrays.asList(firstSchool, secondSchool)); + + final File file = new File( + Objects.requireNonNull(this.getClass().getClassLoader().getResource("sdc-school-students-test-data.json")).getFile() + ); + final List entities = new ObjectMapper().readValue(file, new TypeReference<>() { + }); + var models = entities.stream().map(SdcSchoolCollectionStudentMapper.mapper::toSdcSchoolStudentEntity).toList(); + var students = IntStream.range(0, models.size()) + .mapToObj(i -> { + if (i % 2 == 0) { + models.get(i).setSdcSchoolCollection(secondSchool); + } else { + models.get(i).setSdcSchoolCollection(firstSchool); + } + return models.get(i); + }) + .toList(); + + var savedStudents = sdcSchoolCollectionStudentRepository.saveAll(students); + + List enrolledPrograms = new ArrayList<>(); + + savedStudents.forEach(student -> { + var enrolledProg = new SdcSchoolCollectionStudentEnrolledProgramEntity(); + enrolledProg.setSdcSchoolCollectionStudentEntity(student); + enrolledProg.setEnrolledProgramCode("14"); + enrolledProg.setCreateUser("ABC"); + enrolledProg.setUpdateUser("ABC"); + enrolledProg.setCreateDate(LocalDateTime.now()); + enrolledProg.setUpdateDate(LocalDateTime.now()); + enrolledPrograms.add(enrolledProg); + }); + + + sdcSchoolCollectionStudentEnrolledProgramRepository.saveAll(enrolledPrograms); + + this.mockMvc + .perform(get(URL.BASE_URL_SCHOOL_COLLECTION_STUDENT + "/" + URL.HEADCOUNTS + "/" + firstSchool.getSdcSchoolCollectionID()) + .with(jwt().jwt((jwt) -> jwt.claim("scope", "READ_SDC_SCHOOL_COLLECTION_STUDENT"))) + .param("type", "french") + .param("compare", "true") + .contentType(APPLICATION_JSON)) + .andDo(print()) + .andExpect(MockMvcResultMatchers.jsonPath("$.headcountResultsTable.headers", not(hasItemInArray("KH")))); }