diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/MinistryReportTypeCode.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/MinistryReportTypeCode.java new file mode 100644 index 000000000..769222e6d --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/MinistryReportTypeCode.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.studentdatacollection.api.constants.v1; + +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + +@Getter +public enum MinistryReportTypeCode { + SCHOOL_ENROLLMENT_HEADCOUNTS("school-enrollment-headcounts"); + + private final String code; + MinistryReportTypeCode(String code) { this.code = code; } + + public static Optional findByValue(String value) { + return Arrays.stream(values()).filter(e -> Arrays.asList(e.code).contains(value)).findFirst(); + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/URL.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/URL.java index 8ccb459e9..8934e9bb5 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/URL.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/URL.java @@ -9,6 +9,7 @@ private URL(){ public static final String BASE_URL_COLLECTION="/api/v1/student-data-collection/collection"; public static final String BASE_URL_DISTRICT_COLLECTION="/api/v1/student-data-collection/sdcDistrictCollection"; public static final String BASE_DISTRICT_HEADCOUNTS = "/api/v1/student-data-collection/headcounts"; + public static final String BASE_MINISTRY_HEADCOUNTS = "/api/v1/student-data-collection/ministryHeadcounts"; public static final String BASE_URL_SCHOOL_COLLECTION="/api/v1/student-data-collection/sdcSchoolCollection"; public static final String BASE_URL_SCHOOL_COLLECTION_STUDENT="/api/v1/student-data-collection/sdcSchoolCollectionStudent"; public static final String BASE_URL_REPORT_GENERATION="/api/v1/student-data-collection/reportGeneration"; diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/ministryreports/SchoolEnrolmentHeader.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/ministryreports/SchoolEnrolmentHeader.java new file mode 100644 index 000000000..8ea82cbdf --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/ministryreports/SchoolEnrolmentHeader.java @@ -0,0 +1,34 @@ +package ca.bc.gov.educ.studentdatacollection.api.constants.v1.ministryreports; + +import lombok.Getter; + +@Getter +public enum SchoolEnrolmentHeader { + + SCHOOL_ENROLMENT_COLLECTION("School Enrolment Collection"), + SCHOOL_YEAR("School Year"), + DISTRICT_NUMBER("District Number"), + SCHOOL_NUMBER("School Number"), + SCHOOL_NAME("School Name"), + FACILITY_TYPE("Facility Type"), + SCHOOL_CATEGORY("School Category"), + GRADE_RANGE("Grade Range"), + REPORT_DATE("Report Date"), + KIND_HT_COUNT("Kind(H/T) Count"), + KIND_FT_COUNT("Kind(F/T) Count"), + GRADE_01_COUNT("Grade 1 Count"), + GRADE_02_COUNT("Grade 2 Count"), + GRADE_03_COUNT("Grade 3 Count"), + GRADE_04_COUNT("Grade 4 Count"), + GRADE_05_COUNT("Grade 5 Count"), + GRADE_06_COUNT("Grade 6 Count"), + GRADE_07_COUNT("Grade 7 Count"), + GRADE_08_COUNT("Grade 8 Count"), + GRADE_09_COUNT("Grade 9 Count"), + GRADE_10_COUNT("Grade 10 Count"), + GRADE_11_COUNT("Grade 11 Count"), + GRADE_12_COUNT("Grade 12 Count"); + + private final String code; + SchoolEnrolmentHeader(String code) { this.code = code; } +} diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryHeadcountReportsController.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryHeadcountReportsController.java new file mode 100644 index 000000000..b0de424d3 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryHeadcountReportsController.java @@ -0,0 +1,40 @@ +package ca.bc.gov.educ.studentdatacollection.api.controller.v1; + +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.MinistryReportTypeCode; +import ca.bc.gov.educ.studentdatacollection.api.endpoint.v1.MinistryHeadcountReports; +import ca.bc.gov.educ.studentdatacollection.api.exception.InvalidPayloadException; +import ca.bc.gov.educ.studentdatacollection.api.exception.errors.ApiError; +import ca.bc.gov.educ.studentdatacollection.api.service.v1.MinistryHeadcountService; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountResultsTable; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.util.Optional; +import java.util.UUID; + +import static org.springframework.http.HttpStatus.BAD_REQUEST; + +@RestController +@Slf4j +@RequiredArgsConstructor +public class MinistryHeadcountReportsController implements MinistryHeadcountReports { + + private final MinistryHeadcountService ministryHeadcountService; + + @Override + public HeadcountResultsTable getMinistryHeadcounts(UUID collectionID, String type) { + Optional code = MinistryReportTypeCode.findByValue(type); + + if(code.isEmpty()){ + ApiError error = ApiError.builder().timestamp(LocalDateTime.now()).message("Payload contains invalid report type code.").status(BAD_REQUEST).build(); + throw new InvalidPayloadException(error); + } + + return switch(code.get()) { + case SCHOOL_ENROLLMENT_HEADCOUNTS -> ministryHeadcountService.getAllSchoolEnrollmentHeadcounts(collectionID); + default -> new HeadcountResultsTable(); + }; + } +} diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/endpoint/v1/MinistryHeadcountReports.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/endpoint/v1/MinistryHeadcountReports.java new file mode 100644 index 000000000..9299c348e --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/endpoint/v1/MinistryHeadcountReports.java @@ -0,0 +1,23 @@ +package ca.bc.gov.educ.studentdatacollection.api.endpoint.v1; + +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.URL; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountResultsTable; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.UUID; + +@RequestMapping(URL.BASE_MINISTRY_HEADCOUNTS) +public interface MinistryHeadcountReports { + + @GetMapping("/{collectionID}/{type}") + @PreAuthorize("hasAuthority('SCOPE_READ_SDC_MINISTRY_REPORTS')") + @Transactional(readOnly = true) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "400", description = "BAD REQUEST")}) + HeadcountResultsTable getMinistryHeadcounts(@PathVariable UUID collectionID, @PathVariable(name = "type") String type); +} diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionStudentRepository.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionStudentRepository.java index b812ebb96..943701994 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionStudentRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionStudentRepository.java @@ -39,6 +39,28 @@ HAVING COUNT(assignedStudentId) > 1) long countBySdcSchoolCollection_SdcSchoolCollectionIDAndSdcSchoolCollectionStudentStatusCode(UUID sdcSchoolCollectionID, String sdcSchoolCollectionStatusCode); + @Query("SELECT " + + " sscs.sdcSchoolCollection.schoolID as schoolID, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = 'KH' THEN 1 END) as kindHCount, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = 'KF' THEN 1 END) as kindFCount, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '01' THEN 1 END) as grade1Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '02' THEN 1 END) as grade2Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '03' THEN 1 END) as grade3Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '04' THEN 1 END) as grade4Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '05' THEN 1 END) as grade5Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '06' THEN 1 END) as grade6Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '07' THEN 1 END) as grade7Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '08' THEN 1 END) as grade8Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '09' THEN 1 END) as grade9Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '10' THEN 1 END) as grade10Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '11' THEN 1 END) as grade11Count, " + + " COUNT(CASE WHEN sscs.enrolledGradeCode = '12' THEN 1 END) as grade12Count " + + " FROM SdcSchoolCollectionStudentEntity sscs " + + " WHERE sscs.sdcSchoolCollectionStudentStatusCode NOT IN ('ERROR', 'DELETED') " + + " AND sscs.sdcSchoolCollection.collectionEntity.collectionID = :collectionID " + + " GROUP BY sscs.sdcSchoolCollection.sdcSchoolCollectionID ") + List getAllEnrollmentHeadcountsByCollectionId(@Param("collectionID") UUID collectionID); + @Query(value = """ SELECT stud FROM SdcSchoolCollectionStudentLightEntity stud, SdcSchoolCollectionEntity school, SdcDistrictCollectionEntity dist diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/MinistryHeadcountService.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/MinistryHeadcountService.java new file mode 100644 index 000000000..eb065ec3b --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/MinistryHeadcountService.java @@ -0,0 +1,93 @@ +package ca.bc.gov.educ.studentdatacollection.api.service.v1; + +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.CollectionTypeCodes; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.ministryreports.SchoolEnrolmentHeader; +import ca.bc.gov.educ.studentdatacollection.api.exception.EntityNotFoundException; +import ca.bc.gov.educ.studentdatacollection.api.model.v1.CollectionEntity; +import ca.bc.gov.educ.studentdatacollection.api.repository.v1.CollectionRepository; +import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionStudentRepository; +import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.Collection; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountHeaderColumn; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountResultsTable; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.SchoolHeadcountResult; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.*; + +import static ca.bc.gov.educ.studentdatacollection.api.constants.v1.ministryreports.SchoolEnrolmentHeader.*; + + +@Service +@Slf4j +@RequiredArgsConstructor +public class MinistryHeadcountService { + private final CollectionRepository collectionRepository; + private final SdcSchoolCollectionStudentRepository sdcSchoolCollectionStudentRepository; + private final RestUtils restUtils; + private static final String COLLECTION_ID = "collectionID"; + + public HeadcountResultsTable getAllSchoolEnrollmentHeadcounts(UUID collectionID) { + List collectionRawData = sdcSchoolCollectionStudentRepository.getAllEnrollmentHeadcountsByCollectionId(collectionID); + var collectionOpt = collectionRepository.findById(collectionID); + if(collectionOpt.isEmpty()){ + throw new EntityNotFoundException(Collection.class, COLLECTION_ID, collectionID.toString()); + } + var collection = collectionOpt.get(); + + HeadcountResultsTable resultsTable = new HeadcountResultsTable(); + var headerList = new ArrayList(); + for (SchoolEnrolmentHeader header : SchoolEnrolmentHeader.values()) { + headerList.add(header.getCode()); + } + resultsTable.setHeaders(headerList); + var rows = new ArrayList>(); + collectionRawData.stream().forEach(schoolHeadcountResult -> { + var school = restUtils.getSchoolBySchoolID(schoolHeadcountResult.getSchoolID()).get(); + + var rowMap = new HashMap(); + rowMap.put(SCHOOL_YEAR.getCode(), getHeadcountColumn(getSchoolYearString(collection))); + rowMap.put(DISTRICT_NUMBER.getCode(), getHeadcountColumn(school.getMincode().substring(0,3))); + rowMap.put(SCHOOL_NUMBER.getCode(), getHeadcountColumn(school.getSchoolNumber())); + rowMap.put(SCHOOL_NAME.getCode(), getHeadcountColumn(school.getDisplayName())); + rowMap.put(FACILITY_TYPE.getCode(), getHeadcountColumn(school.getFacilityTypeCode())); + rowMap.put(SCHOOL_CATEGORY.getCode(), getHeadcountColumn(school.getSchoolCategoryCode())); + rowMap.put(REPORT_DATE.getCode(), getHeadcountColumn(collection.getSnapshotDate().toString())); + rowMap.put(KIND_HT_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getKindHCount())); + rowMap.put(KIND_FT_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getKindFCount())); + rowMap.put(GRADE_01_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade1Count())); + rowMap.put(GRADE_02_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade2Count())); + rowMap.put(GRADE_03_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade3Count())); + rowMap.put(GRADE_04_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade4Count())); + rowMap.put(GRADE_05_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade5Count())); + rowMap.put(GRADE_06_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade6Count())); + rowMap.put(GRADE_07_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade7Count())); + rowMap.put(GRADE_08_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade8Count())); + rowMap.put(GRADE_09_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade9Count())); + rowMap.put(GRADE_10_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade10Count())); + rowMap.put(GRADE_11_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade11Count())); + rowMap.put(GRADE_12_COUNT.getCode(), getHeadcountColumn(schoolHeadcountResult.getGrade12Count())); + rows.add(rowMap); + }); + resultsTable.setRows(rows); + return resultsTable; + } + + private HeadcountHeaderColumn getHeadcountColumn(String value){ + HeadcountHeaderColumn column = new HeadcountHeaderColumn(); + column.setCurrentValue(value); + return column; + } + + private String getSchoolYearString(CollectionEntity collection){ + var snapshotDateString = collection.getSnapshotDate(); + if(!collection.getCollectionTypeCode().equals(CollectionTypeCodes.SEPTEMBER.getTypeCode())){ + return snapshotDateString.minusYears(1).getYear() + "/" + snapshotDateString.getYear() + "SY"; + }else{ + return snapshotDateString.getYear() + "/" + snapshotDateString.plusYears(1).getYear() + "SY"; + } + } + +} diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/struct/v1/headcounts/SchoolHeadcountResult.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/struct/v1/headcounts/SchoolHeadcountResult.java new file mode 100644 index 000000000..a5f3e1493 --- /dev/null +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/struct/v1/headcounts/SchoolHeadcountResult.java @@ -0,0 +1,18 @@ +package ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts; + +public interface SchoolHeadcountResult extends HeadcountResult{ + String getKindHCount(); + String getKindFCount(); + String getGrade1Count(); + String getGrade2Count(); + String getGrade3Count(); + String getGrade4Count(); + String getGrade5Count(); + String getGrade6Count(); + String getGrade7Count(); + String getGrade8Count(); + String getGrade9Count(); + String getGrade10Count(); + String getGrade11Count(); + String getGrade12Count(); +} diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryReportsControllerTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryReportsControllerTest.java new file mode 100644 index 000000000..9f9487b63 --- /dev/null +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/controller/v1/MinistryReportsControllerTest.java @@ -0,0 +1,124 @@ +package ca.bc.gov.educ.studentdatacollection.api.controller.v1; + +import ca.bc.gov.educ.studentdatacollection.api.BaseStudentDataCollectionAPITest; +import ca.bc.gov.educ.studentdatacollection.api.StudentDataCollectionApiApplication; +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.URL; +import ca.bc.gov.educ.studentdatacollection.api.model.v1.CollectionEntity; +import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcDistrictCollectionEntity; +import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionEntity; +import ca.bc.gov.educ.studentdatacollection.api.repository.v1.CollectionRepository; +import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcDistrictCollectionRepository; +import ca.bc.gov.educ.studentdatacollection.api.repository.v1.SdcSchoolCollectionRepository; +import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils; +import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone; +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.HeadcountResultsTable; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.val; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockitoAnnotations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.OidcLoginRequestPostProcessor; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.servlet.MockMvc; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oidcLogin; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest(classes = {StudentDataCollectionApiApplication.class}) +@ActiveProfiles("test") +@AutoConfigureMockMvc +class MinistryReportsControllerTest extends BaseStudentDataCollectionAPITest { + + @Autowired + private MockMvc mockMvc; + @Autowired + SdcSchoolCollectionController sdcSchoolCollectionController; + + @Autowired + CollectionRepository collectionRepository; + + @Autowired + SdcSchoolCollectionRepository sdcSchoolCollectionRepository; + + @Autowired + SdcDistrictCollectionRepository sdcDistrictCollectionRepository; + @Autowired + private RestUtils restUtils; + @BeforeEach + public void setUp() { + MockitoAnnotations.openMocks(this); + } + + protected final static ObjectMapper objectMapper = JsonMapper.builder().addModule(new JavaTimeModule()).build(); + + @Test + void testGetMinistryReport_WithWrongType_ShouldReturnBadRequest() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SDC_MINISTRY_REPORTS"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + this.mockMvc.perform(get(URL.BASE_MINISTRY_HEADCOUNTS + "/" + UUID.randomUUID() + "/testing").with(mockAuthority)) + .andDo(print()).andExpect(status().isBadRequest()); + } + + @Test + void testGetMinistryReport_ValidType_ShouldReturnReportData() throws Exception { + final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_SDC_MINISTRY_REPORTS"; + final OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority); + + var school = this.createMockSchool(); + when(this.restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(school)); + + CollectionEntity collection = createMockCollectionEntity(); + collection.setCloseDate(LocalDateTime.now().plusDays(2)); + collection = collectionRepository.save(collection); + + SdcDistrictCollectionEntity sdcMockDistrict = createMockSdcDistrictCollectionEntity(collection, null); + var sdcDistrictCollectionID = sdcDistrictCollectionRepository.save(sdcMockDistrict).getSdcDistrictCollectionID(); + + SdcDistrictCollectionEntity sdcMockDistrict2 = createMockSdcDistrictCollectionEntity(collection, null); + var sdcDistrictCollectionID2 = sdcDistrictCollectionRepository.save(sdcMockDistrict2).getSdcDistrictCollectionID(); + + SchoolTombstone school1 = createMockSchool(); + school1.setDistrictId(sdcMockDistrict.getDistrictID().toString()); + SdcSchoolCollectionEntity sdcSchoolCollectionEntity1 = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school1.getSchoolId())); + sdcSchoolCollectionEntity1.setSdcDistrictCollectionID(sdcDistrictCollectionID); + + SchoolTombstone school2 = createMockSchool(); + school2.setDistrictId(sdcMockDistrict2.getDistrictID().toString()); + SdcSchoolCollectionEntity sdcSchoolCollectionEntity2 = createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school2.getSchoolId())); + sdcSchoolCollectionEntity2.setSdcDistrictCollectionID(sdcDistrictCollectionID2); + + sdcSchoolCollectionRepository.saveAll(List.of(sdcSchoolCollectionEntity1, sdcSchoolCollectionEntity2)); + + var sdcSchoolCollectionStudent1 = createMockSchoolStudentEntity(sdcSchoolCollectionEntity1); + var sdcSchoolCollectionStudent2 = createMockSchoolStudentEntity(sdcSchoolCollectionEntity2); + sdcSchoolCollectionStudentRepository.saveAll(List.of(sdcSchoolCollectionStudent1, sdcSchoolCollectionStudent2)); + + var resultActions1 = this.mockMvc.perform( + get(URL.BASE_MINISTRY_HEADCOUNTS + "/" + collection.getCollectionID() + "/school-enrollment-headcounts").with(mockAuthority)) + .andDo(print()).andExpect(status().isOk()); + + val summary1 = objectMapper.readValue(resultActions1.andReturn().getResponse().getContentAsByteArray(), new TypeReference() { + }); + + assertThat(summary1).isNotNull(); + assertThat(summary1.getRows()).hasSize(2); + } + +} diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/RulesProcessorTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/RulesProcessorTest.java index 8053f14fd..6de9c9f59 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/RulesProcessorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/RulesProcessorTest.java @@ -898,6 +898,7 @@ void testNoOfCoursesRules() { @Test void testSchoolFundingGroupRule() { val school = createMockSchool(); + //Needs independent school.setSchoolCategoryCode(SchoolCategoryCodes.INDEPEND.getCode()); var collection = collectionRepository.save(createMockCollectionEntity()); var sdcSchoolCollectionEntity = sdcSchoolCollectionRepository.save(createMockSdcSchoolCollectionEntity(collection, UUID.fromString(school.getSchoolId()))); diff --git a/tools/config/update-configmap.sh b/tools/config/update-configmap.sh index faca86d4d..f650de132 100644 --- a/tools/config/update-configmap.sh +++ b/tools/config/update-configmap.sh @@ -116,6 +116,13 @@ curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scope -H "Authorization: Bearer $TKN" \ -d "{\"description\": \"Read Student Data Collection School Collection Students\",\"id\": \"READ_SDC_SCHOOL_COLLECTION_STUDENT\",\"name\": \"READ_SDC_SCHOOL_COLLECTION_STUDENT\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" +echo +echo Writing scope READ_SDC_MINISTRY_REPORTS +curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $TKN" \ + -d "{\"description\": \"Read Student Data Collection Ministry Reports\",\"id\": \"READ_SDC_MINISTRY_REPORTS\",\"name\": \"READ_SDC_MINISTRY_REPORTS\",\"protocol\": \"openid-connect\",\"attributes\" : {\"include.in.token.scope\" : \"true\",\"display.on.consent.screen\" : \"false\"}}" + echo echo Writing scope READ_SCHOOL_FUNDING_GROUP_SNAPSHOT curl -sX POST "https://$SOAM_KC/auth/admin/realms/$SOAM_KC_REALM_ID/client-scopes" \