Project

General

Profile

« Previous | Next » 

Revision 6531

include SystemMetadata when replicating data and metadata documents -- this allows us to establish the guid-to-docid mapping that is crucial for being able to read the replicated document by guid (d1 api)

View differences:

ReplicationService.java
84 84
import edu.ucsb.nceas.metacat.shared.ServiceException;
85 85
import edu.ucsb.nceas.metacat.util.DocumentUtil;
86 86
import edu.ucsb.nceas.metacat.util.MetacatUtil;
87
import edu.ucsb.nceas.metacat.util.ReplicationUtil;
87 88
import edu.ucsb.nceas.metacat.util.SystemUtil;
88 89
import edu.ucsb.nceas.utilities.FileUtil;
89 90
import edu.ucsb.nceas.utilities.GeneralPropertyException;
......
568 569
			
569 570

  
570 571
			String docInfoStr = ReplicationService.getURLContent(docinfourl);
571

  
572
			// strip out the system metadata portion
573
			String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
574
			docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);
575
		   	  
572 576
			//dih is the parser for the docinfo xml format
573 577
			DocInfoHandler dih = new DocInfoHandler();
574 578
			XMLReader docinfoParser = ReplicationHandler.initParser(dih);
......
578 582
			
579 583
			// Get home server of this docid
580 584
			String homeServer = (String) docinfoHash.get("home_server");
585
			
586
			// process system metadata
587
			if (systemMetadataXML != null) {
588
				SystemMetadata sysMeta = 
589
					TypeMarshaller.unmarshalTypeFromStream(
590
							SystemMetadata.class,
591
							new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
592
				// need the guid-to-docid mapping
593
				IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), docid);
594
			}
581 595
      
582 596
        	// replicate doc contents
583 597
			String createdDate = (String) docinfoHash.get("date_created");
......
774 788

  
775 789
			String docInfoStr = ReplicationService.getURLContent(docinfourl);
776 790
			
791
			// strip out the system metadata portion
792
		    String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
793
		   	docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);
794

  
777 795
			//dih is the parser for the docinfo xml format
778 796
			DocInfoHandler dih = new DocInfoHandler();
779 797
			XMLReader docinfoParser = ReplicationHandler.initParser(dih);
......
832 850
		        		}
833 851
		            }
834 852
		        }
853
		        
854
		        // process system metadata
855
		        if (systemMetadataXML != null) {
856
		      	  SystemMetadata sysMeta = 
857
		      		TypeMarshaller.unmarshalTypeFromStream(
858
		      				  SystemMetadata.class, 
859
		      				  new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
860
		      	  // need the guid-to-docid mapping
861
		      	  IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), docid);
862
		        }
835 863

  
836 864
				if (writeException != null) {
837 865
					throw writeException;
......
922 950
			DocumentImpl doc = new DocumentImpl(docid);
923 951
			sb.append("<documentinfo><docid>").append(docid);
924 952
			sb.append("</docid>");
953
			
954
			try {
955
				// serialize the System Metadata as XML for docinfo
956
				String guid = IdentifierManager.getInstance().getGUID(doc.getDocID(), doc.getRev());
957
				SystemMetadata systemMetadata = IdentifierManager.getInstance().getSystemMetadata(guid);
958
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
959
				TypeMarshaller.marshalTypeToOutputStream(systemMetadata, baos);
960
				String systemMetadataXML = baos.toString("UTF-8");
961
				sb.append("<systemMetadata>");
962
				sb.append(systemMetadataXML);
963
				sb.append("</systemMetadata>");
964
			} catch(McdbDocNotFoundException e) {
965
			  logMetacat.warn("No SystemMetadata found for: " + docid);
966
			}
925 967
			sb.append("<docname>").append(doc.getDocname());
926 968
			sb.append("</docname><doctype>").append(doc.getDoctype());
927 969
			sb.append("</doctype>");

Also available in: Unified diff