Project

General

Profile

« Previous | Next » 

Revision 10321

Added by Jing Tao over 7 years ago

Fixed a bug that the eml object wasn't changed checksum but its content was modified in the publish method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
1995 1995
		boolean isScienceMetadata = isScienceMetadata(sysmeta);
1996 1996
		//If it's a science metadata doc, we want to update the packageId first
1997 1997
		if(isScienceMetadata){
1998
		    boolean isEML = false;
1999
		    //Get the formatId
2000
            ObjectFormatIdentifier objFormatId = originalSystemMetadata.getFormatId();
2001
            String formatId = objFormatId.getValue();
2002
            //For all EML formats
2003
            if(formatId.indexOf("eml") == 0){
2004
                logMetacat.debug("~~~~~~~~~~~~~~~~~~~~~~MNodeService.publish - the object "+originalIdentifier.getValue()+" with format id "+formatId+" is an eml document.");
2005
                isEML = true;
2006
            }
1998 2007
			InputStream originalObject = this.get(session, originalIdentifier);
1999 2008
			
2000 2009
			//Edit the science metadata with the new package Id (EML)
2001
			inputStream = editScienceMetadata(session, originalObject, originalIdentifier, newIdentifier);
2010
			inputStream = editScienceMetadata(session, originalObject, originalIdentifier, newIdentifier, isEML, sysmeta);
2002 2011
		}
2003 2012
		else{
2004 2013
			inputStream = this.get(session, originalIdentifier);
......
2173 2182
	   * @throws NotFound
2174 2183
	   * @throws NotImplemented
2175 2184
	   */
2176
	  public InputStream editScienceMetadata(Session session, InputStream object, Identifier pid, Identifier newPid)
2185
	  public InputStream editScienceMetadata(Session session, InputStream object, Identifier pid, Identifier newPid, boolean isEML, SystemMetadata newSysmeta)
2177 2186
	  	throws ServiceFailure, IOException, UnsupportedEncodingException, InvalidToken, NotAuthorized, NotFound, NotImplemented {
2178 2187
	    
2179 2188
		logMetacat.debug("D1NodeService.editScienceMetadata() called.");
......
2188 2197
	    	Document doc = XMLUtilities.getXMLReaderAsDOMDocument(new StringReader(xmlStr));
2189 2198
		    org.w3c.dom.Node docNode = doc.getDocumentElement();
2190 2199

  
2191
		    //Get the system metadata for this object
2192
		    SystemMetadata sysMeta = null;
2193
		    try{
2194
		    	sysMeta = getSystemMetadata(session, pid);
2195
		    } catch(NotAuthorized e){
2196
		    	throw new ServiceFailure("1030", "D1NodeService.editScienceMetadata(): " + 
2197
		    			"This session is not authorized to access the system metadata for " +
2198
		    			pid.getValue() + " : " + e.getMessage());
2199
		    } catch(NotFound e){
2200
		    	throw new ServiceFailure("1030", "D1NodeService.editScienceMetadata(): " + 
2201
		    			"Could not find the system metadata for " +
2202
		    			pid.getValue() + " : " + e.getMessage());
2203
		    }
2204
		    
2205
		    //Get the formatId
2206
	        ObjectFormatIdentifier objFormatId = sysMeta.getFormatId();
2207
	        String formatId = objFormatId.getValue();
2208
	        
2209 2200
	    	//For all EML formats
2210
	        if(formatId.indexOf("eml") == 0){
2201
	        if(isEML){
2211 2202
	        	//Update or add the id attribute
2212 2203
	    	    XMLUtilities.addAttributeNodeToDOMTree(docNode, XPATH_EML_ID, newPid.getValue());
2213 2204
	        }
......
2217 2208
		    Source xmlSource = new DOMSource(docNode);
2218 2209
		    Result outputTarget = new StreamResult(outputStream);
2219 2210
		    TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
2220
		    newObject = new ByteArrayInputStream(outputStream.toByteArray());
2221
		    
2211
		    byte[] output = outputStream.toByteArray();
2212
		    Checksum checksum = ChecksumUtil.checksum(output, newSysmeta.getChecksum().getAlgorithm());
2213
		    newObject = new ByteArrayInputStream(output);
2214
		    newSysmeta.setChecksum(checksum);
2215
		    logMetacat.debug("MNNodeService.editScienceMetadata - the new checksum is "+checksum.getValue() +" with algorithm "+checksum.getAlgorithm()+" for the new pid "+newPid.getValue()+" which is published from the pid "+pid.getValue());
2222 2216
	    } catch(TransformerException e) {
2223 2217
	    	throw new ServiceFailure("1030", "MNNodeService.editScienceMetadata(): " +
2224 2218
	                "Could not update the ID in the XML document for " +
......
2227 2221
	    	throw new ServiceFailure("1030", "MNNodeService.editScienceMetadata(): " +
2228 2222
	                "Could not update the ID in the XML document for " +
2229 2223
	                "pid " + pid.getValue() +" : " + e.getMessage());
2224
	    } catch(NoSuchAlgorithmException e) {
2225
	        throw new ServiceFailure("1030", "MNNodeService.editScienceMetadata(): " +
2226
                    "Could not update the ID in the XML document for " +
2227
                    "pid " + pid.getValue() +" since the checksum can't be computed : " + e.getMessage());
2230 2228
	    }
2231 2229
	    
2232 2230
	    return newObject;

Also available in: Unified diff