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 58c4d244c..c4919ad14 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 @@ -190,13 +190,14 @@ public boolean noCoursesForSchoolAgedStudentInLastTwoYears(StudentRuleData stude var reportedByOnlineOrContEdSchool = StringUtils.equals(school.getFacilityTypeCode(), FacilityTypeCodes.DIST_LEARN.getCode()) || StringUtils.equals(school.getFacilityTypeCode(), FacilityTypeCodes.DISTONLINE.getCode()); var zeroCourses = TransformUtil.parseNumberOfCourses(student.getNumberOfCourses(), student.getSdcSchoolCollection().getSdcSchoolCollectionID()) == 0; boolean isSchoolAged = Boolean.TRUE.equals(student.getIsSchoolAged()); + LocalDate currentCollectionSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate(); if (isSchoolAged && isEightPlusGradeCode && reportedByOnlineOrContEdSchool && zeroCourses) { if(studentRuleData.getSdcSchoolCollectionStudentEntity().getAssignedStudentId() == null) { return true; } validationRulesService.setupMergedStudentIdValues(studentRuleData); - var lastTwoYearsOfCollections = sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(UUID.fromString(school.getSchoolId()), student.getSdcSchoolCollection().getSdcSchoolCollectionID()); + var lastTwoYearsOfCollections = sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(UUID.fromString(school.getSchoolId()), student.getSdcSchoolCollection().getSdcSchoolCollectionID(), currentCollectionSnapshotDate); return lastTwoYearsOfCollections.isEmpty() || sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(studentRuleData.getHistoricStudentIds(), lastTwoYearsOfCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList(), "0") == 0; } return false; @@ -213,13 +214,14 @@ public boolean noCoursesForAdultStudentInLastTwoYears(StudentRuleData studentRul var reportedByOnlineSchool = StringUtils.equals(school.getFacilityTypeCode(), FacilityTypeCodes.DIST_LEARN.getCode()) || StringUtils.equals(school.getFacilityTypeCode(), FacilityTypeCodes.DISTONLINE.getCode()); var zeroCourses = TransformUtil.parseNumberOfCourses(student.getNumberOfCourses(), student.getSdcSchoolCollection().getSdcSchoolCollectionID()) == 0; boolean isAdult = Boolean.TRUE.equals(student.getIsAdult()); + LocalDate currentCollectionSnapshotDate = studentRuleData.getSdcSchoolCollectionStudentEntity().getSdcSchoolCollection().getCollectionEntity().getSnapshotDate(); if (isAdult && isAllowedAdultGradeCode && reportedByOnlineSchool && zeroCourses) { if(studentRuleData.getSdcSchoolCollectionStudentEntity().getAssignedStudentId() == null) { return true; } validationRulesService.setupMergedStudentIdValues(studentRuleData); - var lastTwoYearsOfCollections = sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(UUID.fromString(school.getSchoolId()), student.getSdcSchoolCollection().getSdcSchoolCollectionID()); + var lastTwoYearsOfCollections = sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(UUID.fromString(school.getSchoolId()), student.getSdcSchoolCollection().getSdcSchoolCollectionID(), currentCollectionSnapshotDate); return lastTwoYearsOfCollections.isEmpty() || sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(studentRuleData.getHistoricStudentIds(), lastTwoYearsOfCollections.stream().map(SdcSchoolCollectionEntity::getSdcSchoolCollectionID).toList(), "0") == 0; } return false; diff --git a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionRepository.java b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionRepository.java index d246e7577..c4f699ac8 100644 --- a/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/studentdatacollection/api/repository/v1/SdcSchoolCollectionRepository.java @@ -39,9 +39,10 @@ public interface SdcSchoolCollectionRepository extends JpaRepository findAllCollectionsForSchoolInLastTwoYears(UUID schoolId, UUID sdcCollectionID); + List findAllCollectionsForSchoolInLastTwoYears(UUID schoolId, UUID sdcCollectionID, LocalDate snapshotDate); @Query(""" SELECT diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/BaseStudentDataCollectionAPITest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/BaseStudentDataCollectionAPITest.java index 061928e38..ba3904674 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/BaseStudentDataCollectionAPITest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/BaseStudentDataCollectionAPITest.java @@ -556,6 +556,7 @@ public UUID createMockHistoricalCollection(int yearsAgo, UUID schoolID, LocalDat LocalDateTime historicalOpenDate = currentCollectionOpenDate.minusYears(yearsAgo); CollectionEntity historicalCollectionEntity = createMockCollectionEntity(); historicalCollectionEntity.setOpenDate(historicalOpenDate); + historicalCollectionEntity.setSnapshotDate(LocalDate.from(historicalOpenDate.plusDays(20))); collectionRepository.save(historicalCollectionEntity); SdcSchoolCollectionEntity historicalSdcSchoolCollectionEntity = createMockSdcSchoolCollectionEntity(historicalCollectionEntity, schoolID); 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 9f15a2cfa..a7d39d083 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 @@ -976,11 +976,17 @@ void noCoursesForStudentInLastTwoYears_NotSchoolAged_ShouldReturnFalse() { schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(1)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1000,7 +1006,7 @@ void noCoursesForStudentInLastTwoYears_NotSchoolAged_ShouldReturnFalse() { studentData.setSdcSchoolCollectionStudentEntity(student); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(lastTwoYearsOfCollections); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(0L); @@ -1026,11 +1032,17 @@ void noCoursesForStudentInLastTwoYears_NoCoursesInLastTwoYears_ShouldReturnTrue( schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(1)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1050,7 +1062,7 @@ void noCoursesForStudentInLastTwoYears_NoCoursesInLastTwoYears_ShouldReturnTrue( student.setSdcSchoolCollection(schoolCollection1); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(lastTwoYearsOfCollections); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(0L); @@ -1076,11 +1088,17 @@ void noCoursesForStudentInLastTwoYears_OneCourseInLastTwoYears_ReturnsFalse() { schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(1)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1100,7 +1118,7 @@ void noCoursesForStudentInLastTwoYears_OneCourseInLastTwoYears_ReturnsFalse() { student.setSdcSchoolCollection(schoolCollection1); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(lastTwoYearsOfCollections); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(1L); @@ -1146,11 +1164,17 @@ void noCoursesForStudentInLastTwoYears_NoCollectionsInLastTwoYears_ReturnsTrue() schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(1)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1168,7 +1192,7 @@ void noCoursesForStudentInLastTwoYears_NoCollectionsInLastTwoYears_ReturnsTrue() student.setSdcSchoolCollection(schoolCollection1); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(List.of()); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(1L); @@ -1202,11 +1226,17 @@ void noCoursesForStudentInLastTwoYears_GivenDifferentFacilityTypesAndNumCourses_ schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(1)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1226,7 +1256,7 @@ void noCoursesForStudentInLastTwoYears_GivenDifferentFacilityTypesAndNumCourses_ student.setSdcSchoolCollection(schoolCollection1); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(lastTwoYearsOfCollections); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(0L); @@ -1271,11 +1301,17 @@ void noCoursesForStudentInLastTwoYears_GivenAllGrades_ShouldReturnTrue(String en schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1295,7 +1331,7 @@ void noCoursesForStudentInLastTwoYears_GivenAllGrades_ShouldReturnTrue(String en student.setSdcSchoolCollection(schoolCollection1); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(lastTwoYearsOfCollections); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(0L); @@ -1320,11 +1356,17 @@ void noCoursesForStudentInLastTwoYears_NumberOfCoursesNull_ReturnsTrue() { schoolTombstone.setFacilityTypeCode(facilityTypeCode); SdcSchoolCollectionEntity schoolCollection1 = new SdcSchoolCollectionEntity(); + var mockCollection1 = createMockCollectionEntity(); + mockCollection1.setSnapshotDate(LocalDate.now().minusYears(1)); + schoolCollection1.setCollectionEntity(mockCollection1); schoolCollection1.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection1.setSchoolID(schoolId); schoolCollection1.setCreateDate(studentCreateDate.minusYears(1)); // One year ago SdcSchoolCollectionEntity schoolCollection2 = new SdcSchoolCollectionEntity(); + var mockCollection2 = createMockCollectionEntity(); + mockCollection2.setSnapshotDate(LocalDate.now().minusYears(2)); + schoolCollection1.setCollectionEntity(mockCollection2); schoolCollection2.setSdcSchoolCollectionID(UUID.randomUUID()); schoolCollection2.setSchoolID(schoolId); schoolCollection2.setCreateDate(studentCreateDate.minusYears(2)); // Two years ago @@ -1343,7 +1385,7 @@ void noCoursesForStudentInLastTwoYears_NumberOfCoursesNull_ReturnsTrue() { student.setSdcSchoolCollection(schoolCollection1); studentData.setHistoricStudentIds(List.of(UUID.fromString(getStudentMergeResult().getStudentID()), student.getAssignedStudentId())); - when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any())) + when(sdcSchoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(any(UUID.class), any(), any())) .thenReturn(lastTwoYearsOfCollections); when(sdcSchoolCollectionStudentRepository.countByAssignedStudentIdInAndSdcSchoolCollection_SdcSchoolCollectionIDInAndNumberOfCoursesGreaterThan(anyList(), anyList(), any(String.class))) .thenReturn(0L); diff --git a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/helpers/HeadcountHelperTest.java b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/helpers/HeadcountHelperTest.java index cba892ba6..6317aa9f9 100644 --- a/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/helpers/HeadcountHelperTest.java +++ b/api/src/test/java/ca/bc/gov/educ/studentdatacollection/api/helpers/HeadcountHelperTest.java @@ -171,7 +171,7 @@ void testGetPreviousCollectionID_givenNoCollections_shouldReturnNull() { schoolCollectionEntity.setCreateDate(createDate); schoolCollectionEntity.setCollectionEntity(collectionEntity); - when(schoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(eq(schoolId), any())) + when(schoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(eq(schoolId), any(), any())) .thenReturn(new ArrayList<>()); // When @@ -195,7 +195,7 @@ void testGetPreviousCollectionIDJuly_givenNoCollections_shouldReturnNull() { schoolCollectionEntity.setCreateDate(createDate); schoolCollectionEntity.setCollectionEntity(collectionEntity); - when(schoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(eq(schoolId), any())) + when(schoolCollectionRepository.findAllCollectionsForSchoolInLastTwoYears(eq(schoolId), any(), any())) .thenReturn(new ArrayList<>()); // When