Don't access getBinaries directly in XVerExtensionManager (#864)

* Don't access getBinaries directly in XVerExtensionManager

* Remove getBinaries() add getBinaryKeysAsSet()

Co-authored-by: dotasek <david.otasek@smilecdr.com>
This commit is contained in:
dotasek 2022-07-22 11:13:42 -04:00 committed by GitHub
parent b855463aa7
commit 6b7ac47076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 17 deletions

View File

@ -115,14 +115,14 @@ public class ComparisonRenderer implements IEvaluationContext {
}
private void dumpBinaries() throws IOException {
if (contextLeft != null && contextLeft.getBinaries() != null) {
for (String k : contextLeft.getBinaries().keySet()) {
TextFile.bytesToFile(contextLeft.getBinaries().get(k), Utilities.path(folder, k));
if (contextLeft != null && contextLeft.getBinaryKeysAsSet() != null) {
for (String k : contextLeft.getBinaryKeysAsSet()) {
TextFile.bytesToFile(contextLeft.getBinaryForKey(k), Utilities.path(folder, k));
}
}
if (contextRight != null && contextRight.getBinaries() != null) {
for (String k : contextRight.getBinaries().keySet()) {
TextFile.bytesToFile(contextRight.getBinaries().get(k), Utilities.path(folder, k));
if (contextRight != null && contextRight.getBinaryKeysAsSet() != null) {
for (String k : contextRight.getBinaryKeysAsSet()) {
TextFile.bytesToFile(contextRight.getBinaryForKey(k), Utilities.path(folder, k));
}
}
}

View File

@ -2161,10 +2161,18 @@ public abstract class BaseWorkerContext extends I18nBase implements IWorkerConte
}
@Override
public Map<String, byte[]> getBinaries() {
return binaries;
public Set<String> getBinaryKeysAsSet() { return binaries.keySet(); }
@Override
public boolean hasBinaryKey(String binaryKey) {
return binaries.containsKey(binaryKey);
}
@Override
public byte[] getBinaryForKey(String binaryKey) {
return binaries.get(binaryKey);
}
public void finishLoading() {
for (StructureDefinition sd : listStructures()) {
try {

View File

@ -833,7 +833,28 @@ public interface IWorkerContext {
public void setUcumService(UcumService ucumService);
public String getLinkForUrl(String corePath, String s);
public Map<String, byte[]> getBinaries();
/**
* Returns a set of keys that can be used to get binaries from this context.
*
* @return a set of binaries or null
*/
public Set<String> getBinaryKeysAsSet();
/**
* Returns true if this worker context contains a binary for this key.
*
* @param binaryKey
* @return true if binary is available for this key
*/
public boolean hasBinaryKey(String binaryKey);
/**
* Returns the binary for the key
* @param binaryKey
* @return
*/
public byte[] getBinaryForKey(String binaryKey);
/**
* Load relevant resources of the appropriate types (as specified by the loader) from the nominated package

View File

@ -52,9 +52,9 @@ public class XVerExtensionManager {
String v = url.substring(20, 23);
String e = url.substring(54);
if (!lists.containsKey(v)) {
if (context.getBinaries().containsKey("xver-paths-"+v+".json")) {
if (context.hasBinaryKey("xver-paths-"+v+".json")) {
try {
lists.put(v, JsonTrackingParser.parseJson(context.getBinaries().get("xver-paths-"+v+".json")));
lists.put(v, JsonTrackingParser.parseJson(context.getBinaryForKey("xver-paths-"+v+".json")));
} catch (IOException e1) {
throw new FHIRException(e);
}

View File

@ -67,11 +67,11 @@ public class ComparisonService {
System.out.println("Generating output to " + dest + "...");
Utilities.createDirectory(dest);
ComparisonRenderer cr = new ComparisonRenderer(validator.getContext(), validator.getContext(), dest, session);
cr.getTemplates().put("CodeSystem", new String(validator.getContext().getBinaries().get("template-comparison-CodeSystem.html")));
cr.getTemplates().put("ValueSet", new String(validator.getContext().getBinaries().get("template-comparison-ValueSet.html")));
cr.getTemplates().put("Profile", new String(validator.getContext().getBinaries().get("template-comparison-Profile.html")));
cr.getTemplates().put("Index", new String(validator.getContext().getBinaries().get("template-comparison-index.html")));
cr.getTemplates().put("CapabilityStatement", new String(validator.getContext().getBinaries().get("template-comparison-CapabilityStatement.html")));
cr.getTemplates().put("CodeSystem", new String(validator.getContext().getBinaryForKey("template-comparison-CodeSystem.html")));
cr.getTemplates().put("ValueSet", new String(validator.getContext().getBinaryForKey("template-comparison-ValueSet.html")));
cr.getTemplates().put("Profile", new String(validator.getContext().getBinaryForKey("template-comparison-Profile.html")));
cr.getTemplates().put("Index", new String(validator.getContext().getBinaryForKey("template-comparison-index.html")));
cr.getTemplates().put("CapabilityStatement", new String(validator.getContext().getBinaryForKey("template-comparison-CapabilityStatement.html")));
File htmlFile = cr.render(left, right);
Desktop.getDesktop().browse(htmlFile.toURI());
System.out.println("Done");