Search in sources :

Example 11 with NpmPackage

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

the class NpmPackageTests method testNewTgz.

@Test
public void testNewTgz() throws IOException {
    NpmPackage npm = NpmPackage.fromPackage(TestingUtilities.loadTestResourceStream("npm", "test.format.new.tgz"));
    checkNpm(npm);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) Test(org.junit.jupiter.api.Test)

Example 12 with NpmPackage

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

the class IgLoader method fetchVersionByPackage.

private String fetchVersionByPackage(String src) throws FHIRException, IOException {
    String id = src;
    String version = null;
    if (src.contains("#")) {
        id = src.substring(0, src.indexOf("#"));
        version = src.substring(src.indexOf("#") + 1);
    }
    if (version == null) {
        version = getPackageCacheManager().getLatestVersion(id);
    }
    NpmPackage pi = null;
    if (version == null) {
        pi = getPackageCacheManager().loadPackageFromCacheOnly(id);
        if (pi != null)
            System.out.println("   ... Using version " + pi.version());
    } else
        pi = getPackageCacheManager().loadPackageFromCacheOnly(id, version);
    if (pi == null) {
        return resolvePackageForVersion(id, version);
    } else {
        return pi.fhirVersion();
    }
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 13 with NpmPackage

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

the class IgLoader method fetchByPackage.

private Map<String, byte[]> fetchByPackage(String src) throws FHIRException, IOException {
    String id = src;
    String version = null;
    if (src.contains("#")) {
        id = src.substring(0, src.indexOf("#"));
        version = src.substring(src.indexOf("#") + 1);
    }
    if (version == null) {
        version = getPackageCacheManager().getLatestVersion(id);
    }
    NpmPackage pi;
    if (version == null) {
        pi = getPackageCacheManager().loadPackageFromCacheOnly(id);
        if (pi != null)
            System.out.println("   ... Using version " + pi.version());
    } else
        pi = getPackageCacheManager().loadPackageFromCacheOnly(id, version);
    if (pi == null) {
        return resolvePackage(id, version);
    } else
        return loadPackage(pi);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 14 with NpmPackage

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

the class ValidationEngine method loadCoreDefinitions.

/**
 * @param src
 * @param recursive
 * @param terminologyCachePath
 * @param userAgent
 * @param tt
 * @param loggingService
 * @throws FHIRException
 * @throws IOException
 *
 * @see IgLoader#loadIgSource(String, boolean, boolean) loadIgSource for detailed description of the src parameter
 */
private void loadCoreDefinitions(String src, boolean recursive, String terminologyCachePath, String userAgent, TimeTracker tt, IWorkerContext.ILoggingService loggingService) throws FHIRException, IOException {
    NpmPackage npm = getPcm().loadPackage(src, null);
    if (npm != null) {
        version = npm.fhirVersion();
        SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder().withLoggingService(loggingService);
        if (terminologyCachePath != null)
            contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
        if (userAgent != null) {
            contextBuilder.withUserAgent(userAgent);
        }
        context = contextBuilder.fromPackage(npm, ValidatorUtils.loaderForVersion(version));
    } else {
        Map<String, byte[]> source = igLoader.loadIgSource(src, recursive, true);
        if (version == null) {
            version = getVersionFromPack(source);
        }
        SimpleWorkerContext.SimpleWorkerContextBuilder contextBuilder = new SimpleWorkerContext.SimpleWorkerContextBuilder();
        if (terminologyCachePath != null)
            contextBuilder = contextBuilder.withTerminologyCachePath(terminologyCachePath);
        if (userAgent != null) {
            contextBuilder.withUserAgent(userAgent);
        }
        context = contextBuilder.fromDefinitions(source, ValidatorUtils.loaderForVersion(version), new PackageVersion(src, new Date()));
        ValidatorUtils.grabNatives(getBinaries(), source, "http://hl7.org/fhir");
    }
    // on https://chat.fhir.org/#narrow/stream/179167-hapi
    try {
        ClassLoader classLoader = ValidationEngine.class.getClassLoader();
        InputStream ue = classLoader.getResourceAsStream("ucum-essence.xml");
        context.setUcumService(new UcumEssenceService(ue));
    } catch (Exception e) {
        throw new FHIRException("Error loading UCUM from embedded ucum-essence.xml: " + e.getMessage(), e);
    }
    initContext(tt);
}
Also used : SimpleWorkerContext(org.hl7.fhir.r5.context.SimpleWorkerContext) PackageVersion(org.hl7.fhir.r5.context.IWorkerContext.PackageVersion) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) UcumEssenceService(org.fhir.ucum.UcumEssenceService) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 15 with NpmPackage

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

the class ValidationEngine method initContext.

protected void initContext(TimeTracker tt) throws IOException {
    context.setCanNoTS(true);
    context.setCacheId(UUID.randomUUID().toString());
    // because of Forge
    context.setAllowLoadingDuplicates(true);
    context.setExpansionProfile(makeExpProfile());
    if (tt != null) {
        context.setClock(tt);
    }
    NpmPackage npmX = getPcm().loadPackage(CommonPackages.ID_XVER, CommonPackages.VER_XVER);
    context.loadFromPackage(npmX, null);
    this.fhirPathEngine = new FHIRPathEngine(context);
}
Also used : NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine)

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