Fix system path for FileSystemPackageCacheManager

This commit is contained in:
dotasek 2023-09-05 15:35:21 -04:00
parent 8d8e6e188e
commit 82813a88d2
9 changed files with 84 additions and 58 deletions

View File

@ -160,7 +160,7 @@ public class StructureMapUtilities {
public List<Base> performSearch(Object appContext, String url); public List<Base> performSearch(Object appContext, String url);
} }
private class FFHIRPathHostServices implements IEvaluationContext{ private class FHIRPathHostServices implements IEvaluationContext{
public Base resolveConstant(Object appContext, String name) throws PathEngineException { public Base resolveConstant(Object appContext, String name) throws PathEngineException {
Variables vars = (Variables) appContext; Variables vars = (Variables) appContext;
@ -223,7 +223,7 @@ public class StructureMapUtilities {
this.services = services; this.services = services;
this.pkp = pkp; this.pkp = pkp;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public StructureMapUtilities(IWorkerContext worker, Map<String, StructureMap> library, ITransformerServices services) { public StructureMapUtilities(IWorkerContext worker, Map<String, StructureMap> library, ITransformerServices services) {
@ -232,7 +232,7 @@ public class StructureMapUtilities {
this.library = library; this.library = library;
this.services = services; this.services = services;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public StructureMapUtilities(IWorkerContext worker, Map<String, StructureMap> library) { public StructureMapUtilities(IWorkerContext worker, Map<String, StructureMap> library) {
@ -240,14 +240,14 @@ public class StructureMapUtilities {
this.worker = worker; this.worker = worker;
this.library = library; this.library = library;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public StructureMapUtilities(IWorkerContext worker) { public StructureMapUtilities(IWorkerContext worker) {
super(); super();
this.worker = worker; this.worker = worker;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) { public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) {
@ -260,7 +260,7 @@ public class StructureMapUtilities {
} }
this.services = services; this.services = services;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public static String render(StructureMap map) { public static String render(StructureMap map) {

View File

@ -175,7 +175,7 @@ public class StructureMapUtilities {
public List<Base> performSearch(Object appContext, String url) throws FHIRException; public List<Base> performSearch(Object appContext, String url) throws FHIRException;
} }
private class FFHIRPathHostServices implements IEvaluationContext { private class FHIRPathHostServices implements IEvaluationContext {
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext)
throws PathEngineException { throws PathEngineException {
@ -241,7 +241,7 @@ public class StructureMapUtilities {
ok = ok && v.getLevel().isError(); ok = ok && v.getLevel().isError();
return ok; return ok;
} }
throw new NotImplementedException("Not done yet (FFHIRPathHostServices.conformsToProfile), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathHostServices.conformsToProfile), when item is element");
} }
@Override @Override
@ -264,7 +264,7 @@ public class StructureMapUtilities {
this.services = services; this.services = services;
this.pkp = pkp; this.pkp = pkp;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) { public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) {
@ -272,7 +272,7 @@ public class StructureMapUtilities {
this.worker = worker; this.worker = worker;
this.services = services; this.services = services;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
public StructureMapUtilities(IWorkerContext worker) { public StructureMapUtilities(IWorkerContext worker) {
@ -280,7 +280,7 @@ public class StructureMapUtilities {
this.worker = worker; this.worker = worker;
if (worker != null) { if (worker != null) {
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
} }
} }

View File

@ -16,11 +16,11 @@ import org.hl7.fhir.utilities.validation.ValidationMessage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext { public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
private final StructureMapUtilities structureMapUtilities; private final StructureMapUtilities structureMapUtilities;
public FFHIRPathHostServices(StructureMapUtilities structureMapUtilities) { public FHIRPathHostServices(StructureMapUtilities structureMapUtilities) {
this.structureMapUtilities = structureMapUtilities; this.structureMapUtilities = structureMapUtilities;
} }
@ -96,7 +96,7 @@ public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext
return noErrorValidationMessages(valerrors); return noErrorValidationMessages(valerrors);
} }
throw new NotImplementedException( throw new NotImplementedException(
"Not done yet (FFHIRPathHostServices.conformsToProfile), when item is not element or not resource"); "Not done yet (FHIRPathHostServices.conformsToProfile), when item is not element or not resource");
} }
@Override @Override

View File

@ -109,7 +109,7 @@ public class StructureMapUtilities {
private static final boolean RENDER_MULTIPLE_TARGETS_ONELINE = true; private static final boolean RENDER_MULTIPLE_TARGETS_ONELINE = true;
private static final String AUTO_VAR_NAME = "vvv"; private static final String AUTO_VAR_NAME = "vvv";
private class FFHIRPathHostServices implements IEvaluationContext { private class FHIRPathHostServices implements IEvaluationContext {
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext) public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext)
throws PathEngineException { throws PathEngineException {
@ -177,7 +177,7 @@ public class StructureMapUtilities {
ok = ok && v.getLevel().isError(); ok = ok && v.getLevel().isError();
return ok; return ok;
} }
throw new NotImplementedException("Not done yet (FFHIRPathHostServices.conformsToProfile), when item is element"); throw new NotImplementedException("Not done yet (FHIRPathHostServices.conformsToProfile), when item is element");
} }
@Override @Override
@ -201,7 +201,7 @@ public class StructureMapUtilities {
this.services = services; this.services = services;
this.pkp = pkp; this.pkp = pkp;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
} }
@ -210,7 +210,7 @@ public class StructureMapUtilities {
this.worker = worker; this.worker = worker;
this.services = services; this.services = services;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
} }
@ -218,7 +218,7 @@ public class StructureMapUtilities {
super(); super();
this.worker = worker; this.worker = worker;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices()); fpe.setHostServices(new FHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
} }

View File

@ -16,11 +16,11 @@ import org.hl7.fhir.utilities.validation.ValidationMessage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext { public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
private final StructureMapUtilities structureMapUtilities; private final StructureMapUtilities structureMapUtilities;
public FFHIRPathHostServices(StructureMapUtilities structureMapUtilities) { public FHIRPathHostServices(StructureMapUtilities structureMapUtilities) {
this.structureMapUtilities = structureMapUtilities; this.structureMapUtilities = structureMapUtilities;
} }
@ -92,7 +92,7 @@ public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext
val.validate(appContext, valerrors, null, (Element) item, url); val.validate(appContext, valerrors, null, (Element) item, url);
return noErrorValidationMessages(valerrors); return noErrorValidationMessages(valerrors);
} }
throw new NotImplementedException("Not done yet (FFHIRPathHostServices.conformsToProfile), when item is not element or not resource"); throw new NotImplementedException("Not done yet (FHIRPathHostServices.conformsToProfile), when item is not element or not resource");
} }
@Override @Override

View File

@ -116,7 +116,7 @@ public class StructureMapUtilities {
this.services = services; this.services = services;
this.pkp = pkp; this.pkp = pkp;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices(this)); fpe.setHostServices(new FHIRPathHostServices(this));
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
} }
@ -125,7 +125,7 @@ public class StructureMapUtilities {
this.worker = worker; this.worker = worker;
this.services = services; this.services = services;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices(this)); fpe.setHostServices(new FHIRPathHostServices(this));
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
} }
@ -133,7 +133,7 @@ public class StructureMapUtilities {
super(); super();
this.worker = worker; this.worker = worker;
fpe = new FHIRPathEngine(worker); fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices(this)); fpe.setHostServices(new FHIRPathHostServices(this));
profileUtilities = new ProfileUtilities(worker, null, null); profileUtilities = new ProfileUtilities(worker, null, null);
} }

View File

@ -11,7 +11,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class FFHIRPathHostServicesTest { class FHIRPathHostServicesTest {
static private SimpleWorkerContext context; static private SimpleWorkerContext context;
@BeforeAll @BeforeAll
@ -23,7 +23,7 @@ class FFHIRPathHostServicesTest {
@Test @Test
public void testrResolveValueSet() throws IOException, FHIRException { public void testrResolveValueSet() throws IOException, FHIRException {
StructureMapUtilities scu = new StructureMapUtilities(context); StructureMapUtilities scu = new StructureMapUtilities(context);
FFHIRPathHostServices fphs = new FFHIRPathHostServices(scu); FHIRPathHostServices fphs = new FHIRPathHostServices(scu);
ValueSet v = fphs.resolveValueSet(null, "http://hl7.org/fhir/ValueSet/FHIR-version"); ValueSet v = fphs.resolveValueSet(null, "http://hl7.org/fhir/ValueSet/FHIR-version");
Assertions.assertNotNull(v); Assertions.assertNotNull(v);
Assertions.assertEquals("http://hl7.org/fhir/ValueSet/FHIR-version", v.getUrl()); Assertions.assertEquals("http://hl7.org/fhir/ValueSet/FHIR-version", v.getUrl());

View File

@ -146,7 +146,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
switch (mode) { switch (mode) {
case SYSTEM: case SYSTEM:
cacheFolder = new File(Utilities.path("var", "lib", ".fhir", "packages")); cacheFolder = new File(Utilities.path("/var", "lib", ".fhir", "packages"));
break; break;
case USER: case USER:
cacheFolder = new File(Utilities.path(System.getProperty("user.home"), ".fhir", "packages")); cacheFolder = new File(Utilities.path(System.getProperty("user.home"), ".fhir", "packages"));
@ -162,10 +162,17 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
break; break;
} }
initCacheFolder();
}
protected void initCacheFolder() throws IOException {
if (!(cacheFolder.exists())) if (!(cacheFolder.exists()))
Utilities.createDirectory(cacheFolder.getAbsolutePath()); Utilities.createDirectory(cacheFolder.getAbsolutePath());
if (!(new File(Utilities.path(cacheFolder, "packages.ini")).exists())) String packagesIniPath = Utilities.path(cacheFolder, "packages.ini");
TextFile.stringToFile("[cache]\r\nversion=" + CACHE_VERSION + "\r\n\r\n[urls]\r\n\r\n[local]\r\n\r\n", Utilities.path(cacheFolder, "packages.ini"), false); File packagesIniFile = new File(packagesIniPath);
if (!(packagesIniFile.exists()))
packagesIniFile.createNewFile();
TextFile.stringToFile("[cache]\r\nversion=" + CACHE_VERSION + "\r\n\r\n[urls]\r\n\r\n[local]\r\n\r\n", packagesIniPath, false);
createIniFile(); createIniFile();
for (File f : cacheFolder.listFiles()) { for (File f : cacheFolder.listFiles()) {
if (f.isDirectory() && Utilities.isValidUUID(f.getName())) { if (f.isDirectory() && Utilities.isValidUUID(f.getName())) {

View File

@ -2,6 +2,7 @@ package org.hl7.fhir.utilities.npm;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -64,4 +65,22 @@ public class FilesystemPackageManagerTests {
} }
}; };
} }
@Test
public void testUserCacheDirectory() throws IOException {
FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager(true) {
protected void initCacheFolder() throws IOException {
}
};
assertEquals(System.getProperty("user.home") + File.separator + ".fhir/packages", filesystemPackageCacheManager.getFolder());
}
@Test
public void testSystemCacheDirectory() throws IOException {
FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager(false) {
protected void initCacheFolder() throws IOException {
}
};
assertEquals( "/var/lib/.fhir/packages", filesystemPackageCacheManager.getFolder());
}
} }