Package org.dspace.pack.bagit
Class BagItAipReader
- java.lang.Object
-
- org.dspace.pack.bagit.BagItAipReader
-
public class BagItAipReader extends Object
Assist in reading aips and retrieving information from the package.- Since:
- 2020-03-19
- Author:
- mikejritter
-
-
Constructor Summary
Constructors Constructor Description BagItAipReader(Path bag)Constructor for aBagItAipReader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclean()Finish operations and remove the aipList<PackagedBitstream>findBitstreams()Find anyBitstreams packaged in an aip and return path, bundle name, and metadatacom.google.common.base.Optional<Metadata>findItemTemplate()Search forMetadatafor an Item Template in a Bagcom.google.common.base.Optional<Path>findLogo()Retrieve the logo for an aip, if it is availablecom.google.common.base.Optional<Path>findRoles()Attempt to find the data/roles.xml within a Bag.List<String>readFile(String relativePath)Read a file's lines given a relative path to the file.MetadatareadMetadata()Read the metadata.xml file located in a bags data directoryPoliciesreadPolicy()Read the policy.xml file located in a bags data directoryPropertiesreadProperties()Retrieve the object.properties for an aipvoidvalidateBag()Validate that an AIP is in a BagIt format which passes both bagit-bag validation and bagit-profile validation
-
-
-
Constructor Detail
-
BagItAipReader
public BagItAipReader(Path bag) throws IOException
Constructor for aBagItAipReader. If the given path to thebagis a single file, it is assumed that the path is an archived aip and will be deserialized.- Parameters:
bag- thePathto the bag- Throws:
IOException- if there are any errors while deserializing the aip located atPath
-
-
Method Detail
-
validateBag
public void validateBag()
Validate that an AIP is in a BagIt format which passes both bagit-bag validation and bagit-profile validation- Throws:
RuntimeException- if there is an error during validation
-
readProperties
public Properties readProperties() throws IOException
Retrieve the object.properties for an aip- Returns:
- the
Properties, loaded from the data/object.properties - Throws:
IOException- if there is an error loading the properties
-
readFile
public List<String> readFile(String relativePath)
Read a file's lines given a relative path to the file. If a file does not exist, or an error is encountered while trying to read the file an empty list is returned. Note: the path given should be in relation to the data directory, not the root of the bag
-
findLogo
public com.google.common.base.Optional<Path> findLogo() throws IOException
Retrieve the logo for an aip, if it is available- Returns:
- an
Optionalcontaining theInputStreamof the logo if it exists, andOptional.absent()otherwise - Throws:
IOException- if there is an error getting theInputStreamfor the logo
-
readMetadata
public Metadata readMetadata() throws IOException
Read the metadata.xml file located in a bags data directory- Returns:
- the
Metadatawith values read from data/metadata.xml - Throws:
IOException- if there was an error reading the file or parsing the xml
-
findItemTemplate
public com.google.common.base.Optional<Metadata> findItemTemplate() throws IOException
Search forMetadatafor an Item Template in a Bag- Returns:
- the
Metadatawith values read from data/template-metadata.xml if it exists - Throws:
IOException
-
readPolicy
public Policies readPolicy() throws IOException
Read the policy.xml file located in a bags data directory- Returns:
- the
Policywith values read from data/policy.xml - Throws:
IOException- if there was an error reading the file or parsing the xml
-
findRoles
public com.google.common.base.Optional<Path> findRoles()
Attempt to find the data/roles.xml within a Bag. If it does not exist, return an emptyOptional.- Returns:
- an
Optionalcontaining thePathfor the roles.xml, if it exists
-
findBitstreams
public List<PackagedBitstream> findBitstreams() throws IOException
Find anyBitstreams packaged in an aip and return path, bundle name, and metadata- Returns:
- a list of
PackagedBitstreams found - Throws:
IOException- if there are any errors searching for bitstreams
-
clean
public void clean() throws IOExceptionFinish operations and remove the aip- Throws:
IOException- if there are any errors removing the aip
-
-