Skip to content

Commit

Permalink
Fixed #250
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosjepard committed Mar 13, 2024
1 parent aa8ee20 commit 76e274a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/roda_project/commons_ip/model/IP.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public abstract class IP implements IPInterface {
private List<IPFile> documentation;

private Map<String, ZipEntryInfo> zipEntries;
private String checksumAlgorithm;

private ValidationReport validationReport;

Expand All @@ -61,6 +62,7 @@ public IP() {
this.ancestors = new ArrayList<>();

this.description = "";
this.checksumAlgorithm = "SHA-256";

this.descriptiveMetadata = new ArrayList<>();
this.preservationMetadata = new ArrayList<>();
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/roda_project/commons_ip/utils/ZIPUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void zip(Map<String, ZipEntryInfo> files, OutputStream out, SIP si
}

Set<String> nonMetsChecksumAlgorithms = new TreeSet<>();
nonMetsChecksumAlgorithms.add(IPConstants.CHECKSUM_ALGORITHM);
nonMetsChecksumAlgorithms.add(sip.getChecksum());
Set<String> metsChecksumAlgorithms = new TreeSet<>();
metsChecksumAlgorithms.addAll(nonMetsChecksumAlgorithms);
metsChecksumAlgorithms.addAll(sip.getExtraChecksumAlgorithms());
Expand All @@ -126,6 +126,7 @@ public static void zip(Map<String, ZipEntryInfo> files, OutputStream out, SIP si
throw new InterruptedException();
}

file.setChecksum(sip.getChecksum());
file.prepareEntryforZipping();

LOGGER.debug("Zipping file {}", file.getFilePath());
Expand All @@ -150,8 +151,8 @@ public static void zip(Map<String, ZipEntryInfo> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> checksumAlgorithms = new HashSet<>();
checksumAlgorithms.add(checksumType);
try (InputStream inputStream = Files.newInputStream(getFilePath())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ public static void zip(Map<String, ZipEntryInfo> files, OutputStream out, SIP si
throw new InterruptedException();
}

file.setChecksum(sip.getChecksum());
file.prepareEntryforZipping();


LOGGER.debug("Zipping file {}", file.getFilePath());
ZipEntry entry;
if (createSipIdFolder) {
Expand Down

0 comments on commit 76e274a

Please sign in to comment.