Skip to content

Commit b0555a1

Browse files
Merge pull request #1076 from bcgov/feature/edx-2782
Close collection fix
2 parents 1616275 + b96dd29 commit b0555a1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ca.bc.gov.educ.studentdatacollection.api.struct.v1.headcounts.*;
77
import org.springframework.data.jpa.repository.JpaRepository;
88
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
9+
import org.springframework.data.jpa.repository.Modifying;
910
import org.springframework.data.jpa.repository.Query;
1011
import org.springframework.data.repository.query.Param;
1112
import org.springframework.stereotype.Repository;
@@ -869,6 +870,15 @@ WHERE stud.assignedStudentId IN (:matchedAssignedIDs)
869870

870871
List<SdcSchoolCollectionStudentEntity> findAllBySdcSchoolCollection_CollectionEntity_CollectionID(UUID collectionID);
871872

873+
@Modifying
874+
@Query(value = """
875+
UPDATE SDC_SCHOOL_COLLECTION_STUDENT
876+
SET sdc_school_collection_student_status_code = 'DEMOG_UPD', update_user = 'STUDENT_DATA_COLLECTION_API', update_date = CURRENT_TIMESTAMP
877+
WHERE sdc_school_collection_id IN
878+
(SELECT sdc_school_collection_id FROM SDC_SCHOOL_COLLECTION WHERE collection_id = :collectionID)
879+
""", nativeQuery = true)
880+
void updateAllSdcSchoolCollectionStudentStatus(UUID collectionID);
881+
872882
@Query(value="""
873883
SELECT stud FROM SdcSchoolCollectionStudentEntity stud WHERE stud.sdcSchoolCollectionStudentID
874884
NOT IN (SELECT saga.sdcSchoolCollectionStudentID FROM SdcSagaEntity saga WHERE saga.status != 'COMPLETED'

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,8 @@ public void closeCurrentCollAndOpenNewCollection(final CollectionSagaData collec
122122
collectionToOpen.setUpdateDate(LocalDateTime.now());
123123
collectionTypeCodeRepository.save(collectionToOpen);
124124

125+
sdcSchoolCollectionStudentRepository.updateAllSdcSchoolCollectionStudentStatus(UUID.fromString(collectionSagaData.getExistingCollectionID()));
125126
log.info("New collection for {} is now open", collectionToOpen.getCollectionTypeCode());
126-
127-
List<SdcSchoolCollectionStudentEntity> studentsInCollections= sdcSchoolCollectionStudentRepository.findAllBySdcSchoolCollection_CollectionEntity_CollectionID(UUID.fromString(collectionSagaData.getExistingCollectionID()));
128-
log.debug("Found {} studentsInCollections for downstream update", studentsInCollections.size());
129-
studentsInCollections.forEach(student -> {
130-
student.setSdcSchoolCollectionStudentStatusCode(SdcSchoolStudentStatus.DEMOG_UPD.getCode());
131-
student.setUpdateUser(ApplicationProperties.STUDENT_DATA_COLLECTION_API);
132-
student.setUpdateDate(LocalDateTime.now());
133-
});
134-
sdcSchoolCollectionStudentRepository.saveAll(studentsInCollections);
135127
}
136128
}
137129

0 commit comments

Comments
 (0)