3170 language portion of language code is case insensitive (#3171)

* 3170 language portion of language code is case insensitive

* 3170 adding changelog

* 3170 house keeping

Co-authored-by: leif stawnyczy <leifstawnyczy@leifs-MacBook-Pro.local>
This commit is contained in:
TipzCM 2021-11-16 10:58:58 -05:00 committed by GitHub
parent 7e291bb469
commit 0c3fb775df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 7 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 3170
title: "Fixed language code validation so that it is case insensitive (eg, en-US, en-us, EN-US, EN-us should all work)"

View File

@ -212,7 +212,6 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
@Override
public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode, String theDisplayLanguage) {
Map<String, String> map;
switch (theSystem) {
case LANGUAGES_CODESYSTEM_URL:
@ -254,9 +253,7 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
}
private LookupCodeResult lookupLanguageCode(String theCode) {
Map<String, String> languagesMap = myLanguagesLanugageMap;
Map<String, String> regionsMap = myLanguagesRegionMap;
if (languagesMap == null || regionsMap == null) {
if (myLanguagesLanugageMap == null || myLanguagesRegionMap == null) {
initializeBcp47LanguageMap();
}
@ -266,8 +263,10 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
String region;
if (hasRegionAndCodeSegments) {
language = myLanguagesLanugageMap.get(theCode.substring(0, langRegionSeparatorIndex));
region = myLanguagesRegionMap.get(theCode.substring(langRegionSeparatorIndex + 1));
// we look for languages in lowercase only
// this will allow case insensitivity for language portion of code
language = myLanguagesLanugageMap.get(theCode.substring(0, langRegionSeparatorIndex).toLowerCase());
region = myLanguagesRegionMap.get(theCode.substring(langRegionSeparatorIndex + 1).toUpperCase());
if (language == null || region == null) {
//In case the user provides both a language and a region, they must both be valid for the lookup to succeed.
@ -278,7 +277,8 @@ public class CommonCodeSystemsTerminologyService implements IValidationSupport {
}
} else {
//In case user has only provided a language, we build the lookup from only that.
language = myLanguagesLanugageMap.get(theCode);
//NB: we only use the lowercase version of the language
language = myLanguagesLanugageMap.get(theCode.toLowerCase());
if (language == null) {
ourLog.warn("Couldn't find a valid bcp47 language from code: {}", theCode);
return buildNotFoundLookupCodeResult(theCode);

View File

@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ -54,6 +55,26 @@ public class CommonCodeSystemsTerminologyServiceTest {
assertNull(outcome);
}
@Test
public void lookupCode_languageOnlyLookup_isCaseInsensitive() {
IValidationSupport.LookupCodeResult outcomeUpper = mySvc.lookupCode(newSupport(), "urn:ietf:bcp:47", "SGN", "Sign Languages");
IValidationSupport.LookupCodeResult outcomeLower = mySvc.lookupCode(newSupport(), "urn:ietf:bcp:47", "sgn", "Sign Languages");
assertNotNull(outcomeUpper);
assertNotNull(outcomeLower);
assertTrue(outcomeLower.isFound());
assertTrue(outcomeUpper.isFound());
}
@Test
public void lookupCode_languageAndRegionLookup_isCaseInsensitive() {
IValidationSupport.LookupCodeResult outcomeUpper = mySvc.lookupCode(newSupport(), "urn:ietf:bcp:47", "EN-US", "English");
IValidationSupport.LookupCodeResult outcomeLower = mySvc.lookupCode(newSupport(), "urn:ietf:bcp:47", "en-us", "English");
assertNotNull(outcomeUpper);
assertNotNull(outcomeLower);
assertTrue(outcomeLower.isFound());
assertTrue(outcomeUpper.isFound());
}
@Test
public void testUcum_ValidateCode_Good() {
ValueSet vs = new ValueSet();