added i18N handling to all BaseWorkerContexts

This commit is contained in:
patrick-werner 2020-03-09 17:25:08 +01:00
parent 41e9b0e9fa
commit 7443eb3f59
10 changed files with 212 additions and 18 deletions

View File

@ -23,11 +23,15 @@ package org.hl7.fhir.dstu2.utils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import org.hl7.fhir.dstu2.model.BooleanType;
@ -73,6 +77,8 @@ public abstract class BaseWorkerContext implements IWorkerContext {
// private ValueSetExpansionCache expansionCache; //
protected FHIRToolingClient txServer;
private Locale locale;
private ResourceBundle i18Nmessages;
@Override
public ValueSet fetchCodeSystem(String system) {
@ -402,4 +408,37 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+typeName);
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
}
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale );
}
}

View File

@ -23,6 +23,7 @@ package org.hl7.fhir.dstu2.utils;
import java.util.List;
import java.util.Locale;
import org.hl7.fhir.dstu2.formats.IParser;
import org.hl7.fhir.dstu2.formats.ParserType;
import org.hl7.fhir.dstu2.model.CodeableConcept;
@ -209,6 +210,14 @@ public interface IWorkerContext {
*/
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc);
Locale getLocale();
void setLocale(Locale locale);
String formatMessage(String theMessage, Object... theMessageArguments);
void setValidationMessageLanguage(Locale locale);
public class ValidationResult {
private ConceptDefinitionComponent definition;
private IssueSeverity severity;

View File

@ -23,11 +23,15 @@ package org.hl7.fhir.dstu2016may.utils;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import org.hl7.fhir.dstu2016may.model.BooleanType;
@ -75,6 +79,8 @@ public abstract class BaseWorkerContext implements IWorkerContext {
protected FHIRToolingClient txServer;
private Bundle bndCodeSystems;
private Locale locale;
private ResourceBundle i18Nmessages;
@Override
public CodeSystem fetchCodeSystem(String system) {
@ -441,5 +447,37 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+typeName);
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
}
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale );
}
}

View File

@ -22,6 +22,7 @@ package org.hl7.fhir.dstu2016may.utils;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.hl7.fhir.dstu2016may.formats.IParser;
@ -205,6 +206,14 @@ public interface IWorkerContext {
*/
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc);
Locale getLocale();
void setLocale(Locale locale);
String formatMessage(String theMessage, Object... theMessageArguments);
void setValidationMessageLanguage(Locale locale);
public class ValidationResult {
private ConceptDefinitionComponent definition;
private IssueSeverity severity;

View File

@ -27,11 +27,15 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import ca.uhn.fhir.rest.api.Constants;
@ -122,6 +126,8 @@ public abstract class BaseWorkerContext implements IWorkerContext {
private int expandCodesLimit = 1000;
protected ILoggingService logger;
protected ExpansionProfile expProfile;
private Locale locale;
private ResourceBundle i18Nmessages;
public Map<String, CodeSystem> getCodeSystems() {
return codeSystems;
@ -991,5 +997,37 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/"+typeName);
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
}
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale );
}
}

View File

@ -22,6 +22,7 @@ package org.hl7.fhir.dstu3.context;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.hl7.fhir.dstu3.formats.IParser;
@ -237,6 +238,14 @@ public interface IWorkerContext {
*/
public ValueSetExpansionComponent expandVS(ConceptSetComponent inc, boolean heiarchical) throws TerminologyServiceException;
Locale getLocale();
void setLocale(Locale locale);
String formatMessage(String theMessage, Object... theMessageArguments);
void setValidationMessageLanguage(Locale locale);
public class ValidationResult {
private ConceptDefinitionComponent definition;
private IssueSeverity severity;

View File

@ -21,6 +21,10 @@ package org.hl7.fhir.r4.context;
*/
import com.google.gson.JsonObject;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Objects;
import java.util.ResourceBundle;
import org.apache.commons.lang3.StringUtils;
import org.fhir.ucum.UcumService;
import org.hl7.fhir.exceptions.DefinitionException;
@ -99,6 +103,8 @@ public abstract class BaseWorkerContext implements IWorkerContext {
protected TerminologyCache txCache;
private boolean tlogging = true;
private Locale locale;
private ResourceBundle i18Nmessages;
public BaseWorkerContext() throws FileNotFoundException, IOException, FHIRException {
super();
@ -1174,5 +1180,37 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return null;
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
if (theMessageArguments != null && theMessageArguments.length > 0) {
message = MessageFormat.format(i18Nmessages.getString(theMessage), theMessageArguments);
} else if (i18Nmessages.containsKey(theMessage)) {
message = i18Nmessages.getString(theMessage);
} else {
message = theMessage;
}
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale );
}
}

View File

@ -22,6 +22,7 @@ package org.hl7.fhir.r4.context;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -284,6 +285,14 @@ public interface IWorkerContext {
*/
public ValueSetExpansionOutcome expandVS(ConceptSetComponent inc, boolean heirarchical) throws TerminologyServiceException;
Locale getLocale();
void setLocale(Locale locale);
String formatMessage(String theMessage, Object... theMessageArguments);
void setValidationMessageLanguage(Locale locale);
public class ValidationResult {
private ConceptDefinitionComponent definition;
private IssueSeverity severity;

View File

@ -425,19 +425,6 @@ public abstract class BaseWorkerContext implements IWorkerContext {
this.expandCodesLimit = expandCodesLimit;
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
}
@Override
public ValueSetExpansionOutcome expandVS(ElementDefinitionBindingComponent binding, boolean cacheOk, boolean heirarchical) throws FHIRException {
ValueSet vs = null;
@ -1293,6 +1280,21 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return binaries;
}
@Override
public Locale getLocale() {
if (Objects.nonNull(locale)){
return locale;
} else {
return Locale.US;
}
}
@Override
public void setLocale(Locale locale) {
this.locale = locale;
setValidationMessageLanguage(getLocale());
}
@Override
public String formatMessage(String theMessage, Object... theMessageArguments) {
String message;
@ -1306,6 +1308,7 @@ public abstract class BaseWorkerContext implements IWorkerContext {
return message;
}
@Override
public void setValidationMessageLanguage(Locale locale) {
i18Nmessages = ResourceBundle.getBundle("Messages", locale );
}

View File

@ -334,6 +334,8 @@ public interface IWorkerContext {
String formatMessage(String theMessage, Object... theMessageArguments);
void setValidationMessageLanguage(Locale locale);
class ValidationResult {
private ConceptDefinitionComponent definition;
private IssueSeverity severity;