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:

src/edu/ucsb/nceas/metacat/util/ReplicationUtil.java
28 28

  
29 29
/**
30 30
 * A suite of utility classes for the system metadata replication functions
31
 * @deprecated
32 31
 */
33 32
public class ReplicationUtil {
34 33
	  
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
59 59
import edu.ucsb.nceas.metacat.DocumentImpl;
60 60
import edu.ucsb.nceas.metacat.DocumentImplWrapper;
61 61
import edu.ucsb.nceas.metacat.EventLog;
62
import edu.ucsb.nceas.metacat.IdentifierManager;
62 63
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
63 64
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile;
64 65
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
......
70 71
import edu.ucsb.nceas.metacat.properties.PropertyService;
71 72
import edu.ucsb.nceas.metacat.shared.HandlerException;
72 73
import edu.ucsb.nceas.metacat.util.MetacatUtil;
74
import edu.ucsb.nceas.metacat.util.ReplicationUtil;
73 75
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
74 76

  
75 77

  
......
380 382
      logReplication.info("ReplicationHandler.handleSingleXMLDocument - Sending message: " + docinfoUrl.toString());
381 383
      String docInfoStr = ReplicationService.getURLContent(docinfoUrl);
382 384
      
385
      // strip out the system metadata portion
386
      String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
387
   	  docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);
388
      
383 389
      docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
384 390
      Hashtable<String, String> docinfoHash = dih.getDocInfo();
385 391
      // Get home server of the docid
......
443 449
          }
444 450
      }
445 451
      
452
      // process system metadata
453
      if (systemMetadataXML != null) {
454
    	  SystemMetadata sysMeta = 
455
    		  TypeMarshaller.unmarshalTypeFromStream(
456
    				  SystemMetadata.class, 
457
    				  new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
458
    	  // need the guid-to-docid mapping
459
      	  IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), accNumber);
460
      }
461
      
446 462
      logReplication.info("ReplicationHandler.handleSingleXMLDocument - Successfully replicated doc " + accNumber);
447 463
      if (tableName.equals(DocumentImpl.DOCUMENTTABLE))
448 464
      {
......
523 539

  
524 540
      String docInfoStr = ReplicationService.getURLContent(docinfoUrl);
525 541
      
542
      // strip out the system metadata portion
543
      String systemMetadataXML = ReplicationUtil.getSystemMetadataContent(docInfoStr);
544
   	  docInfoStr = ReplicationUtil.getContentWithoutSystemMetadata(docInfoStr);  
545
   	  
526 546
      docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
527 547
      Hashtable<String, String> docinfoHash = dih.getDocInfo();
528 548
      
......
579 599
            }
580 600
        }
581 601
        
602
        // process system metadata
603
        if (systemMetadataXML != null) {
604
      	  SystemMetadata sysMeta = 
605
      		TypeMarshaller.unmarshalTypeFromStream(
606
      				  SystemMetadata.class, 
607
      				  new ByteArrayInputStream(systemMetadataXML.getBytes("UTF-8")));
608
      	  // need the guid-to-docid mapping
609
      	  IdentifierManager.getInstance().createMapping(sysMeta.getIdentifier().getValue(), accNumber);
610
        }
611
        
582 612
        logReplication.info("ReplicationHandler.handleSingleDataFile - Successfully to write datafile " + accNumber);
583 613
        /*MetacatReplication.replLog("wrote datafile " + accNumber + " from " +
584 614
                                    remote server);*/
src/edu/ucsb/nceas/metacat/replication/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