|
| 1 | +package ca.bc.gov.educ.studentdatacollection.api.rules.validationrules.impl; |
| 2 | + |
| 3 | +import ca.bc.gov.educ.studentdatacollection.api.calculator.FteCalculatorUtils; |
| 4 | +import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationFieldCode; |
| 5 | +import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationIssueSeverityCode; |
| 6 | +import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationIssueTypeCode; |
| 7 | +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.CollectionTypeCodes; |
| 8 | +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes; |
| 9 | +import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolGradeCodes; |
| 10 | +import ca.bc.gov.educ.studentdatacollection.api.model.v1.SdcSchoolCollectionStudentEntity; |
| 11 | +import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils; |
| 12 | +import ca.bc.gov.educ.studentdatacollection.api.rules.ValidationBaseRule; |
| 13 | +import ca.bc.gov.educ.studentdatacollection.api.service.v1.ValidationRulesService; |
| 14 | +import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData; |
| 15 | +import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone; |
| 16 | +import ca.bc.gov.educ.studentdatacollection.api.struct.v1.SdcSchoolCollectionStudentValidationIssue; |
| 17 | +import lombok.extern.slf4j.Slf4j; |
| 18 | +import org.springframework.core.annotation.Order; |
| 19 | +import org.springframework.stereotype.Component; |
| 20 | + |
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Optional; |
| 24 | + |
| 25 | +/** |
| 26 | + * | ID | Severity | Rule | Dependent On | |
| 27 | + * |----- |----------|-------------------------------------------------------------- |--------------| |
| 28 | + * | V103 | ERROR | Student included in any collection in this school year | V92 | |
| 29 | + * for the authority with FTE > 0 in any school with type |
| 30 | + * different from online |
| 31 | + * OR if the student reported in Online school in the authority |
| 32 | + * in grade K to 9 with FTE >0 |
| 33 | + */ |
| 34 | +@Component |
| 35 | +@Slf4j |
| 36 | +@Order(1030) |
| 37 | +public class SummerStudentReportedInAuthorityRule implements ValidationBaseRule { |
| 38 | + private final ValidationRulesService validationRulesService; |
| 39 | + private final RestUtils restUtils; |
| 40 | + |
| 41 | + public SummerStudentReportedInAuthorityRule(ValidationRulesService validationRulesService, RestUtils restUtils) { |
| 42 | + this.validationRulesService = validationRulesService; |
| 43 | + this.restUtils = restUtils; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public boolean shouldExecute(StudentRuleData studentRuleData, List<SdcSchoolCollectionStudentValidationIssue> validationErrorsMap) { |
| 48 | + log.debug("In shouldExecute of SummerStudentReportedInAuthorityRule-V93: for collectionType {} and sdcSchoolCollectionStudentID :: {}", FteCalculatorUtils.getCollectionTypeCode(studentRuleData), |
| 49 | + studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID()); |
| 50 | + return !studentRuleData.getSchool().getFacilityTypeCode().equalsIgnoreCase(FacilityTypeCodes.SUMMER.getCode()) && |
| 51 | + FteCalculatorUtils.getCollectionTypeCode(studentRuleData).equalsIgnoreCase(CollectionTypeCodes.JULY.getTypeCode()) && |
| 52 | + isValidationDependencyResolved("V103", validationErrorsMap); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public List<SdcSchoolCollectionStudentValidationIssue> executeValidation(StudentRuleData studentRuleData) { |
| 57 | + log.debug("In executeValidation of SummerStudentReportedInAuthorityRule-V93 for sdcSchoolCollectionStudentID ::" + studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID()); |
| 58 | + final List<SdcSchoolCollectionStudentValidationIssue> errors = new ArrayList<>(); |
| 59 | + validationRulesService.setupPENMatchAndEllAndGraduateValues(studentRuleData); |
| 60 | + if (studentRuleData.getSdcSchoolCollectionStudentEntity().getAssignedStudentId() != null) { |
| 61 | + var historicalStudentCollection = validationRulesService.getStudentInHistoricalCollectionWithInSameAuthority(studentRuleData, "3"); |
| 62 | + for (SdcSchoolCollectionStudentEntity studentEntity : historicalStudentCollection) { |
| 63 | + Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(studentEntity.getSdcSchoolCollection().getSchoolID().toString()); |
| 64 | + if (school.isPresent()) { |
| 65 | + boolean isOnlineSchool = FacilityTypeCodes.getOnlineFacilityTypeCodes().contains(school.get().getFacilityTypeCode()); |
| 66 | + if (!isOnlineSchool || SchoolGradeCodes.getKToNineGrades().contains(studentEntity.getEnrolledGradeCode())) { |
| 67 | + errors.add(createValidationIssue(StudentValidationIssueSeverityCode.FUNDING_WARNING, StudentValidationFieldCode.ENROLLED_GRADE_CODE, StudentValidationIssueTypeCode.SUMMER_STUDENT_ALREADY_REPORTED_AUTHORITY_ERROR)); |
| 68 | + break; |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + return errors; |
| 74 | + } |
| 75 | + |
| 76 | +} |
| 77 | + |
0 commit comments