Package nl.knaw.dans.bagit.conformance
Class BagLinter
java.lang.Object
nl.knaw.dans.bagit.conformance.BagLinter
Responsible for checking a bag and providing insight into how it cause problems.
This class is only to be used on VALID bags, using it on un-validated bags may result in
exceptions being thrown (like
IOException
)-
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private static final ResourceBundle
private static final Version
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkAgainstProfile
(InputStream jsonProfile, Bag bag) Check a bag against a bagit-profile as described by https://github.com/ruebot/bagit-profiles
Note: This implementation does not check the Serialization part of the profile!private static void
checkForExtraLines
(Path bagitFile, Collection<BagitWarning> warnings, Collection<BagitWarning> warningsToIgnore) static Set<BagitWarning>
The BagIt specification is very flexible in what it allows which leads to situations where something may be technically allowed, but should be discouraged.static Set<BagitWarning>
lintBag
(Path rootDir, Collection<BagitWarning> warningsToIgnore) The BagIt specification is very flexible in what it allows which leads to situations where something may be technically allowed, but should be discouraged.
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
messages
-
VERSION_1_0
-
-
Constructor Details
-
BagLinter
private BagLinter()
-
-
Method Details
-
checkAgainstProfile
public static void checkAgainstProfile(InputStream jsonProfile, Bag bag) throws com.fasterxml.jackson.core.JsonParseException, com.fasterxml.jackson.databind.JsonMappingException, IOException, FetchFileNotAllowedException, RequiredMetadataFieldNotPresentException, MetatdataValueIsNotAcceptableException, RequiredManifestNotPresentException, BagitVersionIsNotAcceptableException, RequiredTagFileNotPresentException, MetatdataValueIsNotRepeatableException Check a bag against a bagit-profile as described by https://github.com/ruebot/bagit-profiles
Note: This implementation does not check the Serialization part of the profile!- Parameters:
jsonProfile
- the input stream to the json string describing the profilebag
- the bag to check against the profile- Throws:
IOException
- if there is a problem reading the profile or some of the bag filescom.fasterxml.jackson.databind.JsonMappingException
- if there is a problem mapping the profile to theBagitProfile
com.fasterxml.jackson.core.JsonParseException
- if there is a problem parsing the json while mapping to java objectFetchFileNotAllowedException
- if there is a fetch file when the profile prohibits itMetatdataValueIsNotAcceptableException
- if a metadata value is not in the list of acceptable valuesMetatdataValueIsNotRepeatableException
- if a metadata value shows up more than once when not repeatableRequiredMetadataFieldNotPresentException
- if a metadata field is not present but it should beRequiredManifestNotPresentException
- if a payload or tag manifest type is not present but should beBagitVersionIsNotAcceptableException
- if the version of the bag is not in the list of acceptable versionsRequiredTagFileNotPresentException
- if a tag file is not present but should be
-
lintBag
public static Set<BagitWarning> lintBag(Path rootDir) throws IOException, UnparsableVersionException, InvalidBagMetadataException, InvalidBagitFileFormatException, MaliciousPathException, UnsupportedAlgorithmException The BagIt specification is very flexible in what it allows which leads to situations where something may be technically allowed, but should be discouraged. This method checks a bag for potential problems, or other items that are allowed but discouraged. This does not validate a bag. SeeBagVerifier
instead.- Parameters:
rootDir
- the root directory of the bag- Returns:
- a set of
BagitWarning
detailing all items that should be fixed. - Throws:
InvalidBagMetadataException
- if the bag metadata does not conform to the bagit specificationUnparsableVersionException
- if there is an error reading the bagit versionIOException
- if there was an error reading a fileUnsupportedAlgorithmException
- if there is an error while reading one of the manifests due to the algorithm being unsupportedMaliciousPathException
- if the path is crafted to be malicious (overwrite non bag files)InvalidBagitFileFormatException
-
lintBag
public static Set<BagitWarning> lintBag(Path rootDir, Collection<BagitWarning> warningsToIgnore) throws IOException, UnparsableVersionException, InvalidBagMetadataException, InvalidBagitFileFormatException, MaliciousPathException, UnsupportedAlgorithmException The BagIt specification is very flexible in what it allows which leads to situations where something may be technically allowed, but should be discouraged. This method checks a bag for potential problems, or other items that are allowed but discouraged. This does not validate a bag. SeeBagVerifier
instead.- Parameters:
rootDir
- the root directory of the bagwarningsToIgnore
- anyBagitWarning
to ignore when linting- Returns:
- a set of
BagitWarning
detailing all items that should be fixed. - Throws:
InvalidBagMetadataException
- if the bag metadata does not conform to the bagit specificationUnparsableVersionException
- if there is an error reading the bagit versionIOException
- if there was an error reading a fileUnsupportedAlgorithmException
- if there is an error while reading one of the manifests due to the algorithm being unsupportedMaliciousPathException
- if the path is crafted to be malicious (overwrite non bag files)InvalidBagitFileFormatException
-
checkForExtraLines
private static void checkForExtraLines(Path bagitFile, Collection<BagitWarning> warnings, Collection<BagitWarning> warningsToIgnore) throws InvalidBagMetadataException, IOException, UnparsableVersionException
-