From cdaf85bf0bf501cbb0df87136a7904fc9682f6f4 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 24 Sep 2024 20:34:23 -0400 Subject: [PATCH] support n/a for tx cache folder --- .../utilities/TerminologyCache.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/utilities/TerminologyCache.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/utilities/TerminologyCache.java index b65c63a2e..3a60a33bc 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/utilities/TerminologyCache.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/utilities/TerminologyCache.java @@ -302,22 +302,26 @@ public class TerminologyCache { this.lock = lock; if (folder == null) { folder = Utilities.path("[tmp]", "default-tx-cache"); + } else if ("n/a".equals(folder)) { + // this is a weird way to do things but it maintains the legacy interface + folder = null; } this.folder = folder; requestCount = 0; hitCount = 0; networkCount = 0; - - File f = ManagedFileAccess.file(folder); - if (!f.exists()) { - Utilities.createDirectory(folder); + if (folder != null) { + File f = ManagedFileAccess.file(folder); + if (!f.exists()) { + Utilities.createDirectory(folder); + } + if (!f.exists()) { + throw new IOException("Unable to create terminology cache at "+folder); + } + checkVersion(); + load(); } - if (!f.exists()) { - throw new IOException("Unable to create terminology cache at "+folder); - } - checkVersion(); - load(); } private void checkVersion() throws IOException { @@ -361,7 +365,9 @@ public class TerminologyCache { } private void clear() throws IOException { - Utilities.clearDirectory(folder); + if (folder != null) { + Utilities.clearDirectory(folder); + } caches.clear(); vsCache.clear(); csCache.clear(); @@ -1039,7 +1045,7 @@ public class TerminologyCache { public SourcedValueSet getValueSet(String canonical) { SourcedValueSetEntry sp = vsCache.get(canonical); - if (sp == null) { + if (sp == null || folder == null) { return null; } else { try { @@ -1052,7 +1058,7 @@ public class TerminologyCache { public SourcedCodeSystem getCodeSystem(String canonical) { SourcedCodeSystemEntry sp = csCache.get(canonical); - if (sp == null) { + if (sp == null || folder == null) { return null; } else { try { @@ -1073,7 +1079,9 @@ public class TerminologyCache { } else { String uuid = Utilities.makeUuidLC(); String fn = "vs-"+uuid+".json"; - new JsonParser().compose(ManagedFileAccess.outStream(Utilities.path(folder, fn)), svs.getVs()); + if (folder != null) { + new JsonParser().compose(ManagedFileAccess.outStream(Utilities.path(folder, fn)), svs.getVs()); + } vsCache.put(canonical, new SourcedValueSetEntry(svs.getServer(), fn)); } org.hl7.fhir.utilities.json.model.JsonObject j = new org.hl7.fhir.utilities.json.model.JsonObject(); @@ -1090,7 +1098,9 @@ public class TerminologyCache { j.add(k, e); } } - org.hl7.fhir.utilities.json.parser.JsonParser.compose(j, ManagedFileAccess.file(Utilities.path(folder, "vs-externals.json")), true); + if (folder != null) { + org.hl7.fhir.utilities.json.parser.JsonParser.compose(j, ManagedFileAccess.file(Utilities.path(folder, "vs-externals.json")), true); + } } catch (Exception e) { e.printStackTrace(); } @@ -1106,7 +1116,9 @@ public class TerminologyCache { } else { String uuid = Utilities.makeUuidLC(); String fn = "cs-"+uuid+".json"; - new JsonParser().compose(ManagedFileAccess.outStream(Utilities.path(folder, fn)), scs.getCs()); + if (folder != null) { + new JsonParser().compose(ManagedFileAccess.outStream(Utilities.path(folder, fn)), scs.getCs()); + } csCache.put(canonical, new SourcedCodeSystemEntry(scs.getServer(), fn)); } org.hl7.fhir.utilities.json.model.JsonObject j = new org.hl7.fhir.utilities.json.model.JsonObject(); @@ -1123,7 +1135,9 @@ public class TerminologyCache { j.add(k, e); } } - org.hl7.fhir.utilities.json.parser.JsonParser.compose(j, ManagedFileAccess.file(Utilities.path(folder, "cs-externals.json")), true); + if (folder != null) { + org.hl7.fhir.utilities.json.parser.JsonParser.compose(j, ManagedFileAccess.file(Utilities.path(folder, "cs-externals.json")), true); + } } catch (Exception e) { e.printStackTrace(); }