use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.
the class PackageVisitor method processPackage.
private void processPackage(String pid, String v) throws IOException {
NpmPackage npm = null;
String fv = null;
try {
npm = pcm.loadPackage(pid, v);
fv = npm.fhirVersion();
} catch (Throwable e) {
System.out.println("Unable to process: " + pid + "#" + v + ": " + e.getMessage());
}
int c = 0;
if (fv != null && (versions.isEmpty() || versions.contains(fv))) {
for (String type : resourceTypes) {
for (String s : npm.listResources(type)) {
c++;
processor.processResource(pid + "#" + v, fv, type, TextFile.streamToBytes(npm.load("package", s)));
}
}
}
System.out.println("Processed: " + pid + "#" + v + ": " + c + " resources");
}
use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.
the class TestingUtilities method getWorkerContext.
public static SimpleWorkerContext getWorkerContext(NpmPackage npmPackage) throws Exception {
SimpleWorkerContext swc = new SimpleWorkerContext.SimpleWorkerContextBuilder().withAllowLoadingDuplicates(true).withUserAgent(TestConstants.USER_AGENT).withTerminologyCachePath(TestConstants.TX_CACHE).fromPackage(npmPackage);
TerminologyCache.setCacheErrors(true);
return swc;
}
use of org.hl7.fhir.utilities.npm.NpmPackage 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.npm.NpmPackage 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.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.
the class NpmPackage method fromZip.
public static NpmPackage fromZip(InputStream stream, boolean dropRootFolder, String desc) throws IOException {
NpmPackage res = new NpmPackage();
ZipInputStream zip = new ZipInputStream(stream);
ZipEntry ze;
while ((ze = zip.getNextEntry()) != null) {
int size;
byte[] buffer = new byte[2048];
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(bytes, buffer.length);
while ((size = zip.read(buffer, 0, buffer.length)) != -1) {
bos.write(buffer, 0, size);
}
bos.flush();
bos.close();
if (bytes.size() > 0) {
if (dropRootFolder) {
res.loadFile(ze.getName().substring(ze.getName().indexOf("/") + 1), bytes.toByteArray());
} else {
res.loadFile(ze.getName(), bytes.toByteArray());
}
}
zip.closeEntry();
}
zip.close();
try {
res.npm = JsonTrackingParser.parseJson(res.folders.get("package").fetchFile("package.json"));
} catch (Exception e) {
throw new IOException("Error parsing " + (desc == null ? "" : desc + "#") + "package/package.json: " + e.getMessage(), e);
}
res.checkIndexed(desc);
return res;
}
Aggregations