@@ -123,7 +123,6 @@ public class BagGenerator {
123123 private PoolingHttpClientConnectionManager cm = null ;
124124
125125 private ChecksumType hashtype = null ;
126- private boolean ignorehashes = false ;
127126
128127 private long dataCount = 0l ;
129128 private long totalDataSize = 0l ;
@@ -158,6 +157,8 @@ public class BagGenerator {
158157 private boolean usingFetchFile = false ;
159158 private boolean createHoleyBag = false ;
160159 private List <FileEntry > oversizedFiles = new ArrayList <>();
160+
161+ private ChecksumType defaultHashtype ;
161162
162163 // Bag-info.txt field labels
163164 private static final String CONTACT_NAME = "Contact-Name: " ;
@@ -244,6 +245,13 @@ public BagGenerator(jakarta.json.JsonObject oremapObject, String dataciteXml, Ma
244245 e .printStackTrace ();
245246 }
246247 initializeHoleyBagLimits ();
248+ try {
249+ // Use the current type if we can retrieve it
250+ defaultHashtype = CDI .current ().select (SystemConfig .class ).get ().getFileFixityChecksumAlgorithm ();
251+ } catch (Exception e ) {
252+ // Default to MD5 if we can't
253+ defaultHashtype = DataFile .ChecksumType .MD5 ;
254+ }
247255 }
248256
249257 private void initializeHoleyBagLimits () {
@@ -255,10 +263,6 @@ private void initializeHoleyBagLimits() {
255263 ", createHoleyBag: " + createHoleyBag );
256264 }
257265
258- public void setIgnoreHashes (boolean val ) {
259- ignorehashes = val ;
260- }
261-
262266 public static void println (String s ) {
263267 System .out .println (s );
264268 System .out .flush ();
@@ -353,13 +357,8 @@ public boolean generateBag(OutputStream outputStream) throws Exception {
353357 sha1StringBuffer .append (sha1Entry .getValue () + " " + path );
354358 }
355359 if (hashtype == null ) { // No files - still want to send an empty manifest to nominally comply with BagIT specification requirement.
356- try {
357- // Use the current type if we can retrieve it
358- hashtype = CDI .current ().select (SystemConfig .class ).get ().getFileFixityChecksumAlgorithm ();
359- } catch (Exception e ) {
360- // Default to MD5 if we can't
361- hashtype = DataFile .ChecksumType .MD5 ;
362- }
360+ // Use the default
361+ hashtype = defaultHashtype ;
363362 }
364363 if (!(hashtype == null )) {
365364 String manifestName = "manifest-" ;
@@ -644,10 +643,6 @@ private void processAllFiles(List<FileEntry> sortedFiles)
644643 // Track titles to detect duplicates
645644 Set <String > titles = new HashSet <>();
646645
647- if ((hashtype == null ) | ignorehashes ) {
648- hashtype = DataFile .ChecksumType .SHA512 ;
649- }
650-
651646 for (FileEntry entry : sortedFiles ) {
652647 // Extract all needed information from the JsonObject reference
653648 JsonObject child = entry .jsonObject ;
@@ -679,12 +674,15 @@ private void processAllFiles(List<FileEntry> sortedFiles)
679674 childHash = child .getAsJsonObject (JsonLDTerm .checksum .getLabel ()).get ("@value" ).getAsString ();
680675 }
681676 }
682-
677+ //Pick a hashtype if we encounter a file that doesn't have one
678+ if (hashtype == null ) {
679+ hashtype = defaultHashtype ;
680+ }
683681 resourceUsed [entry .resourceIndex ] = true ;
684682 String dataUrl = entry .getDataUrl ();
685683
686684 try {
687- if (( childHash == null ) | ignorehashes ) {
685+ if (childHash == null ) {
688686 // Generate missing hash
689687
690688 try (InputStream inputStream = getInputStreamSupplier (dataUrl ).get ()){
0 commit comments