Project

General

Profile

« Previous | Next » 

Revision 7222

use metacat.properties to specify the default checksum algorithm to use -- this way it will be easy for us to switch to whatever DataONE decrees.
https://redmine.dataone.org/issues/2834

View differences:

lib/metacat.properties
524 524
dataone.replicationpolicy.default.preferredNodeList=
525 525
dataone.replicationpolicy.default.blockedNodeList=
526 526

  
527
# Default checksum algorithm
528
dataone.checksumAlgorithm.default=MD5
529

  
527 530
# overall services (TODO: mn vs. cn?)
528 531
dataone.mn.services.enabled=true
529 532
dataone.mn.registration.submitted=false
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
620 620
     */
621 621
    private void checksum(String pid) throws NotImplemented, JiBXException, IOException, InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest {
622 622
    	String checksumAlgorithm = "MD5";
623
    	try {
624
    		checksumAlgorithm = PropertyService.getProperty("dataone.checksumAlgorithm.default");
625
        } catch(Exception e) {
626
        	logMetacat.warn("Could not lookup configured default checksum algorithm, using: " + checksumAlgorithm);
627
        }    
623 628
        
624 629
        Identifier pidid = new Identifier();
625 630
        pidid.setValue(pid);
626 631
        try {
627 632
            checksumAlgorithm = params.get("checksumAlgorithm")[0];
628 633
        } catch(Exception e) {
629
            //do nothing.  default to MD5
634
            //do nothing.  use the default
630 635
        	logMetacat.warn("No algorithm specified, using default: " + checksumAlgorithm);
631 636
        }
632 637
        logMetacat.debug("getting checksum for object " + pid + " with algorithm " + checksumAlgorithm);
src/edu/ucsb/nceas/metacat/util/MetacatPopulator.java
200 200
							System.out.println(e.getMessage());
201 201
						}
202 202
	                    dataDocIs = IOUtils.toInputStream(dataDocText, MetaCatServlet.DEFAULT_ENCODING);
203
	                    Checksum checksum = ChecksumUtil.checksum(dataDocIs, "MD5");
203
	                    String algorithm = PropertyService.getProperty("dataone.checksumAlgorithm.default");
204
	                    Checksum checksum = ChecksumUtil.checksum(dataDocIs, algorithm);
204 205
	                    dataDocSysMeta.setChecksum(checksum);
205 206
	                    String sizeStr = 
206 207
	                    	Long.toString(dataDocText.getBytes(MetaCatServlet.DEFAULT_ENCODING).length);
......
299 300
        
300 301
        //create the checksum
301 302
        ByteArrayInputStream bais = new ByteArrayInputStream(doc.doctext.getBytes(MetaCatServlet.DEFAULT_ENCODING));
302
        Checksum checksum = ChecksumUtil.checksum(bais, "MD5");
303
        String algorithm = PropertyService.getProperty("dataone.checksumAlgorithm.default");
304
        Checksum checksum = ChecksumUtil.checksum(bais, algorithm);
303 305
        sm.setChecksum(checksum);
304 306
        
305 307
        //set the size
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java
197 197
		inputStream = MetacatHandler.read(localId);
198 198

  
199 199
		// create the checksum
200
		String algorithm = "MD5";
200
		String algorithm = PropertyService.getProperty("dataone.checksumAlgorithm.default");
201 201
		Checksum checksum = ChecksumUtil.checksum(inputStream, algorithm);
202 202
		logMetacat.debug("The checksum for " + localId + " is " + checksum.getValue());
203 203
		sysMeta.setChecksum(checksum);
......
528 528
				            SystemMetadata resourceMapSysMeta = new SystemMetadata();
529 529
				            BeanUtils.copyProperties(resourceMapSysMeta, sysMeta);
530 530
				            resourceMapSysMeta.setIdentifier(resourceMapId);
531
				            Checksum oreChecksum = ChecksumUtil.checksum(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), "MD5");
531
				            Checksum oreChecksum = ChecksumUtil.checksum(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), algorithm);
532 532
							resourceMapSysMeta.setChecksum(oreChecksum);
533 533
				            ObjectFormatIdentifier formatId = ObjectFormatCache.getInstance().getFormat("http://www.openarchives.org/ore/terms").getFormatId();
534 534
							resourceMapSysMeta.setFormatId(formatId);

Also available in: Unified diff