Fix null exception for debug messages in BaseWorkerContext

This commit is contained in:
dotasek 2022-03-23 14:11:26 -04:00
parent 7c6e7b278a
commit 25d9439fa9
2 changed files with 18 additions and 15 deletions

View File

@ -53,9 +53,7 @@ import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.NoTerminologyServiceException;
import org.hl7.fhir.exceptions.TerminologyServiceException;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.BaseWorkerContext.ResourceProxy;
import org.hl7.fhir.r5.context.CanonicalResourceManager.CanonicalResourceProxy;
import org.hl7.fhir.r5.context.IWorkerContext.PackageVersion;
import org.hl7.fhir.r5.context.IWorkerContext.ILoggingService.LogCategory;
import org.hl7.fhir.r5.context.TerminologyCache.CacheToken;
import org.hl7.fhir.r5.model.BooleanType;
@ -128,8 +126,6 @@ import org.hl7.fhir.utilities.validation.ValidationOptions.ValueSetMode;
import com.google.gson.JsonObject;
import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum;
public abstract class BaseWorkerContext extends I18nBase implements IWorkerContext{
public class ResourceProxy {
@ -388,7 +384,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
map.put(r.getId(), new ResourceProxy(r));
} else {
logger.logDebugMessage(LogCategory.PROGRESS,"Ignore "+r.fhirType()+"/"+r.getId()+" from package "+packageInfo.toString());
logDebugMessage(LogCategory.PROGRESS,"Ignore "+r.fhirType()+"/"+r.getId()+" from package "+packageInfo.toString());
}
if (r instanceof CodeSystem || r instanceof NamingSystem) {
@ -399,7 +395,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
CanonicalResource m = (CanonicalResource) r;
String url = m.getUrl();
if (!allowLoadingDuplicates && hasResource(r.getClass(), url)) {
// spcial workaround for known problems with existing packages
// special workaround for known problems with existing packages
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}
@ -633,8 +629,15 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
}
protected void logDebugMessage(LogCategory category, String message) {
if (logger != null) {
logger.logDebugMessage(category, message);
} else {
System.out.println(" -"+ category.name().toLowerCase() + ": " +message);
}
}
protected void tlog(String msg) {
protected void txLog(String msg) {
if (tlogging ) {
if (logger != null) {
logger.logDebugMessage(LogCategory.TX, msg);
@ -692,7 +695,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit ));
params.put("_incomplete", "true");
tlog("$expand on "+txCache.summary(vs));
txLog("$expand on "+txCache.summary(vs));
try {
ValueSet result = txClient.expandValueset(vs, p, params);
res = new ValueSetExpansionOutcome(result).setTxLink(txLog.getLastId());
@ -786,7 +789,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
Map<String, String> params = new HashMap<String, String>();
params.put("_limit", Integer.toString(expandCodesLimit ));
params.put("_incomplete", "true");
tlog("$expand on "+txCache.summary(vs));
txLog("$expand on "+txCache.summary(vs));
try {
ValueSet result = txClient.expandValueset(vs, p, params);
if (!result.hasUrl()) {
@ -895,7 +898,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
}
if (batch.getEntry().size() > 0) {
tlog("$batch validate for "+batch.getEntry().size()+" codes on systems "+systems.toString());
txLog("$batch validate for "+batch.getEntry().size()+" codes on systems "+systems.toString());
if (txClient == null) {
throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
}
@ -983,9 +986,9 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
String csumm = txCache != null ? txCache.summary(code) : null;
if (txCache != null) {
tlog("$validate "+csumm+" for "+ txCache.summary(vs));
txLog("$validate "+csumm+" for "+ txCache.summary(vs));
} else {
tlog("$validate "+csumm+" before cache exists");
txLog("$validate "+csumm+" before cache exists");
}
try {
Parameters pIn = constructParameters(options, code);
@ -1107,7 +1110,7 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
if (noTerminologyServer) {
return new ValidationResult(IssueSeverity.ERROR, "Error validating code: running without terminology services", TerminologyServiceErrorClass.NOSERVICE);
}
tlog("$validate "+txCache.summary(code)+" for "+ txCache.summary(vs));
txLog("$validate "+txCache.summary(code)+" for "+ txCache.summary(vs));
try {
Parameters pIn = constructParameters(options, code);
res = validateOnServer(vs, pIn, options);

View File

@ -314,7 +314,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
public String connectToTSServer(TerminologyClient client, String log) {
try {
tlog("Connect to "+client.getAddress());
txLog("Connect to "+client.getAddress());
txClient = client;
if (log != null && log.endsWith(".txt")) {
txLog = new TextClientLogger(log);
@ -359,7 +359,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon
Bundle bnd = (Bundle) f;
for (BundleEntryComponent e : bnd.getEntry()) {
if (e.getFullUrl() == null) {
logger.logDebugMessage(LogCategory.CONTEXT, "unidentified resource in " + name+" (no fullUrl)");
logDebugMessage(LogCategory.CONTEXT, "unidentified resource in " + name+" (no fullUrl)");
}
if (filter == null || filter.isOkToLoad(e.getResource())) {
String path = loader != null ? loader.getResourcePath(e.getResource()) : null;