Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading