From 9a0c5fd195f238426b1c8f04c10979d0e0244f82 Mon Sep 17 00:00:00 2001 From: keeganbcgov Date: Tue, 17 Oct 2023 16:07:24 -0700 Subject: [PATCH] EDX-1904: ensured that finding a Primary EDX Activation Code will expect: -the DistrictID column to be null when selecting a Primary EDX Activation Code for a School; and -the SchoolID column to be null when selecting a Primary EDX Activation Code for a District. --- .../educ/api/edx/repository/EdxActivationCodeRepository.java | 4 ++-- .../api/edx/service/v1/CreateSchoolOrchestratorService.java | 4 +--- .../ca/bc/gov/educ/api/edx/service/v1/EdxUsersService.java | 4 ++-- .../api/edx/orchestrator/CreateSchoolOrchestratorTest.java | 3 +-- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/api/edx/repository/EdxActivationCodeRepository.java b/api/src/main/java/ca/bc/gov/educ/api/edx/repository/EdxActivationCodeRepository.java index c38023d3..f75ba4da 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/edx/repository/EdxActivationCodeRepository.java +++ b/api/src/main/java/ca/bc/gov/educ/api/edx/repository/EdxActivationCodeRepository.java @@ -17,9 +17,9 @@ public interface EdxActivationCodeRepository extends JpaRepository findEdxActivationCodeEntitiesByValidationCode(UUID userActivationValidationCode); - Optional findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(UUID schoolID); + Optional findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(UUID schoolID); - Optional findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrue(UUID districtID); + Optional findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrueAndSchoolIDIsNull(UUID districtID); List findEdxActivationCodeEntitiesByEdxUserId(UUID edxUserId); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/CreateSchoolOrchestratorService.java b/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/CreateSchoolOrchestratorService.java index c8c6045a..751b278f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/CreateSchoolOrchestratorService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/CreateSchoolOrchestratorService.java @@ -70,7 +70,6 @@ public void createPrimaryActivationCode(CreateSchoolSagaData sagaData) { EdxPrimaryActivationCode edxPrimaryActivationCode = new EdxPrimaryActivationCode(); School school = sagaData.getSchool(); edxPrimaryActivationCode.setSchoolID(UUID.fromString(school.getSchoolId())); - edxPrimaryActivationCode.setDistrictID(UUID.fromString(school.getDistrictId())); RequestUtil.setAuditColumnsForCreate(edxPrimaryActivationCode); service.generateOrRegeneratePrimaryEdxActivationCode(SCHOOL, school.getSchoolId(), edxPrimaryActivationCode); @@ -82,8 +81,7 @@ public void sendPrimaryActivationCodeNotification(CreateSchoolSagaData sagaData) School school = sagaData.getSchool(); UUID schoolId = UUID.fromString(school.getSchoolId()); - Optional edxActivationCodeEntity - = edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(schoolId); + Optional edxActivationCodeEntity = edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(schoolId); EmailNotification emailNotification = EmailNotification.builder() .fromEmail(emailProperties.getEdxSchoolUserActivationInviteEmailFrom()) diff --git a/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/EdxUsersService.java b/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/EdxUsersService.java index d95a616d..3b27df07 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/EdxUsersService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/edx/service/v1/EdxUsersService.java @@ -854,9 +854,9 @@ public EdxActivationCodeEntity generateOrRegeneratePrimaryEdxActivationCode(Inst private Optional findPrimaryEdxActivationCodeForInstitute(InstituteTypeCode instituteType, String contactIdentifier) { switch (instituteType) { case SCHOOL: - return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(UUID.fromString(contactIdentifier)); + return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(UUID.fromString(contactIdentifier)); case DISTRICT: - return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrue(UUID.fromString(contactIdentifier)); + return getEdxActivationCodeRepository().findEdxActivationCodeEntitiesByDistrictIDAndIsPrimaryTrueAndSchoolIDIsNull(UUID.fromString(contactIdentifier)); default: return Optional.empty(); } diff --git a/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/CreateSchoolOrchestratorTest.java b/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/CreateSchoolOrchestratorTest.java index 5d107207..9d3d0235 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/CreateSchoolOrchestratorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/api/edx/orchestrator/CreateSchoolOrchestratorTest.java @@ -143,8 +143,7 @@ void testCreatePrimaryCode_GivenAnInitialUserAndSchool_sagaShouldCreatePrimarySc JsonUtil.getJsonObjectFromString(CreateSchoolSagaData.class, newEvent.getEventPayload()); UUID schooId = UUID.fromString(newData.getSchool().getSchoolId()); - Optional codeOptional = - edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrue(schooId); + Optional codeOptional = edxActivationCodeRepository.findEdxActivationCodeEntitiesBySchoolIDAndIsPrimaryTrueAndDistrictIDIsNull(schooId); assertThat(codeOptional).isPresent(); assertThat(newData.getInitialEdxUser()).isPresent();