From 76e274a9b1aae2f0ecd34040bd776971c356acbf Mon Sep 17 00:00:00 2001 From: carlosjepard Date: Wed, 13 Mar 2024 15:08:26 +0000 Subject: [PATCH] Fixed #250 --- src/main/java/org/roda_project/commons_ip/model/IP.java | 9 +++++++++ .../java/org/roda_project/commons_ip/utils/ZIPUtils.java | 7 ++++--- .../roda_project/commons_ip2/utils/METSZipEntryInfo.java | 2 +- .../org/roda_project/commons_ip2/utils/ZIPUtils.java | 2 ++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/roda_project/commons_ip/model/IP.java b/src/main/java/org/roda_project/commons_ip/model/IP.java index e67e417e..e2bad35a 100644 --- a/src/main/java/org/roda_project/commons_ip/model/IP.java +++ b/src/main/java/org/roda_project/commons_ip/model/IP.java @@ -48,6 +48,7 @@ public abstract class IP implements IPInterface { private List documentation; private Map zipEntries; + private String checksumAlgorithm; private ValidationReport validationReport; @@ -61,6 +62,7 @@ public IP() { this.ancestors = new ArrayList<>(); this.description = ""; + this.checksumAlgorithm = "SHA-256"; this.descriptiveMetadata = new ArrayList<>(); this.preservationMetadata = new ArrayList<>(); @@ -92,6 +94,13 @@ public IP setId(String id) { this.ids = Arrays.asList(id); return this; } + public void setChecksum(final String checksum) { + this.checksumAlgorithm = checksum; + } + public String getChecksum() { + return this.checksumAlgorithm; + } + @Override public String getId() { diff --git a/src/main/java/org/roda_project/commons_ip/utils/ZIPUtils.java b/src/main/java/org/roda_project/commons_ip/utils/ZIPUtils.java index 62d6ee95..c80347cb 100644 --- a/src/main/java/org/roda_project/commons_ip/utils/ZIPUtils.java +++ b/src/main/java/org/roda_project/commons_ip/utils/ZIPUtils.java @@ -115,7 +115,7 @@ public static void zip(Map files, OutputStream out, SIP si } Set nonMetsChecksumAlgorithms = new TreeSet<>(); - nonMetsChecksumAlgorithms.add(IPConstants.CHECKSUM_ALGORITHM); + nonMetsChecksumAlgorithms.add(sip.getChecksum()); Set metsChecksumAlgorithms = new TreeSet<>(); metsChecksumAlgorithms.addAll(nonMetsChecksumAlgorithms); metsChecksumAlgorithms.addAll(sip.getExtraChecksumAlgorithms()); @@ -126,6 +126,7 @@ public static void zip(Map files, OutputStream out, SIP si throw new InterruptedException(); } + file.setChecksum(sip.getChecksum()); file.prepareEntryforZipping(); LOGGER.debug("Zipping file {}", file.getFilePath()); @@ -150,8 +151,8 @@ public static void zip(Map files, OutputStream out, SIP si } LOGGER.debug("Done zipping file"); - String checksum = checksums.get(IPConstants.CHECKSUM_ALGORITHM); - String checksumType = IPConstants.CHECKSUM_ALGORITHM; + String checksum = checksums.get(sip.getChecksum()); + String checksumType = sip.getChecksum(); file.setChecksum(checksum); file.setChecksumAlgorithm(checksumType); if (file instanceof METSFileTypeZipEntryInfo) { diff --git a/src/main/java/org/roda_project/commons_ip2/utils/METSZipEntryInfo.java b/src/main/java/org/roda_project/commons_ip2/utils/METSZipEntryInfo.java index 22216262..7564c65f 100644 --- a/src/main/java/org/roda_project/commons_ip2/utils/METSZipEntryInfo.java +++ b/src/main/java/org/roda_project/commons_ip2/utils/METSZipEntryInfo.java @@ -69,7 +69,7 @@ public void prepareEntryforZipping() throws IPException { if (!rootMETS && fileType != null) { METSUtils.setFileBasicInformation(LOGGER, getFilePath(), fileType); - String checksumType = IPConstants.CHECKSUM_ALGORITHM; + String checksumType = this.getChecksum(); Set checksumAlgorithms = new HashSet<>(); checksumAlgorithms.add(checksumType); try (InputStream inputStream = Files.newInputStream(getFilePath())) { diff --git a/src/main/java/org/roda_project/commons_ip2/utils/ZIPUtils.java b/src/main/java/org/roda_project/commons_ip2/utils/ZIPUtils.java index 69f1b2ea..92a56bc0 100644 --- a/src/main/java/org/roda_project/commons_ip2/utils/ZIPUtils.java +++ b/src/main/java/org/roda_project/commons_ip2/utils/ZIPUtils.java @@ -128,8 +128,10 @@ public static void zip(Map files, OutputStream out, SIP si throw new InterruptedException(); } + file.setChecksum(sip.getChecksum()); file.prepareEntryforZipping(); + LOGGER.debug("Zipping file {}", file.getFilePath()); ZipEntry entry; if (createSipIdFolder) {