Skip to content

Commit 8d4bf1b

Browse files
authored
Merge pull request #1627 from bcgov/feature/EDX-3179
v103
2 parents 27a12b3 + 7a8e05e commit 8d4bf1b

File tree

8 files changed

+591
-10
lines changed

8 files changed

+591
-10
lines changed

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/StudentValidationIssueTypeCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public enum StudentValidationIssueTypeCode {
100100
REFUGEE_IN_PREV_COL("REFUGEEINPREVCOL", "School-aged students reported in the previous collection are not eligible for newcomer refugee funding.", FUNDING_WARNING),
101101
REFUGEE_IS_ADULT("REFUGEEISADULT", "Adults are not eligible for February newcomer refugee funding.", FUNDING_WARNING),
102102
SUMMER_PUBLIC_SCHOOL_GRADE_ERROR("SUMMERPUBLICSCHOOLGRADEERROR","8/9 cross enrolment students must be in grades 8 or 9", ERROR),
103-
SUMMER_STUDENT_ALREADY_REPORTED_ERROR("SUMMERSTUDENTREPORTEDINDISTRICTERROR","The student has already been reported during the current school year.", ERROR),
103+
SUMMER_STUDENT_ALREADY_REPORTED_DISTRICT_ERROR("SUMMERSTUDENTREPORTEDINDISTRICTERROR","The student has already been reported by the district during the current school year.", ERROR),
104+
SUMMER_STUDENT_ALREADY_REPORTED_AUTHORITY_ERROR("SUMMERSTUDENTREPORTEDINDISTRICTERROR","The student has already been reported by the authority during the current school year.", ERROR),
104105
SUMMER_STUDENT_REPORTED_NOT_IN_DISTRICT_ERROR("SUMMERSTUDENTREPORTEDNOTINDISTRICTERROR","Student was not reported in Grade 8 or 9 this school year and cannot be reported in 8/9 cross enrolment in this collection.", FUNDING_WARNING),
105106
SUMMER_ADULT_STUDENT_ERROR("SUMMERADULTSTUDENTERROR","Adult students cannot be reported in 8/9 cross enrolment", ERROR),
106107
SUMMER_FUNDING_CODE_ERROR("SUMMERFUNDINGCODEERROR","Out of Province/International students cannot be reported in Summer collection", ERROR),

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/constants/v1/ValidationRulesDependencyMatrix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public enum ValidationRulesDependencyMatrix {
6969
ENTRY61("V98", new String[]{DOB_INVALID_FORMAT.getCode()}),
7070
ENTRY62("V100", new String[]{ENROLLED_CODE_PARSE_ERR.getCode()}),
7171
ENTRY63("V102", new String[]{SUMMER_PUBLIC_SCHOOL_GRADE_ERROR.getCode(), SUMMER_STUDENT_REPORTED_NOT_IN_DISTRICT_ERROR.getCode()}),
72-
72+
ENTRY64("V103", new String[]{SUMMER_PUBLIC_SCHOOL_GRADE_ERROR.getCode()}),
7373
;
7474

7575
@Getter

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionStudentRepository.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,20 @@ NOT IN (SELECT saga.sdcSchoolCollectionStudentID FROM SdcSagaEntity saga WHERE s
11011101
""")
11021102
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscalWithInSameDistrict(UUID districtID, List<UUID> assignedStudentIDs, String noOfCollections, UUID collectionID, LocalDate snapshotDate);
11031103

1104+
@Query(value="""
1105+
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS
1106+
WHERE SSC.schoolID IN :schoolIDs
1107+
AND C.collectionID = SSC.collectionEntity.collectionID
1108+
AND SSC.sdcSchoolCollectionID = SSCS.sdcSchoolCollection.sdcSchoolCollectionID
1109+
AND SSCS.assignedStudentId in :assignedStudentIDs
1110+
AND C.collectionID != :collectionID
1111+
AND SSCS.fte > 0
1112+
AND SSCS.sdcSchoolCollectionStudentStatusCode != 'DELETED'
1113+
AND C.collectionID IN
1114+
(SELECT CE.collectionID FROM CollectionEntity CE WHERE CE.collectionStatusCode = 'COMPLETED' AND CE.snapshotDate < :snapshotDate ORDER BY CE.snapshotDate DESC LIMIT :noOfCollections)
1115+
""")
1116+
List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscalWithInSameAuthority(List<UUID> schoolIDs, List<UUID> assignedStudentIDs, String noOfCollections, UUID collectionID, LocalDate snapshotDate);
1117+
11041118
@Query(value="""
11051119
SELECT SSCS FROM SdcSchoolCollectionEntity SSC, CollectionEntity C, SdcSchoolCollectionStudentEntity SSCS
11061120
WHERE C.collectionID = SSC.collectionEntity.collectionID
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/rules/validationrules/impl/SummerStudentReportedInDistrictRule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* |-----|----------|-------------------------------------------------------------- |--------------|
2828
* | V93 | ERROR | Student included in any collection in this school year | V92 |
2929
* for the district with FTE > 0 in any school with type
30-
* different than online
30+
* different from online
3131
* OR if the student reported in Online school in the district
3232
* in grade K to 9 with FTE >0
3333
*/
@@ -64,7 +64,7 @@ public List<SdcSchoolCollectionStudentValidationIssue> executeValidation(Student
6464
if (school.isPresent()) {
6565
boolean isOnlineSchool = FacilityTypeCodes.getOnlineFacilityTypeCodes().contains(school.get().getFacilityTypeCode());
6666
if (!isOnlineSchool || SchoolGradeCodes.getKToNineGrades().contains(studentEntity.getEnrolledGradeCode())) {
67-
errors.add(createValidationIssue(StudentValidationIssueSeverityCode.FUNDING_WARNING, StudentValidationFieldCode.ENROLLED_GRADE_CODE, StudentValidationIssueTypeCode.SUMMER_STUDENT_ALREADY_REPORTED_ERROR));
67+
errors.add(createValidationIssue(StudentValidationIssueSeverityCode.FUNDING_WARNING, StudentValidationFieldCode.ENROLLED_GRADE_CODE, StudentValidationIssueTypeCode.SUMMER_STUDENT_ALREADY_REPORTED_DISTRICT_ERROR));
6868
break;
6969
}
7070
}

api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/service/v1/ValidationRulesService.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ca.bc.gov.educ.studentdatacollection.api.rest.RestUtils;
1212
import ca.bc.gov.educ.studentdatacollection.api.struct.StudentRuleData;
1313
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.IndependentSchoolFundingGroup;
14+
import ca.bc.gov.educ.studentdatacollection.api.struct.external.institute.v1.SchoolTombstone;
1415
import ca.bc.gov.educ.studentdatacollection.api.struct.external.penmatch.v1.PenMatchResult;
1516
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.*;
1617
import lombok.Getter;
@@ -216,6 +217,17 @@ public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionWi
216217
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameDistrict(UUID.fromString(studentRuleData.getSchool().getDistrictId()), studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
217218
}
218219

220+
public List<SdcSchoolCollectionStudentEntity> getStudentInHistoricalCollectionWithInSameAuthority(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {
221+
setupMergedStudentIdValues(studentRuleData);
222+
var collection = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity();
223+
List<SchoolTombstone> allSchools = this.restUtils.getSchools();
224+
List<UUID> independentSchoolIDsWithSameAuthorityID = allSchools.stream()
225+
.filter(school -> school.getIndependentAuthorityId() != null && school.getIndependentAuthorityId().equals(studentRuleData.getSchool().getIndependentAuthorityId()))
226+
.map(school -> UUID.fromString(school.getSchoolId()))
227+
.toList();
228+
return sdcSchoolStudentRepository.findStudentInCurrentFiscalWithInSameAuthority(independentSchoolIDsWithSameAuthorityID, studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup, collection.getCollectionID(), collection.getSnapshotDate());
229+
}
230+
219231
public List<SdcSchoolCollectionStudentEntity> findStudentInCurrentFiscal(StudentRuleData studentRuleData, String noOfCollectionsForLookup) {
220232
setupMergedStudentIdValues(studentRuleData);
221233
var collection = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity();

api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/BaseStudentDataCollectionAPITest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,25 @@ public SdcSchoolCollectionEntity createMockSdcSchoolCollectionEntity(CollectionE
213213
return sdcEntity;
214214
}
215215

216+
public SdcSchoolCollectionEntity createMockSdcSchoolCollectionEntityIndependentSchool(CollectionEntity entity, UUID schoolID, UUID authID){
217+
SdcSchoolCollectionEntity sdcEntity = new SdcSchoolCollectionEntity();
218+
sdcEntity.setCollectionEntity(entity);
219+
SchoolTombstone school = createMockIndySchool(schoolID, authID);
220+
sdcEntity.setSchoolID(UUID.fromString(school.getSchoolId()));
221+
sdcEntity.setUploadDate(LocalDateTime.now());
222+
sdcEntity.setUploadFileName("abc.txt");
223+
sdcEntity.setUploadReportDate(null);
224+
sdcEntity.setSdcSchoolCollectionStatusCode("NEW");
225+
sdcEntity.setCreateUser("ABC");
226+
sdcEntity.setCreateDate(LocalDateTime.now());
227+
sdcEntity.setUpdateUser("ABC");
228+
sdcEntity.setUpdateDate(LocalDateTime.now());
229+
sdcEntity.setSdcSchoolCollectionHistoryEntities(new HashSet<>());
230+
sdcEntity.setSdcSchoolStudentEntities(new HashSet<>());
231+
232+
return sdcEntity;
233+
}
234+
216235
public SchoolTombstone createMockSchoolTombstone() {
217236
return SchoolTombstone.builder()
218237
.schoolId(UUID.randomUUID().toString())
@@ -482,6 +501,21 @@ public SchoolTombstone createMockSchool() {
482501
return schoolTombstone;
483502
}
484503

504+
public SchoolTombstone createMockIndySchool(UUID schoolID, UUID authID) {
505+
final SchoolTombstone schoolTombstone = new SchoolTombstone();
506+
schoolTombstone.setSchoolId(schoolID != null ? String.valueOf(schoolID) : UUID.randomUUID().toString());
507+
schoolTombstone.setIndependentAuthorityId(authID != null ? String.valueOf(authID) : UUID.randomUUID().toString());
508+
schoolTombstone.setDistrictId(null);
509+
schoolTombstone.setDisplayName("Alex's Independent school");
510+
schoolTombstone.setMincode("03636018");
511+
schoolTombstone.setSchoolNumber("36018");
512+
schoolTombstone.setOpenedDate("1964-09-01T00:00:00");
513+
schoolTombstone.setSchoolCategoryCode("INDEPEND");
514+
schoolTombstone.setSchoolReportingRequirementCode("REGULAR");
515+
schoolTombstone.setFacilityTypeCode("STANDARD");
516+
return schoolTombstone;
517+
}
518+
485519
public School createMockSchoolDetail() {
486520
final School school = new School();
487521
school.setSchoolId(UUID.randomUUID().toString());

0 commit comments

Comments
 (0)