Skip to content

Commit

Permalink
GRAD2-3191 - Update institute cache to use DisplayName without specia…
Browse files Browse the repository at this point in the history
…l characters (#391)

* GRAD2-3191 - Update institute cache to use DisplayName without special characters

* GRAD2-3191 - Adding test coverage

* GRAD2-3191 - Adding test coverage
  • Loading branch information
kamal-mohammed authored Dec 23, 2024
1 parent 7220a72 commit 0c5e2ec
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class SchoolDetailEntity {
private String displayNameNoSpecialChars;
private String schoolReportingRequirementCode;
private String schoolOrganizationCode;
@Indexed
private String schoolCategoryCode;
private String facilityTypeCode;
private String openedDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SchoolEntity {
private String displayNameNoSpecialChars;
private String schoolReportingRequirementCode;
private String schoolOrganizationCode;
@Indexed
private String schoolCategoryCode;
private String facilityTypeCode;
private String openedDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public List<School> getSchoolsFromInstituteApi() {
log.debug("****Before Calling Institute API");
List<SchoolEntity> response = this.restService.get(constants.getAllSchoolsFromInstituteApiUrl(),
List.class, webClient);
return schoolTransformer.transformToDTO(response);
List<School> schools = schoolTransformer.transformToDTO(response);

//Remove this loop and reload cache when grad supports Special Characters
for (School school : schools) {
if (school.getDisplayNameNoSpecialChars() != null && !school.getDisplayNameNoSpecialChars().isEmpty())
school.setDisplayName(school.getDisplayNameNoSpecialChars());
}

return schools;
} catch (WebClientResponseException e) {
log.warn(String.format("Error getting Common School List: %s", e.getMessage()));
} catch (Exception e) {
Expand Down Expand Up @@ -91,6 +99,9 @@ public SchoolDetail getSchoolDetailByIdFromInstituteApi(String schoolId) {
log.debug("****Before Calling Institute API");
SchoolDetailEntity sde = this.restService.get(String.format(constants.getSchoolDetailsByIdFromInstituteApiUrl(), schoolId),
SchoolDetailEntity.class, webClient);
//Remove this IF block and reload cache when grad supports Special Characters
if (sde.getDisplayNameNoSpecialChars() != null && !sde.getDisplayNameNoSpecialChars().isEmpty())
sde.setDisplayName(sde.getDisplayNameNoSpecialChars());
return schoolDetailTransformer.transformToDTO(sde);
} catch (WebClientResponseException e) {
log.warn("Error getting School Details");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,35 @@ public ClientRegistration findByRegistrationId(String registrationId) {

@Test
void whenGetSchoolsFromInstituteApi_returnsListOfSchools() {
List<SchoolEntity> schools = new ArrayList<>();
SchoolEntity school = new SchoolEntity();
List<SchoolEntity> schoolEntities = new ArrayList<>();
SchoolEntity schoolEntity = new SchoolEntity();

schoolEntity.setSchoolId("ID");
schoolEntity.setDistrictId("DistID");
schoolEntity.setSchoolNumber("12345");
schoolEntity.setSchoolCategoryCode("SCC");
schoolEntity.setEmail("[email protected]");
schoolEntity.setDisplayName("Tk̓emlúps te Secwépemc");
schoolEntity.setDisplayNameNoSpecialChars("Tkkemlups te Secwepemc");
schoolEntities.add(schoolEntity);

List<School> schools = new ArrayList<>();
School school = new School();
school.setSchoolId("ID");
school.setDistrictId("DistID");
school.setSchoolNumber("12345");
school.setSchoolCategoryCode("SCC");
school.setEmail("[email protected]");

school.setDisplayName("Tk̓emlúps te Secwépemc");
school.setDisplayNameNoSpecialChars("Tkkemlups te Secwepemc");
schools.add(school);

when(this.restUtils.getTokenResponseObject(anyString(), anyString()))
.thenReturn(responseObjectMock);
when(webClientMock.get())
.thenReturn(requestHeadersUriSpecMock);
when(this.schoolTransformer.transformToDTO(schoolEntities)).thenReturn(schools);
when(this.restServiceMock.get(constants.getAllSchoolsFromInstituteApiUrl(),
List.class, instWebClient)).thenReturn(schoolEntities);

schoolService.getSchoolsFromInstituteApi();
List<School> result = schoolService.getSchoolsFromInstituteApi();
assertEquals(schools, result);
}

@Test
Expand Down Expand Up @@ -310,11 +322,11 @@ void whenGetSchoolDetailsFromInstituteApi_returnsListOfSchoolDetails() {
schoolDetailEntity1.setSchoolCategoryCode("SCC");
schoolDetailEntity1.setEmail("[email protected]");
SchoolDetailEntity schoolDetailEntity2 = new SchoolDetailEntity();
schoolDetailEntity1.setSchoolId("2");
schoolDetailEntity1.setDistrictId("DistID");
schoolDetailEntity1.setSchoolNumber("12345");
schoolDetailEntity1.setSchoolCategoryCode("SCC");
schoolDetailEntity1.setEmail("[email protected]");
schoolDetailEntity2.setSchoolId("2");
schoolDetailEntity2.setDistrictId("DistID");
schoolDetailEntity2.setSchoolNumber("12345");
schoolDetailEntity2.setSchoolCategoryCode("SCC");
schoolDetailEntity2.setEmail("[email protected]");

when(this.schoolService.getSchoolsFromRedisCache()).thenReturn(schools);
when(this.schoolDetailTransformer.transformToDTO(schoolDetailEntity1)).thenReturn(schoolDetail1);
Expand All @@ -338,13 +350,17 @@ void whenGetSchoolDetailByIdFromInstituteApi_ReturnSchoolDetail() {
schoolDetail.setSchoolNumber("12345");
schoolDetail.setSchoolCategoryCode("SCC");
schoolDetail.setEmail("[email protected]");
schoolDetail.setDisplayName("Stitó:s Lá:lém Totí:lt Elementary");
schoolDetail.setDisplayNameNoSpecialChars("Stitos Lalem Totilt Elementary");

SchoolDetailEntity schoolDetailEntity = new SchoolDetailEntity();
schoolDetailEntity.setSchoolId("1");
schoolDetailEntity.setDistrictId("DistID");
schoolDetailEntity.setSchoolNumber("12345");
schoolDetailEntity.setSchoolCategoryCode("SCC");
schoolDetailEntity.setEmail("[email protected]");
schoolDetailEntity.setDisplayName("Stitó:s Lá:lém Totí:lt Elementary");
schoolDetailEntity.setDisplayNameNoSpecialChars("Stitos Lalem Totilt Elementary");

when(this.schoolDetailTransformer.transformToDTO(schoolDetailEntity)).thenReturn(schoolDetail);
when(this.restServiceMock.get(String.format(constants.getSchoolDetailsByIdFromInstituteApiUrl(), "1"),
Expand Down

0 comments on commit 0c5e2ec

Please sign in to comment.