Skip to content

Commit

Permalink
[ES-1899] converted two-letter language codes to their corresponding …
Browse files Browse the repository at this point in the history
…ISO 639-2/T language codes (mosip#74)

Signed-off-by: pvsaidurga <[email protected]>
  • Loading branch information
pvsaidurga committed Jan 15, 2025
1 parent b78e79b commit 7c6b45e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;


@ConditionalOnProperty(value = "mosip.esignet.integration.authenticator", havingValue = "MockAuthenticationService")
Expand Down Expand Up @@ -85,7 +86,7 @@ public KycExchangeResult doKycExchange(String relyingPartyId, String clientId, K
kycExchangeRequestDto.setKycToken(kycExchangeDto.getKycToken());
kycExchangeRequestDto.setIndividualId(kycExchangeDto.getIndividualId());
kycExchangeRequestDto.setAcceptedClaims(kycExchangeDto.getAcceptedClaims());
kycExchangeRequestDto.setClaimLocales(Arrays.asList(kycExchangeDto.getClaimsLocales()));
kycExchangeRequestDto.setClaimLocales(convertLangCodesToISO3LanguageCodes(kycExchangeDto.getClaimsLocales()));

String requestBody = objectMapper.writeValueAsString(kycExchangeRequestDto);
RequestEntity requestEntity = RequestEntity
Expand Down Expand Up @@ -195,4 +196,19 @@ private VerifiedKycExchangeRequestDto buildVerifiedKycExchangeRequestDto(Verifie
verifiedKycExchangeRequestDto.setAcceptedClaimDetail(verifiedKycExchangeDto.getAcceptedClaimDetails());
return verifiedKycExchangeRequestDto;
}

//Converts an array of two-letter language codes to their corresponding ISO 639-2/T language codes.
protected List<String> convertLangCodesToISO3LanguageCodes(String[] langCodes) {
if(langCodes == null || langCodes.length == 0)
return List.of();
return Arrays.stream(langCodes)
.map(langCode -> {
try {
return org.springframework.util.StringUtils.isEmpty(langCode) ? null : new Locale(langCode).getISO3Language();
} catch (MissingResourceException ex) {}
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,22 @@ public void doVerifiedKycExchange_throwsKycExchangeException_thenFail() {
);
Assert.assertEquals("mock-ida-005", exception.getErrorCode());
}

@Test
public void convertLangCodesToISO3LanguageCodes_withInvalidInput_thenReturnEmpty() {
Assert.assertTrue(mockAuthenticationService.convertLangCodesToISO3LanguageCodes(null).isEmpty());
Assert.assertTrue(mockAuthenticationService.convertLangCodesToISO3LanguageCodes(new String[]{}).isEmpty());
Assert.assertTrue(mockAuthenticationService.convertLangCodesToISO3LanguageCodes(new String[]{"", ""}).isEmpty());
Assert.assertTrue(mockAuthenticationService.convertLangCodesToISO3LanguageCodes(new String[]{"e1"}).isEmpty());
}

@Test
public void convertLangCodesToISO3LanguageCodes_withValidInput_thenPass() {
List<String> langCodes = mockAuthenticationService.convertLangCodesToISO3LanguageCodes(new String[]{"en", "km"});
Assert.assertFalse(langCodes.isEmpty());
Assert.assertEquals(langCodes.get(0), "eng");
Assert.assertEquals(langCodes.get(1), "khm");
}
}


0 comments on commit 7c6b45e

Please sign in to comment.