Project

General

Profile

« Previous | Next » 

Revision 10288

Added by Jing Tao over 7 years ago

Move the checking if the checksum exists into the create method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
374 374
        
375 375
    }
376 376
    
377
    if(sysmeta.getChecksum() == null) {
378
        logMetacat.error("D1NodeService.create - the checksum object from the system metadata shouldn't be null for the object "+pid.getValue());
379
        throw new InvalidSystemMetadata("1180", "The checksum object from the system metadata shouldn't be null.");
380
    } 
381
    
377 382

  
378 383
    logMetacat.debug("Checking if identifier exists: " + pid.getValue());
379 384
    // Check that the identifier does not already exist
......
2089 2094

  
2090 2095
    try {
2091 2096
        if (newFile.createNewFile()) {
2092
          if(checksum == null) {
2093
              logMetacat.error("D1NodeService.writeStreamToFile - the checksum object from the system metadata shouldn't be null for the data object "+pid.getValue());
2094
              throw new InvalidSystemMetadata("1180", "The checksum object from the system metadata shouldn't be null.");
2095
          } 
2096
          String checksumValue = checksum.getValue();
2097
          logMetacat.info("D1NodeService.writeStreamToFile - the checksum value from the system metadata is "+checksumValue+" for the data object "+pid.getValue());
2098
          if(checksumValue == null || checksumValue.trim().equals("")) {
2099
              logMetacat.error("D1NodeService.writeStreamToFile - the checksum value from the system metadata shouldn't be null or blank for the data object "+pid.getValue());
2100
              throw new InvalidSystemMetadata("1180", "The checksum value from the system metadata shouldn't be null or blank.");
2101
          }
2102
          String algorithm = checksum.getAlgorithm();
2103
          logMetacat.info("D1NodeService.writeStreamToFile - the algorithm to calculate the checksum from the system metadata is "+algorithm+" for the data object "+pid.getValue());
2104
          if(algorithm == null || algorithm.trim().equals("")) {
2105
              logMetacat.error("D1NodeService.writeStreamToFile - the algorithm to calculate the checksum from the system metadata shouldn't be null or blank for the data object "+pid.getValue());
2106
              throw new InvalidSystemMetadata("1180", "The algorithm to calculate the checksum from the system metadata shouldn't be null or blank.");
2107
          }
2097
            String checksumValue = checksum.getValue();
2098
            logMetacat.info("D1NodeService.writeStreamToFile - the checksum value from the system metadata is "+checksumValue+" for the data object "+pid.getValue());
2099
            if(checksumValue == null || checksumValue.trim().equals("")) {
2100
                logMetacat.error("D1NodeService.writeStreamToFile - the checksum value from the system metadata shouldn't be null or blank for the data object "+pid.getValue());
2101
                throw new InvalidSystemMetadata("1180", "The checksum value from the system metadata shouldn't be null or blank.");
2102
            }
2103
            String algorithm = checksum.getAlgorithm();
2104
            logMetacat.info("D1NodeService.writeStreamToFile - the algorithm to calculate the checksum from the system metadata is "+algorithm+" for the data object "+pid.getValue());
2105
            if(algorithm == null || algorithm.trim().equals("")) {
2106
                logMetacat.error("D1NodeService.writeStreamToFile - the algorithm to calculate the checksum from the system metadata shouldn't be null or blank for the data object "+pid.getValue());
2107
                throw new InvalidSystemMetadata("1180", "The algorithm to calculate the checksum from the system metadata shouldn't be null or blank.");
2108
            }
2108 2109
          MessageDigest md = MessageDigest.getInstance(algorithm);
2109 2110
          // write data stream to desired file
2110 2111
          DigestOutputStream os = new DigestOutputStream( new FileOutputStream(newFile), md);

Also available in: Unified diff