diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtils.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtils.java index c4919ad14..06e19815e 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtils.java @@ -1,5 +1,8 @@ package ca.bc.gov.educ.studentdatacollection.api.calculator; +import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationFieldCode; +import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationIssueSeverityCode; +import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationIssueTypeCode; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.CollectionTypeCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.FacilityTypeCodes; import ca.bc.gov.educ.studentdatacollection.api.constants.v1.SchoolCategoryCodes; @@ -262,15 +265,12 @@ public boolean includedInCollectionThisSchoolYearForDistrictWithNonZeroFteWithSc public boolean reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(StudentRuleData studentRuleData) { validationRulesService.setupMergedStudentIdValues(studentRuleData); List historicalCollections = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalInAllDistrict(studentRuleData.getHistoricStudentIds(), "3"); + historicalCollections.add(studentRuleData.getSdcSchoolCollectionStudentEntity()); for (SdcSchoolCollectionStudentEntity studentEntity : historicalCollections) { - String schoolId = studentEntity.getSdcSchoolCollection().getSchoolID().toString(); - Optional school = restUtils.getSchoolBySchoolID(schoolId); + Optional school = restUtils.getSchoolBySchoolID(studentEntity.getSdcSchoolCollection().getSchoolID().toString()); if (school.isPresent() && FacilityTypeCodes.getOnlineFacilityTypeCodes().contains(school.get().getFacilityTypeCode())) { - BigDecimal fte = studentEntity.getFte(); - if (fte != null && fte.compareTo(BigDecimal.ZERO) > 0) { - return true; - } + return true; } } return false; @@ -278,9 +278,7 @@ public boolean reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(Stude public boolean reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(StudentRuleData studentRuleData) { validationRulesService.setupMergedStudentIdValues(studentRuleData); - String noOfCollectionsForLookup = "3"; - List entity = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalInOtherDistrictsNotInGrade8Or9WithNonZeroFte(UUID.fromString(studentRuleData.getSchool().getDistrictId()), studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup); - return !entity.isEmpty(); + return validationRulesService.studentExistsInCurrentFiscalInGrade8Or9(studentRuleData); } private LocalDate getFiscalDateFromCurrentSnapshot(LocalDate currentSnapshotDate){ diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculator.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculator.java index 4f69b171d..a4c08f05c 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculator.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculator.java @@ -59,8 +59,8 @@ public FteCalculationResult calculateFte(StudentRuleData studentData) { // v99 // The student was not reported in grade 8 or 9 with FTE>0 in any other districts in any previous collections this school year. - var reportedInAnyPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte = fteCalculatorUtils.reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(studentData); - if (reportedInAnyPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte) { + var studentExistsInCurrentFiscalInGrade8Or9 = fteCalculatorUtils.reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(studentData); + if (!studentExistsInCurrentFiscalInGrade8Or9) { log.debug("CollectionAndFacilityTypeCalculator: FTE Zero; Student was not reported in Grade 8 or 9 outside of district this school year. :: " + studentData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollectionStudentID()); fteCalculationResult.setFte(BigDecimal.ZERO); fteCalculationResult.setFteZeroReason(ZeroFteReasonCodes.NOT_REPORTED.getCode()); diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/rules/validationrules/impl/SummerStudentOnlineLearningRule.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/rules/validationrules/impl/SummerStudentOnlineLearningRule.java index d5dd6db12..fcd70fe24 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/rules/validationrules/impl/SummerStudentOnlineLearningRule.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/rules/validationrules/impl/SummerStudentOnlineLearningRule.java @@ -67,21 +67,19 @@ public List executeValidation(Student if (studentRuleData.getSdcSchoolCollectionStudentEntity().getAssignedStudentId() != null) { var historicalStudentCollection = validationRulesService.getStudentInHistoricalCollectionInAllDistrict(studentRuleData); + historicalStudentCollection.add(studentRuleData.getSdcSchoolCollectionStudentEntity()); for (SdcSchoolCollectionStudentEntity studentEntity : historicalStudentCollection) { Optional school = restUtils.getSchoolBySchoolID(studentEntity.getSdcSchoolCollection().getSchoolID().toString()); if (school.isPresent() && FacilityTypeCodes.getOnlineFacilityTypeCodes().contains(school.get().getFacilityTypeCode())) { - BigDecimal fte = studentEntity.getFte(); - - if (fte != null && fte.compareTo(BigDecimal.ZERO) > 0) { - isOnlineRegistered = true; - break; - } + isOnlineRegistered = true; + break; } } - if (!isOnlineRegistered) + if (!isOnlineRegistered) { errors.add(createValidationIssue(StudentValidationIssueSeverityCode.FUNDING_WARNING, StudentValidationFieldCode.ENROLLED_GRADE_CODE, StudentValidationIssueTypeCode.SUMMER_STUDENT_ONLINE_LEARNING_ERROR)); + } } return errors; } diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtilsTest.java index a7d39d083..a284b8ed3 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/FteCalculatorUtilsTest.java @@ -1631,64 +1631,6 @@ void testReportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear_NotOnlineSc assertFalse(result); } - @Test - void testReportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear_OnlineSchool_InDistrict_ReturnsTrue() { - // Given - StudentRuleData studentRuleData = new StudentRuleData(); - SchoolTombstone schoolTombstone = new SchoolTombstone(); - schoolTombstone.setFacilityTypeCode(FacilityTypeCodes.DISTONLINE.getCode()); - schoolTombstone.setDistrictId(UUID.randomUUID().toString()); - studentRuleData.setSchool(schoolTombstone); - SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); - CollectionEntity collection = createMockCollectionEntity(); - collection.setCollectionTypeCode(CollectionTypeCodes.FEBRUARY.getTypeCode()); - SdcSchoolCollectionEntity sdcSchoolCollectionEntity = createMockSdcSchoolCollectionEntity(collection, null); - student.setSdcSchoolCollection(sdcSchoolCollectionEntity); - student.setFte(BigDecimal.TEN); - student.setEnrolledGradeCode(SchoolGradeCodes.GRADE10.getCode()); - student.setAssignedStudentId(UUID.randomUUID()); - studentRuleData.setSdcSchoolCollectionStudentEntity(student); - studentRuleData.setHistoricStudentIds(List.of(UUID.randomUUID(), student.getAssignedStudentId())); - - when(sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalInAllDistrict(anyList(), any(String.class))).thenReturn(Collections.singletonList(student)); - when(restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(schoolTombstone)); - - // When - var result = fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentRuleData); - - // Then - assertTrue(result); - } - - @Test - void testReportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear_OnlineSchool_NotInDistrict_ReturnsTrue() { - // Given - StudentRuleData studentRuleData = new StudentRuleData(); - SchoolTombstone schoolTombstone = new SchoolTombstone(); - schoolTombstone.setFacilityTypeCode(FacilityTypeCodes.DISTONLINE.getCode()); - studentRuleData.setSchool(schoolTombstone); - SdcSchoolCollectionStudentEntity student = new SdcSchoolCollectionStudentEntity(); - CollectionEntity collection = createMockCollectionEntity(); - collection.setCollectionTypeCode(CollectionTypeCodes.FEBRUARY.getTypeCode()); - SdcSchoolCollectionEntity sdcSchoolCollectionEntity = createMockSdcSchoolCollectionEntity(collection, null); - student.setSdcSchoolCollection(sdcSchoolCollectionEntity); - student.setFte(BigDecimal.TEN); - student.setEnrolledGradeCode(SchoolGradeCodes.GRADE10.getCode()); - student.setCreateDate(LocalDateTime.now()); - student.setAssignedStudentId(UUID.randomUUID()); - studentRuleData.setSdcSchoolCollectionStudentEntity(student); - studentRuleData.setHistoricStudentIds(List.of(UUID.randomUUID(), student.getAssignedStudentId())); - - when(sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalInAllDistrict(anyList(), any(String.class))).thenReturn(Collections.singletonList(student)); - when(restUtils.getSchoolBySchoolID(anyString())).thenReturn(Optional.of(schoolTombstone)); - - // When - var result = fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentRuleData); - - // Then - assertTrue(result); - } - @Test void testReportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte_Grade8Or9_NonZeroFte_ReturnsFalse() { // Given @@ -1798,7 +1740,7 @@ void testReportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear_OnlineSchoo // Given StudentRuleData studentRuleData = new StudentRuleData(); SchoolTombstone schoolTombstone = new SchoolTombstone(); - schoolTombstone.setFacilityTypeCode(FacilityTypeCodes.DISTONLINE.getCode()); + schoolTombstone.setFacilityTypeCode(FacilityTypeCodes.SUMMER.getCode()); schoolTombstone.setDistrictId(UUID.randomUUID().toString()); studentRuleData.setSchool(schoolTombstone); @@ -1840,7 +1782,7 @@ void testReportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear_OnlineSchoo var result = fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentRuleData); // Then - assertFalse(result); + assertTrue(result); } public CollectionEntity createMockCollectionEntity(){ diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculatorTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculatorTest.java index 411af392c..b2fcd1412 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculatorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/calculator/impl/CollectionAndFacilityTypeCalculatorTest.java @@ -155,8 +155,8 @@ void testCalculateFte_JulyCollectionAndFacilityTypeDifferentThanSummerSchool_Not when(fteCalculatorUtils.includedInCollectionThisSchoolYearForDistrictWithNonZeroFteWithSchoolTypeNotOnline(studentData)).thenReturn(false); when(fteCalculatorUtils.includedInCollectionThisSchoolYearForDistrictWithNonZeroFteWithSchoolTypeOnlineInGradeKto9(studentData)).thenReturn(false); - when(fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentData)).thenReturn(false); - when(fteCalculatorUtils.reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(studentData)).thenReturn(true); + when(fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentData)).thenReturn(true); + when(fteCalculatorUtils.reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(studentData)).thenReturn(false); // When FteCalculationResult result = collectionAndFacilityTypeCalculator.calculateFte(studentData); @@ -198,7 +198,7 @@ void testCalculateFte_JulyCollectionAndFacilityTypeDifferentThanSummerSchool_Not when(fteCalculatorUtils.includedInCollectionThisSchoolYearForDistrictWithNonZeroFteWithSchoolTypeNotOnline(studentData)).thenReturn(false); when(fteCalculatorUtils.includedInCollectionThisSchoolYearForDistrictWithNonZeroFteWithSchoolTypeOnlineInGradeKto9(studentData)).thenReturn(false); when(fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentData)).thenReturn(false); - when(fteCalculatorUtils.reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(studentData)).thenReturn(false); + when(fteCalculatorUtils.reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(studentData)).thenReturn(true); // When FteCalculationResult result = collectionAndFacilityTypeCalculator.calculateFte(studentData); diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/SummerRulesProcessorTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/SummerRulesProcessorTest.java index 7defb1c61..b999f9478 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/SummerRulesProcessorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/rules/SummerRulesProcessorTest.java @@ -852,7 +852,7 @@ void testSummerStudentOnlineLearningRuleIsExecuted_WithNoErrors_WhenStudentInOnl val entity = this.createMockSchoolStudentEntity(sdcSchoolCollectionEntity); school.setSchoolCategoryCode(SchoolCategoryCodes.PUBLIC.getCode()); - school.setFacilityTypeCode(FacilityTypeCodes.DIST_LEARN.getCode()); + school.setFacilityTypeCode(FacilityTypeCodes.SUMMER.getCode()); PenMatchResult penMatchResult = getPenMatchResult(); penMatchResult.getMatchingRecords().get(0).setStudentID(String.valueOf(assignedStudentID)); when(this.restUtils.getPenMatchResult(any(), any(), anyString())).thenReturn(penMatchResult);