Add test for localizer and add some docs
This commit is contained in:
parent
65f597aeb1
commit
e05b0e5d8a
|
@ -24,9 +24,12 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,4 +98,17 @@ public class HapiLocalizer {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Set<String> getAllKeys(){
|
||||||
|
HashSet<String> retVal = new HashSet<String>();
|
||||||
|
for (ResourceBundle nextBundle : myBundle) {
|
||||||
|
Enumeration<String> keysEnum = nextBundle.getKeys();
|
||||||
|
while (keysEnum.hasMoreElements()) {
|
||||||
|
retVal.add(keysEnum.nextElement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,14 +47,14 @@ public class LoggingInterceptor implements IClientInterceptor {
|
||||||
private boolean myLogResponseSummary = true;
|
private boolean myLogResponseSummary = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor for client logging interceptor
|
||||||
*/
|
*/
|
||||||
public LoggingInterceptor() {
|
public LoggingInterceptor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor for client logging interceptor
|
||||||
*
|
*
|
||||||
* @param theVerbose
|
* @param theVerbose
|
||||||
* If set to true, all logging is enabled
|
* If set to true, all logging is enabled
|
||||||
|
|
|
@ -137,6 +137,13 @@ public class LoggingInterceptor extends InterceptorAdapter {
|
||||||
private Logger myLogger = ourLog;
|
private Logger myLogger = ourLog;
|
||||||
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
|
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for server logging interceptor
|
||||||
|
*/
|
||||||
|
public LoggingInterceptor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the log message format to be used when logging exceptions
|
* Get the log message format to be used when logging exceptions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package ca.uhn.fhir.i18n;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
|
import static org.hamcrest.Matchers.not;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class HapiLocalizerTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAllKeys() {
|
||||||
|
HapiLocalizer svc = new HapiLocalizer();
|
||||||
|
Set<String> allKeys = svc.getAllKeys();
|
||||||
|
assertThat(allKeys, not(empty()));
|
||||||
|
|
||||||
|
for (String next : allKeys) {
|
||||||
|
svc.getMessage(next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import ca.uhn.fhir.context.FhirVersionEnum;
|
||||||
import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
|
import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
|
||||||
import ca.uhn.fhir.rest.client.IGenericClient;
|
import ca.uhn.fhir.rest.client.IGenericClient;
|
||||||
import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor;
|
import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor;
|
||||||
|
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||||
|
|
||||||
public class UploadTerminologyCommand extends BaseCommand {
|
public class UploadTerminologyCommand extends BaseCommand {
|
||||||
|
|
||||||
|
@ -59,6 +60,10 @@ public class UploadTerminologyCommand extends BaseCommand {
|
||||||
opt.setRequired(false);
|
opt.setRequired(false);
|
||||||
options.addOption(opt);
|
options.addOption(opt);
|
||||||
|
|
||||||
|
opt = new Option("v", "verbose", false, "Verbose output");
|
||||||
|
opt.setRequired(false);
|
||||||
|
options.addOption(opt);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +90,6 @@ public class UploadTerminologyCommand extends BaseCommand {
|
||||||
|
|
||||||
String bearerToken = theCommandLine.getOptionValue("b");
|
String bearerToken = theCommandLine.getOptionValue("b");
|
||||||
|
|
||||||
|
|
||||||
IGenericClient client = super.newClient(ctx, targetServer);
|
IGenericClient client = super.newClient(ctx, targetServer);
|
||||||
IBaseParameters inputParameters;
|
IBaseParameters inputParameters;
|
||||||
if (ctx.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
|
if (ctx.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
|
||||||
|
@ -103,6 +107,10 @@ public class UploadTerminologyCommand extends BaseCommand {
|
||||||
client.registerInterceptor(new BearerTokenAuthInterceptor(bearerToken));
|
client.registerInterceptor(new BearerTokenAuthInterceptor(bearerToken));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (theCommandLine.hasOption('v')) {
|
||||||
|
client.registerInterceptor(new LoggingInterceptor(true));
|
||||||
|
}
|
||||||
|
|
||||||
ourLog.info("Beginning upload - This may take a while...");
|
ourLog.info("Beginning upload - This may take a while...");
|
||||||
IBaseParameters response = client
|
IBaseParameters response = client
|
||||||
.operation()
|
.operation()
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.apache.commons.csv.CSVParser;
|
||||||
import org.apache.commons.csv.CSVRecord;
|
import org.apache.commons.csv.CSVRecord;
|
||||||
import org.apache.commons.csv.QuoteMode;
|
import org.apache.commons.csv.QuoteMode;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.io.input.BOMInputStream;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -174,7 +175,7 @@ public class TerminologyLoaderSvc implements IHapiTerminologyLoaderSvc {
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
CSVParser parsed = null;
|
CSVParser parsed = null;
|
||||||
try {
|
try {
|
||||||
reader = new InputStreamReader(zis, Charsets.UTF_8);
|
reader = new InputStreamReader(new BOMInputStream(zis), Charsets.UTF_8);
|
||||||
CSVFormat format = CSVFormat.newFormat(theDelimiter).withFirstRecordAsHeader();
|
CSVFormat format = CSVFormat.newFormat(theDelimiter).withFirstRecordAsHeader();
|
||||||
if (theQuoteMode != null) {
|
if (theQuoteMode != null) {
|
||||||
format = format.withQuote('"').withQuoteMode(theQuoteMode);
|
format = format.withQuote('"').withQuoteMode(theQuoteMode);
|
||||||
|
|
Loading…
Reference in New Issue