use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class FilesystemPackageCacheManager method fetchTheOldWay.
// ----- the old way, from before package server, while everything gets onto the package server
private InputStreamWithSrc fetchTheOldWay(String id, String v) {
String url = getUrlForPackage(id);
if (url == null) {
try {
url = getPackageUrlFromBuildList(id);
} catch (Exception e) {
url = null;
}
}
if (url == null) {
throw new FHIRException("Unable to resolve package id " + id + "#" + v);
}
if (url.contains("/ImplementationGuide/")) {
url = url.substring(0, url.indexOf("/ImplementationGuide/"));
}
String pu = Utilities.pathURL(url, "package-list.json");
String aurl = pu;
JsonObject json;
try {
json = JsonTrackingParser.fetchJson(pu);
} catch (Exception e) {
String pv = Utilities.pathURL(url, v, "package.tgz");
try {
aurl = pv;
InputStreamWithSrc src = new InputStreamWithSrc(fetchFromUrlSpecific(pv, false), pv, v);
return src;
} catch (Exception e1) {
throw new FHIRException("Error fetching package directly (" + pv + "), or fetching package list for " + id + " from " + pu + ": " + e1.getMessage(), e1);
}
}
if (!id.equals(JSONUtil.str(json, "package-id")))
throw new FHIRException("Package ids do not match in " + pu + ": " + id + " vs " + JSONUtil.str(json, "package-id"));
for (JsonElement e : json.getAsJsonArray("list")) {
JsonObject vo = (JsonObject) e;
if (v.equals(JSONUtil.str(vo, "version"))) {
aurl = Utilities.pathURL(JSONUtil.str(vo, "path"), "package.tgz");
String u = Utilities.pathURL(JSONUtil.str(vo, "path"), "package.tgz");
return new InputStreamWithSrc(fetchFromUrlSpecific(u, true), u, v);
}
}
return null;
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class FilesystemPackageCacheManager method loadPackageFromCacheOnly.
/**
* Load the identified package from the cache - if it exists
* <p>
* This is for special purpose only (testing, control over speed of loading).
* Generally, use the loadPackage method
*
* @param id
* @param version
* @return
* @throws IOException
*/
@Override
public NpmPackage loadPackageFromCacheOnly(String id, String version) throws IOException {
if (!Utilities.noString(version) && version.startsWith("file:")) {
return loadPackageFromFile(id, version.substring(5));
}
for (NpmPackage p : temporaryPackages) {
if (p.name().equals(id) && ("current".equals(version) || "dev".equals(version) || p.version().equals(version))) {
return p;
}
if (p.name().equals(id) && Utilities.noString(version)) {
return p;
}
}
String foundPackage = null;
String foundVersion = null;
for (String f : reverseSorted(new File(cacheFolder).list())) {
File cf = new File(Utilities.path(cacheFolder, f));
if (cf.isDirectory()) {
if (f.equals(id + "#" + version) || (Utilities.noString(version) && f.startsWith(id + "#"))) {
return loadPackageInfo(Utilities.path(cacheFolder, f));
}
if (version != null && version.endsWith(".x") && f.contains("#")) {
String[] parts = f.split("#");
if (parts[0].equals(id) && VersionUtilities.isMajMinOrLaterPatch((foundVersion != null ? foundVersion : version), parts[1])) {
foundVersion = parts[1];
foundPackage = f;
}
}
}
}
if (foundPackage != null) {
return loadPackageInfo(Utilities.path(cacheFolder, foundPackage));
}
if ("dev".equals(version))
return loadPackageFromCacheOnly(id, "current");
else
return null;
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NpmPackage method fromFolder.
/**
* Factory method that parses a package from an extracted folder
*/
public static NpmPackage fromFolder(String path) throws IOException {
NpmPackage res = new NpmPackage();
res.loadFiles(path, new File(path));
res.checkIndexed(path);
return res;
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NpmPackage method loadSubFolders.
private void loadSubFolders(String rootPath, File dir) throws IOException {
for (File f : dir.listFiles()) {
if (f.isDirectory()) {
String d = f.getAbsolutePath().substring(rootPath.length() + 1);
if (!d.startsWith("package")) {
d = Utilities.path("package", d);
}
NpmPackageFolder folder = this.new NpmPackageFolder(d);
folder.folder = f;
this.folders.put(d, folder);
File ij = new File(Utilities.path(f.getAbsolutePath(), ".index.json"));
if (ij.exists()) {
try {
if (!folder.readIndex(JsonTrackingParser.parseJson(ij))) {
indexFolder(folder.getName(), folder);
}
} catch (Exception e) {
throw new IOException("Error parsing " + ij.getAbsolutePath() + ": " + e.getMessage(), e);
}
}
loadSubFolders(rootPath, f);
}
}
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NpmPackage method indexFolder.
public void indexFolder(String desc, NpmPackageFolder folder) throws FileNotFoundException, IOException {
List<String> remove = new ArrayList<>();
NpmPackageIndexBuilder indexer = new NpmPackageIndexBuilder();
indexer.start();
for (String n : folder.listFiles()) {
if (!indexer.seeFile(n, folder.fetchFile(n))) {
remove.add(n);
}
}
for (String n : remove) {
folder.removeFile(n);
}
String json = indexer.build();
try {
folder.readIndex(JsonTrackingParser.parseJson(json));
if (folder.folder != null) {
TextFile.stringToFile(json, Utilities.path(folder.folder.getAbsolutePath(), ".index.json"));
}
} catch (Exception e) {
TextFile.stringToFile(json, Utilities.path("[tmp]", ".index.json"));
throw new IOException("Error parsing " + (desc == null ? "" : desc + "#") + "package/" + folder.name + "/.index.json: " + e.getMessage(), e);
}
}
Aggregations