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);
}
private class FFHIRPathHostServices implements IEvaluationContext{
private class FHIRPathHostServices implements IEvaluationContext{
public Base resolveConstant(Object appContext, String name) throws PathEngineException {
Variables vars = (Variables) appContext;
@ -223,7 +223,7 @@ public class StructureMapUtilities {
this.services = services;
this.pkp = pkp;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
public StructureMapUtilities(IWorkerContext worker, Map<String, StructureMap> library, ITransformerServices services) {
@ -232,7 +232,7 @@ public class StructureMapUtilities {
this.library = library;
this.services = services;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
public StructureMapUtilities(IWorkerContext worker, Map<String, StructureMap> library) {
@ -240,14 +240,14 @@ public class StructureMapUtilities {
this.worker = worker;
this.library = library;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
public StructureMapUtilities(IWorkerContext worker) {
super();
this.worker = worker;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) {
@ -260,7 +260,7 @@ public class StructureMapUtilities {
}
this.services = services;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
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;
}
private class FFHIRPathHostServices implements IEvaluationContext {
private class FHIRPathHostServices implements IEvaluationContext {
public List<Base> resolveConstant(Object appContext, String name, boolean beforeContext)
throws PathEngineException {
@ -241,7 +241,7 @@ public class StructureMapUtilities {
ok = ok && v.getLevel().isError();
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
@ -264,7 +264,7 @@ public class StructureMapUtilities {
this.services = services;
this.pkp = pkp;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
public StructureMapUtilities(IWorkerContext worker, ITransformerServices services) {
@ -272,7 +272,7 @@ public class StructureMapUtilities {
this.worker = worker;
this.services = services;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
}
public StructureMapUtilities(IWorkerContext worker) {
@ -280,7 +280,7 @@ public class StructureMapUtilities {
this.worker = worker;
if (worker != null) {
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.List;
public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
private final StructureMapUtilities structureMapUtilities;
public FFHIRPathHostServices(StructureMapUtilities structureMapUtilities) {
public FHIRPathHostServices(StructureMapUtilities structureMapUtilities) {
this.structureMapUtilities = structureMapUtilities;
}
@ -96,7 +96,7 @@ public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext
return noErrorValidationMessages(valerrors);
}
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

View File

@ -109,7 +109,7 @@ public class StructureMapUtilities {
private static final boolean RENDER_MULTIPLE_TARGETS_ONELINE = true;
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)
throws PathEngineException {
@ -177,7 +177,7 @@ public class StructureMapUtilities {
ok = ok && v.getLevel().isError();
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
@ -201,7 +201,7 @@ public class StructureMapUtilities {
this.services = services;
this.pkp = pkp;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null);
}
@ -210,7 +210,7 @@ public class StructureMapUtilities {
this.worker = worker;
this.services = services;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
profileUtilities = new ProfileUtilities(worker, null, null);
}
@ -218,7 +218,7 @@ public class StructureMapUtilities {
super();
this.worker = worker;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices());
fpe.setHostServices(new FHIRPathHostServices());
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.List;
public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
public class FHIRPathHostServices implements FHIRPathEngine.IEvaluationContext {
private final StructureMapUtilities structureMapUtilities;
public FFHIRPathHostServices(StructureMapUtilities structureMapUtilities) {
public FHIRPathHostServices(StructureMapUtilities structureMapUtilities) {
this.structureMapUtilities = structureMapUtilities;
}
@ -92,7 +92,7 @@ public class FFHIRPathHostServices implements FHIRPathEngine.IEvaluationContext
val.validate(appContext, valerrors, null, (Element) item, url);
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

View File

@ -116,7 +116,7 @@ public class StructureMapUtilities {
this.services = services;
this.pkp = pkp;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices(this));
fpe.setHostServices(new FHIRPathHostServices(this));
profileUtilities = new ProfileUtilities(worker, null, null);
}
@ -125,7 +125,7 @@ public class StructureMapUtilities {
this.worker = worker;
this.services = services;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices(this));
fpe.setHostServices(new FHIRPathHostServices(this));
profileUtilities = new ProfileUtilities(worker, null, null);
}
@ -133,7 +133,7 @@ public class StructureMapUtilities {
super();
this.worker = worker;
fpe = new FHIRPathEngine(worker);
fpe.setHostServices(new FFHIRPathHostServices(this));
fpe.setHostServices(new FHIRPathHostServices(this));
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.Test;
class FFHIRPathHostServicesTest {
class FHIRPathHostServicesTest {
static private SimpleWorkerContext context;
@BeforeAll
@ -23,7 +23,7 @@ class FFHIRPathHostServicesTest {
@Test
public void testrResolveValueSet() throws IOException, FHIRException {
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");
Assertions.assertNotNull(v);
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) {
case SYSTEM:
cacheFolder = new File(Utilities.path("var", "lib", ".fhir", "packages"));
cacheFolder = new File(Utilities.path("/var", "lib", ".fhir", "packages"));
break;
case USER:
cacheFolder = new File(Utilities.path(System.getProperty("user.home"), ".fhir", "packages"));
@ -162,10 +162,17 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
break;
}
initCacheFolder();
}
protected void initCacheFolder() throws IOException {
if (!(cacheFolder.exists()))
Utilities.createDirectory(cacheFolder.getAbsolutePath());
if (!(new File(Utilities.path(cacheFolder, "packages.ini")).exists()))
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);
String packagesIniPath = Utilities.path(cacheFolder, "packages.ini");
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();
for (File f : cacheFolder.listFiles()) {
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 java.io.File;
import java.io.IOException;
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());
}
}