From 8b4f0228a88d79564a48ea761160c3eadbbaf109 Mon Sep 17 00:00:00 2001 From: Chris Ditcher Date: Tue, 29 Oct 2024 08:55:43 -0700 Subject: [PATCH] GRAD2-3017 (#358) * Added dependabot for actions * Added update to School along with SchoolDetail. Eliminated need for callback as SchoolDetail now extends School. --------- Co-authored-by: chris.ditcher --- .github/dependabot.yml | 4 +++ .../model/dto/institute/SchoolDetail.java | 22 +------------ .../model/entity/institute/SchoolEntity.java | 1 + .../institute/SchoolDetailTransformer.java | 31 +++++++++++++++++-- .../trax/service/institute/SchoolService.java | 3 +- .../intstituteSchoolServiceTestToo.java | 7 ++++- 6 files changed, 43 insertions(+), 25 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0d28b300..85708f49 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,3 +10,7 @@ updates: schedule: interval: "daily" target-branch: "grad-release" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolDetail.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolDetail.java index 9047504e..07452198 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolDetail.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/dto/institute/SchoolDetail.java @@ -1,6 +1,5 @@ package ca.bc.gov.educ.api.trax.model.dto.institute; -import ca.bc.gov.educ.api.trax.model.dto.BaseModel; import ca.bc.gov.educ.api.trax.model.dto.SchoolContact; import lombok.Data; import lombok.EqualsAndHashCode; @@ -11,27 +10,8 @@ @Data @EqualsAndHashCode(callSuper = true) @Component("SchoolDetail") -public class SchoolDetail extends BaseModel { +public class SchoolDetail extends School { - private String schoolId; - private String districtId; - private String mincode; - private String independentAuthorityId; - private String schoolNumber; - private String faxNumber; - private String phoneNumber; - private String email; - private String website; - private String displayName; - private String displayNameNoSpecialChars; - private String schoolReportingRequirementCode; - private String schoolOrganizationCode; - private String schoolCategoryCode; - private String facilityTypeCode; - private String openedDate; - private String closedDate; - private boolean canIssueTranscripts; - private boolean canIssueCertificates; List contacts; List addresses; List notes; diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java index 16ce9d58..d97849c4 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/entity/institute/SchoolEntity.java @@ -8,6 +8,7 @@ @Data @NoArgsConstructor @AllArgsConstructor +@Builder @RedisHash("School") public class SchoolEntity { diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolDetailTransformer.java b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolDetailTransformer.java index 071f1d98..b1dd1214 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolDetailTransformer.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/model/transformer/institute/SchoolDetailTransformer.java @@ -1,6 +1,5 @@ package ca.bc.gov.educ.api.trax.model.transformer.institute; -import ca.bc.gov.educ.api.trax.model.dto.institute.School; import ca.bc.gov.educ.api.trax.model.dto.institute.SchoolDetail; import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolDetailEntity; import ca.bc.gov.educ.api.trax.model.entity.institute.SchoolEntity; @@ -16,9 +15,37 @@ @Component("SchoolDetailTransformer") public class SchoolDetailTransformer { - @Autowired ModelMapper modelMapper; + @Autowired + public SchoolDetailTransformer(ModelMapper modelMapper) { + this.modelMapper = modelMapper; + } + + public SchoolEntity transformToSchoolEntity(final SchoolDetail schoolDetail) { + return SchoolEntity.builder() + .schoolId(schoolDetail.getSchoolId()) + .districtId(schoolDetail.getDistrictId()) + .mincode(schoolDetail.getMincode()) + .independentAuthorityId(schoolDetail.getIndependentAuthorityId()) + .schoolNumber(schoolDetail.getSchoolNumber()) + .faxNumber(schoolDetail.getFaxNumber()) + .phoneNumber(schoolDetail.getPhoneNumber()) + .email(schoolDetail.getEmail()) + .website(schoolDetail.getWebsite()) + .displayName(schoolDetail.getDisplayName()) + .displayNameNoSpecialChars(schoolDetail.getDisplayNameNoSpecialChars()) + .schoolReportingRequirementCode(schoolDetail.getSchoolReportingRequirementCode()) + .schoolOrganizationCode(schoolDetail.getSchoolOrganizationCode()) + .schoolCategoryCode(schoolDetail.getSchoolCategoryCode()) + .facilityTypeCode(schoolDetail.getFacilityTypeCode()) + .openedDate(schoolDetail.getOpenedDate()) + .closedDate(schoolDetail.getClosedDate()) + .canIssueTranscripts(schoolDetail.isCanIssueTranscripts()) + .canIssueCertificates(schoolDetail.isCanIssueCertificates()) + .build(); + } + public SchoolDetail transformToDTO (SchoolDetailEntity schoolDetailEntity) { return modelMapper.map(schoolDetailEntity, SchoolDetail.class); } diff --git a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java index 5d775f73..21cdad6f 100644 --- a/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java +++ b/api/src/main/java/ca/bc/gov/educ/api/trax/service/institute/SchoolService.java @@ -144,7 +144,7 @@ public void updateSchoolCache(String schoolId) throws ServiceException { SchoolDetail schoolDetail = this.restService.get(String.format(constants.getSchoolDetailsByIdFromInstituteApiUrl(), schoolId), SchoolDetail.class, webClient); log.debug("Retrieved school: {} from Institute API", schoolDetail.getSchoolId()); - schoolDetailRedisRepository.save(schoolDetailTransformer.transformToEntity(schoolDetail)); + updateSchoolCache(schoolDetail); } /** @@ -153,6 +153,7 @@ public void updateSchoolCache(String schoolId) throws ServiceException { */ public void updateSchoolCache(SchoolDetail schoolDetail) throws ServiceException { schoolDetailRedisRepository.save(schoolDetailTransformer.transformToEntity(schoolDetail)); + schoolRedisRepository.save(schoolDetailTransformer.transformToSchoolEntity(schoolDetail)); } /** diff --git a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/intstituteSchoolServiceTestToo.java b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/intstituteSchoolServiceTestToo.java index 56f437a5..88e0bf15 100644 --- a/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/intstituteSchoolServiceTestToo.java +++ b/api/src/test/java/ca/bc/gov/educ/api/trax/service/institute/intstituteSchoolServiceTestToo.java @@ -101,6 +101,8 @@ public class intstituteSchoolServiceTestToo { @MockBean private Subscriber subscriber; + @Autowired + private ca.bc.gov.educ.api.trax.model.transformer.SchoolTransformer schoolTransformer; @TestConfiguration static class TestConfigInstitute { @@ -120,14 +122,17 @@ public void updateSchoolCache_givenValidShcoolId_shouldUpdate() { SchoolDetail schoolDetail = TestUtils.createSchoolDetail(); SchoolDetailEntity schoolDetailEntity = schoolDetailTransformer.transformToEntity(schoolDetail); Optional schoolDetailEntityOptional = Optional.of(schoolDetailEntity); + Optional schoolEntityOptional = Optional.of(schoolDetailTransformer.transformToSchoolEntity(schoolDetail)); when(this.restServiceMock.get(String.format(constants.getSchoolDetailsByIdFromInstituteApiUrl(), schoolDetail.getSchoolId()), SchoolDetail.class, this.webClientMock)).thenReturn(schoolDetail); when(this.schoolDetailRedisRepository.findById(schoolDetail.getSchoolId())).thenReturn(schoolDetailEntityOptional); + when(this.schoolRedisRepository.findById(schoolDetail.getSchoolId())).thenReturn(schoolEntityOptional); doNothing().when(this.schoolService).updateSchoolCache(schoolDetail.getSchoolId()); this.schoolService.updateSchoolCache(schoolDetail.getSchoolId()); Optional response = this.schoolDetailRedisRepository.findById(schoolDetail.getSchoolId()); + Optional schoolResponse = this.schoolRedisRepository.findById(schoolDetail.getSchoolId()); if (response.isPresent()) { - Assert.assertEquals(response.get().getSchoolId(), schoolDetail.getSchoolId()); + Assert.assertEquals(response.get().getSchoolId(), schoolResponse.get().getSchoolId()); } else { Assert.fail(); }