feat: added support for package.tgz uri in the "file:/" format (#3347)
* feat: added support for package.zgz uri in the "file:/" format * added changelog entry * add error code to thrown message Co-authored-by: Tadgh <garygrantgraham@gmail.com>
This commit is contained in:
parent
f6181fb6ff
commit
2531e6e57d
|
@ -25,7 +25,7 @@ public final class Msg {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IMPORTANT: Please update the following comment after you add a new code
|
* IMPORTANT: Please update the following comment after you add a new code
|
||||||
* Last code value: 2023
|
* Last code value: 2024
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private Msg() {}
|
private Msg() {}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
type: add
|
||||||
|
issue: 3347
|
||||||
|
title: "Added ability to load Implementation Guide packages from filesystem by supporting the file:/ syntax of url."
|
|
@ -88,7 +88,11 @@ import javax.transaction.Transactional;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -473,7 +477,14 @@ public class JpaPackageCache extends BasePackageCacheManager implements IHapiPac
|
||||||
|
|
||||||
protected byte[] loadPackageUrlContents(String thePackageUrl) {
|
protected byte[] loadPackageUrlContents(String thePackageUrl) {
|
||||||
if (thePackageUrl.startsWith("classpath:")) {
|
if (thePackageUrl.startsWith("classpath:")) {
|
||||||
return ClasspathUtil.loadResourceAsByteArray(thePackageUrl.substring("classpath:".length()));
|
return ClasspathUtil.loadResourceAsByteArray(thePackageUrl.substring("classpath:" .length()));
|
||||||
|
} else if (thePackageUrl.startsWith("file:")) {
|
||||||
|
try {
|
||||||
|
byte[] bytes = Files.readAllBytes(Paths.get(new URI(thePackageUrl)));
|
||||||
|
return bytes;
|
||||||
|
} catch (IOException | URISyntaxException e) {
|
||||||
|
throw new InternalErrorException(Msg.code(2024) + "Error loading \"" + thePackageUrl + "\": " + e.getMessage());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
|
HttpClientConnectionManager connManager = new BasicHttpClientConnectionManager();
|
||||||
try (CloseableHttpResponse request = HttpClientBuilder
|
try (CloseableHttpResponse request = HttpClientBuilder
|
||||||
|
|
|
@ -59,6 +59,8 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -924,20 +926,39 @@ public class NpmR4Test extends BaseJpaR4Test {
|
||||||
map.add(StructureDefinition.SP_URL, new UriParam("https://www.medizininformatik-initiative.de/fhir/core/modul-labor/StructureDefinition/LogicalModel/Laborbefund"));
|
map.add(StructureDefinition.SP_URL, new UriParam("https://www.medizininformatik-initiative.de/fhir/core/modul-labor/StructureDefinition/LogicalModel/Laborbefund"));
|
||||||
IBundleProvider result = myStructureDefinitionDao.search(map);
|
IBundleProvider result = myStructureDefinitionDao.search(map);
|
||||||
assertEquals(1, result.sizeOrThrowNpe());
|
assertEquals(1, result.sizeOrThrowNpe());
|
||||||
List<IBaseResource> resources = result.getResources(0,1);
|
List<IBaseResource> resources = result.getResources(0, 1);
|
||||||
assertFalse(((StructureDefinition)resources.get(0)).hasSnapshot());
|
assertFalse(((StructureDefinition) resources.get(0)).hasSnapshot());
|
||||||
|
|
||||||
// Confirm that DiagnosticLab (a resource StructureDefinition with differential but no snapshot) was created with a generated snapshot.
|
// Confirm that DiagnosticLab (a resource StructureDefinition with differential but no snapshot) was created with a generated snapshot.
|
||||||
map = SearchParameterMap.newSynchronous();
|
map = SearchParameterMap.newSynchronous();
|
||||||
map.add(StructureDefinition.SP_URL, new UriParam("https://www.medizininformatik-initiative.de/fhir/core/modul-labor/StructureDefinition/DiagnosticReportLab"));
|
map.add(StructureDefinition.SP_URL, new UriParam("https://www.medizininformatik-initiative.de/fhir/core/modul-labor/StructureDefinition/DiagnosticReportLab"));
|
||||||
result = myStructureDefinitionDao.search(map);
|
result = myStructureDefinitionDao.search(map);
|
||||||
assertEquals(1, result.sizeOrThrowNpe());
|
assertEquals(1, result.sizeOrThrowNpe());
|
||||||
resources = result.getResources(0,1);
|
resources = result.getResources(0, 1);
|
||||||
assertTrue(((StructureDefinition)resources.get(0)).hasSnapshot());
|
assertTrue(((StructureDefinition) resources.get(0)).hasSnapshot());
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInstallR4PackageFromFile() {
|
||||||
|
|
||||||
|
Path currentRelativePath = Paths.get("");
|
||||||
|
String s = currentRelativePath.toAbsolutePath().toString();
|
||||||
|
System.out.println("Current absolute path is: " + s);
|
||||||
|
|
||||||
|
String fileUrl = "file:" + s + "/src/test/resources/packages/de.basisprofil.r4-1.2.0.tgz";
|
||||||
|
|
||||||
|
myPackageInstallerSvc.install(new PackageInstallationSpec()
|
||||||
|
.setName("de.basisprofil.r4")
|
||||||
|
.setVersion("1.2.0")
|
||||||
|
.setPackageUrl(fileUrl)
|
||||||
|
);
|
||||||
|
runInTransaction(() -> {
|
||||||
|
assertTrue(myPackageVersionDao.findByPackageIdAndVersion("de.basisprofil.r4", "1.2.0").isPresent());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static class FakeNpmServlet extends HttpServlet {
|
static class FakeNpmServlet extends HttpServlet {
|
||||||
|
|
||||||
private final Map<String, byte[]> myResponses = new HashMap<>();
|
private final Map<String, byte[]> myResponses = new HashMap<>();
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue