-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1056 from bcgov/feature/sped
Added first Ministry report
- Loading branch information
Showing
11 changed files
with
381 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...in/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/MinistryReportTypeCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MinistryReportTypeCode> findByValue(String value) { | ||
return Arrays.stream(values()).filter(e -> Arrays.asList(e.code).contains(value)).findFirst(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ov/educ/studentdatacollection/api/constants/v1/ministryreports/SchoolEnrolmentHeader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; } | ||
} |
40 changes: 40 additions & 0 deletions
40
.../gov/educ/studentdatacollection/api/controller/v1/MinistryHeadcountReportsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MinistryReportTypeCode> 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(); | ||
}; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...n/java/ca/bc/gov/educ/studentdatacollection/api/endpoint/v1/MinistryHeadcountReports.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...in/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/MinistryHeadcountService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SchoolHeadcountResult> 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<String>(); | ||
for (SchoolEnrolmentHeader header : SchoolEnrolmentHeader.values()) { | ||
headerList.add(header.getCode()); | ||
} | ||
resultsTable.setHeaders(headerList); | ||
var rows = new ArrayList<Map<String, HeadcountHeaderColumn>>(); | ||
collectionRawData.stream().forEach(schoolHeadcountResult -> { | ||
var school = restUtils.getSchoolBySchoolID(schoolHeadcountResult.getSchoolID()).get(); | ||
|
||
var rowMap = new HashMap<String, HeadcountHeaderColumn>(); | ||
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"; | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
.../ca/bc/gov/educ/studentdatacollection/api/struct/v1/headcounts/SchoolHeadcountResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
Oops, something went wrong.