Package org.hl7.fhir.utilities.npm
Class NpmPackage
- java.lang.Object
-
- org.hl7.fhir.utilities.npm.NpmPackage
-
public class NpmPackage extends Object
info and loader for a package Packages may exist on disk in the cache, or purely in memory when they are loaded on the fly Packages are contained in subfolders (see the package spec). The FHIR resources will be in "package"- Author:
- Grahame Grieve
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classNpmPackage.IndexVersionSorterstatic interfaceNpmPackage.ITransformingLoaderclassNpmPackage.NpmPackageFolderclassNpmPackage.PackageResourceInformationclassNpmPackage.PackageResourceInformationSorter
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFile(String folderName, String name, byte[] cnt, String type)booleancanLazyLoad()Stringcanonical()voidclearFolder(String folderName)Stringdate()DatedateAsDate()voiddebugDump(String purpose)voiddeleteFolder(String folderName)List<String>dependencies()StringdependencySummary()Stringdescription()static NpmPackageempty()Factory method that starts a new empty package using the given PackageGenerator to create the manifeststatic NpmPackageempty(PackageGenerator thePackageGenerator)Factory method that starts a new empty package using the given PackageGenerator to create the manifestStringfhirVersion()convenience method for getting the package fhir versionStringfhirVersionList()static NpmPackagefromFolder(String path)Factory method that parses a package from an extracted folderstatic NpmPackagefromFolder(String folder, PackageGenerator.PackageType defType, String... exemptions)static @NotNull NpmPackagefromPackage(InputStream tgz)static NpmPackagefromPackage(InputStream tgz, String desc)static NpmPackagefromPackage(InputStream tgz, String desc, boolean progress)static NpmPackagefromUrl(String source)static NpmPackagefromZip(InputStream stream, boolean dropRootFolder, String desc)Map<String,NpmPackage.NpmPackageFolder>getFolders()special case when playing around inside the packageJsonObjectgetNpm()Handle to the package json fileStringgetPath()Map<String,List<String>>getTypes()Keys are resource type names, values are filenamesMap<String,Object>getUserData()StringgetWebLocation()booleanhasCanonical(String url)booleanhasFile(String folder, String file)Stringhomepage()Stringid()convenience method for getting the package id (which in NPM language is the same as the name)voidindexFolder(String desc, NpmPackage.NpmPackageFolder folder)booleanisChangedByLoader()booleanisCore()static booleanisInternalExemptFile(File f)booleanisNotForPublication()booleanisTx()booleanisType(PackageGenerator.PackageType template)static booleanisValidName(String pid)static booleanisValidVersion(String ver)Stringlicense()List<String>list(String folder)Accessing the contents of the package - get a list of files in a subfolder of the packageList<NpmPackage.PackageResourceInformation>listIndexedResources(String... types)List<String>listResources(String... types)InputStreamload(String file)get a stream that contains the contents of one of the files in the base packageInputStreamload(String folder, String file)get a stream that contains the contents of one of the files in a folderInputStreamload(NpmPackage.PackageResourceInformation p)voidloadAllFiles()voidloadAllFiles(NpmPackage.ITransformingLoader loader)InputStreamloadByCanonical(String canonical)get a stream that contains the contents of a resource in the base folder, by it's canonical URLInputStreamloadByCanonical(String folder, String canonical)get a stream that contains the contents of a resource in the nominated folder, by it's canonical URLInputStreamloadByCanonicalVersion(String canonical, String version)get a stream that contains the contents of a resource in the base folder, by it's canonical URLInputStreamloadByCanonicalVersion(String folder, String canonical, String version)get a stream that contains the contents of a resource in the nominated folder, by it's canonical URLInputStreamloadExampleResource(String type, String id)voidloadFile(String n, byte[] data)voidloadFiles(String path, File source, String... exemptions)InputStreamloadResource(String file)use the name from listResources()InputStreamloadResource(String type, String id)Stringname()convenience method for getting the package namevoidreadStream(InputStream tgz, String desc, boolean progress)voidsave(File directory)voidsave(OutputStream stream)Stringsummary()Stringtitle()StringtoolsVersion()StringtoString()Stringtype()voidunPack(String dir)voidunPack(String dir, boolean withAppend)voidunPackWithAppend(String dir)Stringurl()Stringversion()convenience method for getting the package version
-
-
-
Method Detail
-
isValidName
public static boolean isValidName(String pid)
-
isValidVersion
public static boolean isValidVersion(String ver)
-
fromFolder
public static NpmPackage fromFolder(String path) throws IOException
Factory method that parses a package from an extracted folder- Throws:
IOException
-
empty
public static NpmPackage empty(PackageGenerator thePackageGenerator)
Factory method that starts a new empty package using the given PackageGenerator to create the manifest
-
empty
public static NpmPackage empty()
Factory method that starts a new empty package using the given PackageGenerator to create the manifest
-
getUserData
public Map<String,Object> getUserData()
-
loadFiles
public void loadFiles(String path, File source, String... exemptions) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
isInternalExemptFile
public static boolean isInternalExemptFile(File f)
-
fromFolder
public static NpmPackage fromFolder(String folder, PackageGenerator.PackageType defType, String... exemptions) throws IOException
- Throws:
IOException
-
fromPackage
@NotNull public static @NotNull NpmPackage fromPackage(InputStream tgz) throws IOException
- Throws:
IOException
-
fromPackage
public static NpmPackage fromPackage(InputStream tgz, String desc) throws IOException
- Throws:
IOException
-
fromPackage
public static NpmPackage fromPackage(InputStream tgz, String desc, boolean progress) throws IOException
- Throws:
IOException
-
readStream
public void readStream(InputStream tgz, String desc, boolean progress) throws IOException
- Throws:
IOException
-
loadFile
public void loadFile(String n, byte[] data) throws IOException
- Throws:
IOException
-
indexFolder
public void indexFolder(String desc, NpmPackage.NpmPackageFolder folder) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
fromZip
public static NpmPackage fromZip(InputStream stream, boolean dropRootFolder, String desc) throws IOException
- Throws:
IOException
-
list
public List<String> list(String folder) throws IOException
Accessing the contents of the package - get a list of files in a subfolder of the package- Parameters:
folder-- Returns:
- Throws:
IOException
-
listResources
public List<String> listResources(String... types) throws IOException
- Throws:
IOException
-
listIndexedResources
public List<NpmPackage.PackageResourceInformation> listIndexedResources(String... types) throws IOException
- Throws:
IOException
-
loadResource
public InputStream loadResource(String file) throws IOException
use the name from listResources()- Parameters:
id-- Returns:
- Throws:
IOException
-
loadByCanonical
public InputStream loadByCanonical(String canonical) throws IOException
get a stream that contains the contents of a resource in the base folder, by it's canonical URL- Parameters:
url- - the canonical URL of the resource (exact match only)- Returns:
- null if it is not found
- Throws:
IOException
-
loadByCanonical
public InputStream loadByCanonical(String folder, String canonical) throws IOException
get a stream that contains the contents of a resource in the nominated folder, by it's canonical URL- Parameters:
folder- - one of the folders in the package (main folder is "package")url- - the canonical URL of the resource (exact match only)- Returns:
- null if it is not found
- Throws:
IOException
-
loadByCanonicalVersion
public InputStream loadByCanonicalVersion(String canonical, String version) throws IOException
get a stream that contains the contents of a resource in the base folder, by it's canonical URL- Parameters:
url- - the canonical URL of the resource (exact match only)version- - the specified version (or null if the most recent)- Returns:
- null if it is not found
- Throws:
IOException
-
loadByCanonicalVersion
public InputStream loadByCanonicalVersion(String folder, String canonical, String version) throws IOException
get a stream that contains the contents of a resource in the nominated folder, by it's canonical URL- Parameters:
folder- - one of the folders in the package (main folder is "package")url- - the canonical URL of the resource (exact match only)version- - the specified version (or null if the most recent)- Returns:
- null if it is not found
- Throws:
IOException
-
load
public InputStream load(String file) throws IOException
get a stream that contains the contents of one of the files in the base package- Parameters:
file-- Returns:
- Throws:
IOException
-
load
public InputStream load(String folder, String file) throws IOException
get a stream that contains the contents of one of the files in a folder- Parameters:
folder-file-- Returns:
- Throws:
IOException
-
hasFile
public boolean hasFile(String folder, String file) throws IOException
- Throws:
IOException
-
getNpm
public JsonObject getNpm()
Handle to the package json file- Returns:
-
id
public String id()
convenience method for getting the package id (which in NPM language is the same as the name)- Returns:
-
fhirVersion
public String fhirVersion()
convenience method for getting the package fhir version- Returns:
-
isType
public boolean isType(PackageGenerator.PackageType template)
-
description
public String description()
-
dependencies
public List<String> dependencies()
-
toolsVersion
public String toolsVersion()
-
getWebLocation
public String getWebLocation()
-
loadResource
public InputStream loadResource(String type, String id) throws IOException
- Throws:
IOException
-
loadExampleResource
public InputStream loadExampleResource(String type, String id) throws IOException
- Throws:
IOException
-
getFolders
public Map<String,NpmPackage.NpmPackageFolder> getFolders()
special case when playing around inside the package
-
save
public void save(File directory) throws IOException
- Throws:
IOException
-
save
public void save(OutputStream stream) throws IOException
- Throws:
IOException
-
getTypes
public Map<String,List<String>> getTypes()
Keys are resource type names, values are filenames
-
fhirVersionList
public String fhirVersionList()
-
dependencySummary
public String dependencySummary()
-
unPack
public void unPack(String dir) throws IOException
- Throws:
IOException
-
unPackWithAppend
public void unPackWithAppend(String dir) throws IOException
- Throws:
IOException
-
unPack
public void unPack(String dir, boolean withAppend) throws IOException
- Throws:
IOException
-
clearFolder
public void clearFolder(String folderName)
-
deleteFolder
public void deleteFolder(String folderName)
-
loadAllFiles
public void loadAllFiles() throws IOException
- Throws:
IOException
-
loadAllFiles
public void loadAllFiles(NpmPackage.ITransformingLoader loader) throws IOException
- Throws:
IOException
-
isChangedByLoader
public boolean isChangedByLoader()
-
isCore
public boolean isCore()
-
isTx
public boolean isTx()
-
hasCanonical
public boolean hasCanonical(String url)
-
canLazyLoad
public boolean canLazyLoad() throws IOException
- Throws:
IOException
-
isNotForPublication
public boolean isNotForPublication()
-
load
public InputStream load(NpmPackage.PackageResourceInformation p) throws FileNotFoundException
- Throws:
FileNotFoundException
-
dateAsDate
public Date dateAsDate()
-
fromUrl
public static NpmPackage fromUrl(String source) throws IOException
- Throws:
IOException
-
-