Skip to content

Commit 1a7dafa

Browse files
committed
DD-2212 - use configured checksum when no files are present
1 parent cbdc15f commit 1a7dafa

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/main/java/edu/harvard/iq/dataverse/util/bagit/BagGenerator.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@
7575
import edu.harvard.iq.dataverse.pidproviders.PidUtil;
7676
import edu.harvard.iq.dataverse.settings.JvmSettings;
7777
import static edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key.BagGeneratorThreads;
78+
79+
import edu.harvard.iq.dataverse.util.SystemConfig;
7880
import edu.harvard.iq.dataverse.util.json.JsonLDTerm;
81+
import jakarta.enterprise.inject.spi.CDI;
7982

8083
/**
8184
* Creates an archival zipped Bag for long-term storage. It is intended to
@@ -153,7 +156,6 @@ public class BagGenerator {
153156
public BagGenerator(OREMap oreMap, String dataciteXml) throws JsonSyntaxException, Exception {
154157
this.oremap = oreMap;
155158
this.oremapObject = oreMap.getOREMap();
156-
//(JsonObject) new JsonParser().parse(oreMap.getOREMap().toString());
157159
this.dataciteXml = dataciteXml;
158160

159161
try {
@@ -189,10 +191,6 @@ public void setIgnoreHashes(boolean val) {
189191
ignorehashes = val;
190192
}
191193

192-
public void setDefaultCheckSumType(ChecksumType type) {
193-
hashtype=type;
194-
}
195-
196194
public static void println(String s) {
197195
System.out.println(s);
198196
System.out.flush();
@@ -278,6 +276,15 @@ public boolean generateBag(OutputStream outputStream) throws Exception {
278276
String path = sha1Entry.getKey();
279277
sha1StringBuffer.append(sha1Entry.getValue() + " " + path);
280278
}
279+
if(hashtype == null) { // No files - still want to send an empty manifest to nominally comply with BagIT specification requirement.
280+
try {
281+
//Use the current type if we can retrieve it
282+
hashtype = CDI.current().select(SystemConfig.class).get().getFileFixityChecksumAlgorithm();
283+
} catch (Exception e) {
284+
// Default to MD5 if we can't
285+
hashtype=DataFile.ChecksumType.MD5;
286+
}
287+
}
281288
if (!(hashtype == null)) {
282289
String manifestName = "manifest-";
283290
if (hashtype.equals(DataFile.ChecksumType.SHA1)) {

0 commit comments

Comments
 (0)