Skip to content

Commit

Permalink
Merge pull request #1518 from bcgov/feature/v99
Browse files Browse the repository at this point in the history
Changes for V102
  • Loading branch information
alexmcdermid authored Jan 15, 2025
2 parents 6b10cbf + b7679db commit cf2bcab
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -262,25 +265,20 @@ public boolean includedInCollectionThisSchoolYearForDistrictWithNonZeroFteWithSc
public boolean reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(StudentRuleData studentRuleData) {
validationRulesService.setupMergedStudentIdValues(studentRuleData);
List<SdcSchoolCollectionStudentEntity> historicalCollections = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalInAllDistrict(studentRuleData.getHistoricStudentIds(), "3");
historicalCollections.add(studentRuleData.getSdcSchoolCollectionStudentEntity());

for (SdcSchoolCollectionStudentEntity studentEntity : historicalCollections) {
String schoolId = studentEntity.getSdcSchoolCollection().getSchoolID().toString();
Optional<SchoolTombstone> school = restUtils.getSchoolBySchoolID(schoolId);
Optional<SchoolTombstone> 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;
}

public boolean reportedInOtherDistrictsInPreviousCollectionThisSchoolYearInGrade8Or9WithNonZeroFte(StudentRuleData studentRuleData) {
validationRulesService.setupMergedStudentIdValues(studentRuleData);
String noOfCollectionsForLookup = "3";
List<SdcSchoolCollectionStudentEntity> entity = sdcSchoolCollectionStudentRepository.findStudentInCurrentFiscalInOtherDistrictsNotInGrade8Or9WithNonZeroFte(UUID.fromString(studentRuleData.getSchool().getDistrictId()), studentRuleData.getHistoricStudentIds(), noOfCollectionsForLookup);
return !entity.isEmpty();
return validationRulesService.studentExistsInCurrentFiscalInGrade8Or9(studentRuleData);
}

private LocalDate getFiscalDateFromCurrentSnapshot(LocalDate currentSnapshotDate){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,19 @@ public List<SdcSchoolCollectionStudentValidationIssue> executeValidation(Student

if (studentRuleData.getSdcSchoolCollectionStudentEntity().getAssignedStudentId() != null) {
var historicalStudentCollection = validationRulesService.getStudentInHistoricalCollectionInAllDistrict(studentRuleData);
historicalStudentCollection.add(studentRuleData.getSdcSchoolCollectionStudentEntity());

for (SdcSchoolCollectionStudentEntity studentEntity : historicalStudentCollection) {
Optional<SchoolTombstone> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1840,7 +1782,7 @@ void testReportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear_OnlineSchoo
var result = fteCalculatorUtils.reportedInOnlineSchoolInAnyPreviousCollectionThisSchoolYear(studentRuleData);

// Then
assertFalse(result);
assertTrue(result);
}

public CollectionEntity createMockCollectionEntity(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cf2bcab

Please sign in to comment.