use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagProfileChecker method requiredManifestsExist.
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private static void requiredManifestsExist(final Set<Manifest> manifests, final List<String> requiredManifestTypes, final boolean isPayloadManifest) throws RequiredManifestNotPresentException {
final Set<String> manifestTypesPresent = new HashSet<>();
logger.debug(messages.getString("check_required_manifests_present"));
for (final Manifest manifest : manifests) {
manifestTypesPresent.add(manifest.getAlgorithm().getBagitName());
}
for (final String requiredManifestType : requiredManifestTypes) {
if (!manifestTypesPresent.contains(requiredManifestType)) {
final StringBuilder sb = new StringBuilder();
if (isPayloadManifest) {
sb.append("tag");
sb.append(MessageFormatter.format(messages.getString("required_tag_manifest_type_not_present"), requiredManifestType).getMessage());
} else {
sb.append(MessageFormatter.format(messages.getString("required_manifest_type_not_present"), requiredManifestType).getMessage());
}
throw new RequiredManifestNotPresentException(sb.toString());
}
}
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagCreator method calculatePayloadManifests.
private static Map<Manifest, MessageDigest> calculatePayloadManifests(final Bag bag, final Collection<SupportedAlgorithm> algorithms, final boolean includeHidden) throws NoSuchAlgorithmException, IOException {
final Path dataDir = PathUtils.getDataDir(bag);
logger.info(messages.getString("creating_payload_manifests"));
final Map<Manifest, MessageDigest> payloadFilesMap = Hasher.createManifestToMessageDigestMap(algorithms);
final CreatePayloadManifestsVistor payloadVisitor = new CreatePayloadManifestsVistor(payloadFilesMap, includeHidden);
Files.walkFileTree(dataDir, payloadVisitor);
return payloadFilesMap;
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class Hasher method createManifestToMessageDigestMap.
/**
* create a mapping between {@link Manifest} and {@link MessageDigest} for each each supplied {@link SupportedAlgorithm}
*
* @param algorithms the {@link SupportedAlgorithm} that you which to map to {@link MessageDigest}
* @return mapping between {@link Manifest} and {@link MessageDigest}
* @throws NoSuchAlgorithmException if {@link MessageDigest} doesn't support the algorithm
*/
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public static Map<Manifest, MessageDigest> createManifestToMessageDigestMap(final Collection<SupportedAlgorithm> algorithms) throws NoSuchAlgorithmException {
final Map<Manifest, MessageDigest> map = new HashMap<>();
for (final SupportedAlgorithm algorithm : algorithms) {
final MessageDigest messageDigest = MessageDigest.getInstance(algorithm.getMessageDigestName());
final Manifest manifest = new Manifest(algorithm);
map.put(manifest, messageDigest);
}
return map;
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadBagWithEncodedNames.
@Test
public void testReadBagWithEncodedNames() throws Exception {
Path rootDir = Paths.get(getClass().getClassLoader().getResource("bags/v0_96/bag-with-encoded-names").toURI());
Bag bag = sut.read(rootDir);
assertNotNull(bag);
for (Manifest payloadManifest : bag.getPayLoadManifests()) {
for (Path file : payloadManifest.getFileToChecksumMap().keySet()) {
assertTrue(file + " should exist but it doesn't!", Files.exists(file));
}
}
}
use of gov.loc.repository.bagit.domain.Manifest in project bagit-java by LibraryOfCongress.
the class BagReaderTest method testReadVersion0_97Bag.
@Test
public void testReadVersion0_97Bag() throws Exception {
Path rootBag = Paths.get(new File("src/test/resources/bags/v0_97/bag").toURI());
Path[] payloadFiles = new Path[] { rootBag.resolve("data/dir1/test3.txt"), rootBag.resolve("data/dir2/dir3/test5.txt"), rootBag.resolve("data/dir2/test4.txt"), rootBag.resolve("data/test1.txt"), rootBag.resolve("data/test2.txt") };
Bag returnedBag = sut.read(rootBag);
assertNotNull(returnedBag);
assertEquals(new Version(0, 97), returnedBag.getVersion());
Manifest payloadManifest = (Manifest) returnedBag.getPayLoadManifests().toArray()[0];
for (Path payloadFile : payloadFiles) {
assertTrue(payloadManifest.getFileToChecksumMap().containsKey(payloadFile));
}
}
Aggregations