diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java index 67dfb37..fc6cd66 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansBagMappingServiceImpl.java @@ -58,7 +58,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.security.NoSuchAlgorithmException; import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; @@ -326,13 +325,6 @@ Optional getDatasetContact(DansBagDeposit dansDeposit) { @Override public DansBagDeposit readDansDeposit(Path depositDir) throws InvalidDepositException { - var deposit = dansBagDepositReader.readDeposit(depositDir); - try { - ManifestUtil.ensureSha1ManifestPresent(deposit.getBag()); - return deposit; - } - catch (IOException | NoSuchAlgorithmException e) { - throw new IllegalStateException("Error reading deposit", e); - } + return dansBagDepositReader.readDeposit(depositDir); } } diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/ManifestUtil.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/ManifestUtil.java index 7729b24..53e83fb 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/ManifestUtil.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/ManifestUtil.java @@ -23,7 +23,10 @@ import gov.loc.repository.bagit.hash.StandardSupportedAlgorithms; import gov.loc.repository.bagit.util.PathUtils; import gov.loc.repository.bagit.writer.ManifestWriter; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import javax.validation.constraints.NotNull; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; @@ -37,13 +40,16 @@ import static gov.loc.repository.bagit.hash.StandardSupportedAlgorithms.SHA1; +@Slf4j public class ManifestUtil { public static void ensureSha1ManifestPresent(Bag bag) throws NoSuchAlgorithmException, IOException { + log.debug("Ensure SHA-1 manifest is present in bag {}", bag.getRootDir()); var manifests = bag.getPayLoadManifests(); var algorithms = manifests.stream().map(Manifest::getAlgorithm); if (algorithms.anyMatch(SHA1::equals)) { + log.debug("SHA-1 manifest already present in bag {}", bag.getRootDir()); return; } @@ -54,6 +60,7 @@ public static void ensureSha1ManifestPresent(Bag bag) throws NoSuchAlgorithmExce ManifestWriter.writePayloadManifests(manifests, PathUtils.getBagitDir(bag), bag.getRootDir(), bag.getFileEncoding()); updateTagManifests(bag); + log.debug("SHA-1 manifest added to bag {}", bag.getRootDir()); } private static void updateTagManifests(Bag bag) throws NoSuchAlgorithmException, IOException { @@ -65,7 +72,7 @@ private static void updateTagManifests(Bag bag) throws NoSuchAlgorithmException, var tagVisitor = new CreateTagManifestsVistor(tagFilesMap, true) { @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { + public @NotNull FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attrs) throws IOException { /* * Fix for EASY-1306: a tag manifest must not contain an entry for itself, as this is practically * impossible to calculate. It could in theory contain entries for other tag manifests. However, diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/deposit/DansBagDepositReaderImpl.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/deposit/DansBagDepositReaderImpl.java index ab764f9..93d9210 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/deposit/DansBagDepositReaderImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/deposit/DansBagDepositReaderImpl.java @@ -61,6 +61,7 @@ public DansBagDeposit readDeposit(Path depositDir) throws InvalidDepositExceptio var depositProperties = readDepositProperties(depositDir); var bag = bagReader.read(bagDir); + ManifestUtil.ensureSha1ManifestPresent(bag); var deposit = mapToDeposit(bag, depositProperties);