Search in sources :

Example 31 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackageTests method testSave.

@Test
public void testSave() throws IOException {
    NpmPackage npm = NpmPackage.fromPackage(TestingUtilities.loadTestResourceStream("npm", "test.format.old.tgz"));
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    npm.save(bs);
    npm = NpmPackage.fromPackage(new ByteArrayInputStream(bs.toByteArray()));
    checkNpm(npm);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 32 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackageTests method testNewFolder.

@Test
public void testNewFolder() throws IOException {
    // extract the test
    String dst = Utilities.path("[tmp]", "npm", "test.format.new");
    Utilities.clearDirectory(dst);
    unzip(TestingUtilities.loadTestResourceStream("npm", "test.format.new.zip"), new File(dst));
    dst = Utilities.path(dst, "test.format.new");
    NpmPackage npm = NpmPackage.fromFolder(dst);
    checkNpm(npm);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 33 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class NpmPackageTests method testOldFolder.

@Test
public void testOldFolder() throws IOException {
    // extract the test
    String dst = Utilities.path("[tmp]", "npm", "test.format.old");
    Utilities.clearDirectory(dst);
    unzip(TestingUtilities.loadTestResourceStream("npm", "test.format.old.zip"), new File(dst));
    dst = Utilities.path(dst, "test.format.old");
    NpmPackage npm = NpmPackage.fromFolder(dst);
    checkNpm(npm);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 34 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class SimpleWorkerContext method loadFromPackageAndDependenciesInt.

public int loadFromPackageAndDependenciesInt(NpmPackage pi, IContextResourceLoader loader, BasePackageCacheManager pcm, String path) throws FileNotFoundException, IOException, FHIRException {
    int t = 0;
    for (String e : pi.dependencies()) {
        if (!loadedPackages.contains(e) && !VersionUtilities.isCorePackage(e)) {
            NpmPackage npm = pcm.loadPackage(e);
            if (!VersionUtilities.versionsMatch(version, npm.fhirVersion())) {
                System.out.println(formatMessage(I18nConstants.PACKAGE_VERSION_MISMATCH, e, version, npm.fhirVersion(), path));
            }
            t = t + loadFromPackageAndDependenciesInt(npm, loader.getNewLoader(npm), pcm, path + " -> " + npm.name() + "#" + npm.version());
        }
    }
    t = t + loadFromPackageInt(pi, loader, loader.getTypes());
    return t;
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 35 with NpmPackage

use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.

the class PackageValidator method execute.

private void execute() throws IOException {
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    CachingPackageClient pc = new CachingPackageClient(PackageClient.PRIMARY_SERVER);
    for (PackageInfo t : pc.search(null, null, null, false)) {
        System.out.println("Check Package " + t.getId());
        List<PackageInfo> vl = pc.getVersions(t.getId());
        PackageInfo v = vl.get(vl.size() - 1);
        System.out.println(" v" + v.getVersion());
        try {
            NpmPackage pi = pcm.loadPackage(v.getId(), v.getVersion());
            if (VersionUtilities.isR4Ver(pi.fhirVersion()) || VersionUtilities.isR3Ver(pi.fhirVersion()) || VersionUtilities.isR2Ver(pi.fhirVersion())) {
                for (String n : pi.list("package")) {
                    if (n.endsWith(".json") && !n.equals("ig-r4.json")) {
                        InputStream s = pi.load("package", n);
                        try {
                            parseResource(s, pi.fhirVersion());
                        } catch (Exception e) {
                            System.out.println("  error parsing " + n + " for " + pi.fhirVersion() + ": " + e.getMessage());
                        }
                    }
                }
            } else {
                System.out.println("  Unsupported FHIR version " + pi.fhirVersion());
            }
        } catch (Exception e) {
            System.out.println("  Error - no FHIR version");
        }
    }
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) PackageInfo(org.hl7.fhir.utilities.npm.PackageInfo) InputStream(java.io.InputStream) CachingPackageClient(org.hl7.fhir.utilities.npm.CachingPackageClient) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

NpmPackage (org.hl7.fhir.utilities.npm.NpmPackage)34 File (java.io.File)15 FHIRException (org.hl7.fhir.exceptions.FHIRException)15 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)13 IOException (java.io.IOException)11 Test (org.junit.jupiter.api.Test)11 FileNotFoundException (java.io.FileNotFoundException)9 TextFile (org.hl7.fhir.utilities.TextFile)8 FileOutputStream (java.io.FileOutputStream)7 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 PackageResourceInformation (org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation)6 SimpleWorkerContext (org.hl7.fhir.r5.context.SimpleWorkerContext)4 IniFile (org.hl7.fhir.utilities.IniFile)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 RandomAccessFile (java.io.RandomAccessFile)3 URISyntaxException (java.net.URISyntaxException)3 ParseException (java.text.ParseException)3 NotImplementedException (org.apache.commons.lang3.NotImplementedException)3 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)3