Project

General

Profile

« Previous | Next » 

Revision 6099

-remove system metadata guid -> local id mapping (there is no document for system metadata now)
-include system metadata elements when replicating data objects (TODO: transfer all system metadata structures with the docinfo request).
TODO: remove docid+rev from the systemMetadata table definition

View differences:

test/edu/ucsb/nceas/metacattest/IdentifierManagerTest.java
207 207
        }
208 208
    }
209 209
    
210
    /**
211
     * test createSystemMetadataMapping and getSystemMetadataId
212
     */
213
    public void testCreateSystemMetadataMapping()
214
    {
215
        ph("testCreateSystemMetadataMapping");
216
        try
217
        {
218
            IdentifierManager im = IdentifierManager.getInstance();
219
            String docid = "test." + new Date().getTime() + ".1";
220
            String guid = "guid:" + docid;
221
            im.createSystemMetadataMapping(guid, docid);
222
            String docid2 = im.getSystemMetadataLocalId(guid);
223
            assertTrue(docid2.equals(docid));
224
        } catch (McdbDocNotFoundException e) {
225
          e.printStackTrace();
226
          fail("createSystemMetadataMapping failed to create proper localId from guid: " + e.getMessage());
227
        }
228
    }
229 210
    
230 211
    /**
231 212
     * test the local id creation
src/edu/ucsb/nceas/metacat/MetacatHandler.java
1866 1866
                  // handle updates
1867 1867
                  identifier.setValue(im.getGUID(newdocid, rev));
1868 1868
                  sysMeta = getSystemMetadata(identifier);
1869
                  IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sysMeta);
1869
                  IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
1870 1870
                  
1871 1871
                } catch ( McdbDocNotFoundException mnfe) {
1872 1872
                  
1873 1873
                  // handle inserts
1874 1874
                  try {
1875 1875
                    sysMeta = createSystemMetadata(newdocid, user, groups);
1876
                    IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sysMeta);
1876
                    IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
1877 1877
                    
1878 1878
                  } catch ( McdbDocNotFoundException dnfe ) {
1879 1879
                    logMetacat.debug(
......
3666 3666
                    f = ObjectFormat.OCTET_STREAM;
3667 3667
                }
3668 3668
                dataSysMeta.setObjectFormat(f);
3669
                IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(dataSysMeta);
3669
                IdentifierManager.getInstance().updateSystemMetadata(dataSysMeta);
3670 3670
                
3671 3671
              } catch ( McdbDocNotFoundException nf ) {
3672 3672
                // System metadata for data doesn't exist
......
3692 3692
                  
3693 3693
                  logMetacat.debug("Updating system metadata for " + 
3694 3694
                    dataDocId.getValue() + " to " + dataDocMimeType);
3695
                  IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(dataSysMeta);
3695
                  IdentifierManager.getInstance().updateSystemMetadata(dataSysMeta);
3696 3696
                  
3697 3697
                } catch ( McdbDocNotFoundException mdnf) {
3698 3698
                  mdnf.printStackTrace();
......
3805 3805
      SystemMetadata sysMeta = null;
3806 3806
      
3807 3807
      try {
3808
        String localId = IdentifierManager.getInstance().getSystemMetadataLocalId(guid.getValue());        
3809
        sysMeta = IdentifierManager.getInstance().getSystemMetadata(localId);
3808
        sysMeta = IdentifierManager.getInstance().getSystemMetadata(guid.getValue());
3810 3809
      } catch ( McdbDocNotFoundException dnfe ) {
3811 3810
        logMetacat.debug("There was a problem getting the system " +
3812
        "metadata local id. The error was: " + dnfe.getMessage());
3811
        "metadata. The error was: " + dnfe.getMessage());
3813 3812
        throw dnfe;
3814 3813
      }
3815 3814
      return sysMeta;
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataManager.java
3 3
 */
4 4
package edu.ucsb.nceas.metacat.dataone;
5 5

  
6
import org.dataone.service.types.SystemMetadata;
7

  
6 8
import edu.ucsb.nceas.metacat.IdentifierManager;
7 9
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
8 10

  
......
49 51
        boolean hassm = false;
50 52
        try
51 53
        {
52
            String smid = idManager.getSystemMetadataLocalId(guid);
53
            if(smid != null && !smid.trim().equals(""))
54
            SystemMetadata sm = idManager.getSystemMetadata(guid);
55
            if(sm != null && !sm.getIdentifier().getValue().equals(""))
54 56
            {
55 57
                hassm = true;
56 58
            }
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
478 478
                    permissionType + " on doc with localid " + docid);
479 479
            handler.setAccess(metacatUrl, sessionData.getUserName(), docid, 
480 480
                    principal, permNum, permissionType, permissionOrder);
481
            if(setSystemMetadata)
482
            {
483
                //set the same perms on the system metadata doc
484
                String smlocalid = im.getSystemMetadataLocalId(id.getValue());
485
                logCrud.debug("setting access on SM doc with localid " + smlocalid);
486
                //cs.setAccess(token, smid, principal, permission, permissionType, permissionOrder);
487
                handler.setAccess(metacatUrl, sessionData.getUserName(), smlocalid,
488
                        principal, permNum, permissionType, permissionOrder);
489
            }
481
            
490 482
            String username = "public";
491 483
            if(sessionData != null)
492 484
            {
......
1216 1208
        
1217 1209
    	logMetacat.debug("CrudService.getSystemMetadata - for guid: " + guid.getValue());
1218 1210
        
1219
        IdentifierManager im = IdentifierManager.getInstance();
1220
        String localId = null;
1221 1211
        SystemMetadata sysmeta = null;
1222 1212
		try {
1223
			localId = im.getSystemMetadataLocalId(guid.getValue());
1224 1213
	        // look up the SysMeta
1225
	        sysmeta = im.getSystemMetadata(localId);
1214
	        sysmeta = IdentifierManager.getInstance().getSystemMetadata(guid.getValue());
1226 1215
		} catch (McdbDocNotFoundException e) {
1227 1216
			e.printStackTrace();
1228
			throw new NotFound(null, "Could not locate SystemMetadata for localId: " + localId);
1217
			throw new NotFound(null, "Could not locate SystemMetadata for: " + guid.getValue());
1229 1218
		}        
1230 1219

  
1231
		logCrud.info("getsystemmetadata D1GUID:" + guid.getValue()  + ":D1SYSMETADATA:"+ localId + ":");
1220
		logCrud.info("getsystemmetadata D1GUID:" + guid.getValue());;
1232 1221
        
1233 1222
        return sysmeta;
1234 1223
                   
......
1483 1472
        throws ServiceFailure 
1484 1473
    {
1485 1474
        logMetacat.debug("Starting to insert SystemMetadata...");
1486
    
1487
        // generate guid/localId pair for sysmeta
1488
        Identifier sysMetaGuid = new Identifier();
1489
        sysMetaGuid.setValue(DocumentUtil.generateDocumentId(1));
1490 1475
        sysmeta.setDateSysMetadataModified(new Date());
1491 1476
        logCrud.debug("****inserting new system metadata with modified date " + 
1492 1477
                sysmeta.getDateSysMetadataModified());
1493 1478

  
1494
        //insert the system metadata doc id into the systemmetadata table to 
1495
        //link it to the data or metadata document
1496
        IdentifierManager.getInstance().createSystemMetadataMapping(
1497
                sysmeta, sysMetaGuid.getValue());
1479
        //insert the system metadata
1480
        IdentifierManager.getInstance().createSystemMetadata(sysmeta);
1481
        IdentifierManager.getInstance().updateSystemMetadata(sysmeta);
1498 1482
        
1499
        IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sysmeta);
1500
        
1501 1483
    }
1502 1484
    
1503 1485
    /**
......
1512 1494
        {
1513 1495
            logCrud.debug("Setting date modified to " + new Date());
1514 1496
            sm.setDateSysMetadataModified(new Date());
1515

  
1516
            IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sm);
1517
                        
1497
            IdentifierManager.getInstance().updateSystemMetadata(sm);
1518 1498
        }
1519 1499
        catch(Exception e)
1520 1500
        {
......
1602 1582
            try
1603 1583
            {
1604 1584
                logCrud.debug("updating guid " + guid.getValue());
1605
                if(!isSystemMetadata)
1606
                {
1607
                    logCrud.debug("looking in identifier table for guid " + guid.getValue());
1608
                    localId = im.getLocalId(guid.getValue());
1609
                }
1610
                else
1611
                {
1612
                    logCrud.debug("looking in systemmetadata table for guid " + guid.getValue());
1613
                    localId = im.getSystemMetadataLocalId(guid.getValue());
1614
                }
1585
                logCrud.debug("looking in identifier table for guid " + guid.getValue());
1586
                
1587
                localId = im.getLocalId(guid.getValue());
1588
                
1615 1589
                logCrud.debug("localId: " + localId);
1616 1590
                //increment the revision
1617 1591
                String docid = localId.substring(0, localId.lastIndexOf("."));
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadata.java
176 176
        	throw sf;
177 177
        }
178 178
        
179
        //insert the systemmetadata object
180
        String guid = null;
181
        try {
182
        	IdentifierManager.getInstance().getLocalId(sm.getIdentifier().getValue());
183
        } catch (Exception e) {
184
			guid = null;
185
		}
186
        if (guid == null) {
187
        	IdentifierManager.getInstance().createSystemMetadataMapping(sm, localId);
179
        //insert the systemmetadata object or just update it
180
        boolean exists = IdentifierManager.getInstance().identifierExists(sm.getIdentifier().getValue());
181
        if (!exists) {
182
        	IdentifierManager.getInstance().createSystemMetadata(sm);
188 183
        }
189
        IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sm);
184
        IdentifierManager.getInstance().updateSystemMetadata(sm);
190 185

  
191 186
        log.info("generateMissingSystemMetadata(token, localId)");
192 187
    }
src/edu/ucsb/nceas/metacat/IdentifierManager.java
45 45
import edu.ucsb.nceas.metacat.database.DBConnection;
46 46
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
47 47
import edu.ucsb.nceas.metacat.properties.PropertyService;
48
import edu.ucsb.nceas.metacat.shared.ServiceException;
49 48
import edu.ucsb.nceas.metacat.util.DocumentUtil;
50
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
51 49

  
52 50
/**
53 51
 * Manage the relationship between Metacat local identifiers (LocalIDs) that are
54
 * codified as the (docid, rev) pair with globally uniqe string identifiers
52
 * codified as the (docid, rev) pair with globally unique string identifiers
55 53
 * (GUIDs) that are opaque strings.  This class provides methods to manage these
56 54
 * identifiers, and to search for and look up LocalIDs based on their GUID and
57 55
 * vice versa. IdentifierManager is a singleton.
......
62 60
    
63 61
    public static final String TYPE_SYSTEM_METADATA = "systemmetadata";
64 62
    public static final String TYPE_IDENTIFIER = "identifier";
65
    public static String DATAONE_SM_DOCTYPE;
66 63
  
67 64
    /**
68 65
     * The single instance of the manager that is always returned.
69 66
     */
70 67
    private static IdentifierManager self = null;
71
    private Logger logMetacat = Logger.getLogger(EventLog.class);
68
    private Logger logMetacat = Logger.getLogger(IdentifierManager.class);
72 69

  
73 70
    /**
74 71
     * A private constructor that initializes the class when getInstance() is
75 72
     * called.
76 73
     */
77
    private IdentifierManager()
78
    {
79
        try
80
        {
81
            DATAONE_SM_DOCTYPE = PropertyService.getProperty("crudService.listObjects.ReturnDoctype");
82
        }
83
        catch(Exception e)
84
        {
85
            throw new RuntimeException("Error getting System Metadata doctype from " + 
86
                    "the properties file.  Please make sure crudService.listObjects.ReturnDoctype " +
87
                    "exists in metacat.properties.");
88
        }
89
    }
74
    private IdentifierManager() {}
90 75

  
91 76
    /**
92 77
     * Return the single instance of the manager after initializing it if it
......
220 205
    
221 206
    /**
222 207
     * return a hash of all of the info that is in the systemmetadata table
223
     * @param localId
208
     * @param guid
224 209
     * @return
225 210
     */
226
    public SystemMetadata getSystemMetadata(String localId)
211
    public SystemMetadata getSystemMetadata(String guid)
227 212
    	throws McdbDocNotFoundException
228 213
    {
229
        try
230
        {
231
            AccessionNumber acc = new AccessionNumber(localId, "NONE");
232
            localId = acc.getDocid();
233
        }
234
        catch(Exception e)
235
        {
236
            //do nothing. just try the localId as it is
237
        }
214
        
238 215
        SystemMetadata sysMeta = new SystemMetadata();
239 216
        String sql = "select guid, date_uploaded, rights_holder, checksum, checksum_algorithm, " +
240 217
          "origin_member_node, authoritive_member_node, date_modified, submitter, object_format, size " +
241
          "from systemmetadata where docid = ?";
218
          "from systemmetadata where guid = ?";
242 219
        DBConnection dbConn = null;
243 220
        int serialNumber = -1;
244 221
        try 
......
249 226

  
250 227
            // Execute the statement
251 228
            PreparedStatement stmt = dbConn.prepareStatement(sql);
252
            stmt.setString(1, localId);
229
            stmt.setString(1, guid);
253 230
            ResultSet rs = stmt.executeQuery();
254 231
            if (rs.next()) 
255 232
            {
256
                String guid = rs.getString(1);
257 233
                Timestamp dateUploaded = rs.getTimestamp(2);
258 234
                String rightsHolder = rs.getString(3);
259 235
                String checksum = rs.getString(4);
......
295 271
            {
296 272
                stmt.close();
297 273
                DBConnectionPool.returnDBConnection(dbConn, serialNumber);
298
                throw new McdbDocNotFoundException("Could not find " + localId);
274
                throw new McdbDocNotFoundException("Could not find " + guid);
299 275
            }
300 276
            
301 277
        } 
302 278
        catch (SQLException e) 
303 279
        {
304 280
            e.printStackTrace();
305
            logMetacat.error("Error while getting system metadata for localid " + localId + " : "  
281
            logMetacat.error("Error while getting system metadata for guid " + guid + " : "  
306 282
                    + e.getMessage());
307 283
        } 
308 284
        finally 
......
430 406
            
431 407
            String sql2 = "select principal_name, permission, perm_type, perm_order from xml_access " +
432 408
            "where docid like '" + localId + "'";
433
            System.out.println("executing sql: " + sql2);
409
            logMetacat.debug("executing sql: " + sql2);
434 410
            PreparedStatement stmt2 = dbConn.prepareStatement(sql2);
435 411
            rs = stmt2.executeQuery();
436 412
            Vector accessVector = new Vector();
......
445 421
                accessHash.put("permission", permission);
446 422
                accessHash.put("permission_type", permissionType);
447 423
                accessHash.put("permission_order", permissionOrder);
448
                System.out.println("accessHash: " + accessHash.toString());
424
                logMetacat.debug("accessHash: " + accessHash.toString());
449 425
                accessVector.add(accessHash);
450 426
            }
451 427
            h.put("access", accessVector);
......
521 497
    
522 498
    /**
523 499
     * return all local ids in the object store that do not have associated
524
     * system metadata and are not themselves system metadata
500
     * system metadata
525 501
     */
526 502
    public List<String> getLocalIdsWithNoSystemMetadata()
527 503
    {
528 504
        Vector<String> ids = new Vector<String>();
529
        //String sql = "select docid from identifier where guid in (select guid from systemmetadata)"; 
530
        //String sql = "select docid from xml_documents where docid not " +
531
        //    "in (select docid from identifier where guid in (select guid from systemmetadata)) " +
532
        //    "and doctype not like '" + DATAONE_SM_DOCTYPE + "'";
533
        String sql = "select docid, rev from xml_documents where docid not in " +
534
            "(select docid from systemmetadata) and (docid not in " +
535
            "(select docid from identifier where guid in (select guid from systemmetadata)))";
505
        String sql = "select docid, rev from xml_documents " +
506
        		"where docid not in " +
507
        		"(select docid from identifier where guid in (select guid from systemmetadata)))";
536 508
        DBConnection dbConn = null;
537 509
        int serialNumber = -1;
538 510
        try 
......
549 521
                String localid = rs.getString(1);
550 522
                String rev = rs.getString(2);
551 523
                localid += "." + rev;
552
                System.out.println("id to add SM for: " + localid);
524
                logMetacat.debug("id to add SM for: " + localid);
553 525
                ids.add(localid);
554 526
            } 
555 527
            stmt.close();
......
608 580
        return ids;
609 581
    }
610 582
    
611
    /**
612
     * Lookup a GUID from the database, and return the associated LocalID. If
613
     * the identifier is not found, throw an exception.
614
     * 
615
     * @param guid the global identifier to look up
616
     * @return String containing the corresponding LocalId
617
     * @throws McdbDocNotFoundException if the identifier is not found
618
     */
619
    public String getLocalId(String guid) throws McdbDocNotFoundException
620
    {
621
        return this.getLocalId(guid, TYPE_IDENTIFIER);
622
    }
583

  
623 584
    
624 585
    /**
625 586
     * Determine if an identifier exists already, returning true if so.
......
642 603
    }
643 604
    
644 605
    /**
645
     * Create a mapping between two identifiers, one representing an 
646
     * unconstrained, globally unique string (guid), and one a localId 
647
     * in the Metacat docid format (scope.id.revision). 
648
     * This mapping allows one to find the global id (guid) from the localId.
649 606
     * 
650
     * @param guid the global string identifier to be mapped
651
     * @param localId the local identifier to be mapped
652
     */
653
    public void createMapping(String guid, String localId)
654
    {   
655
        createGenericMapping(guid, localId, TYPE_IDENTIFIER);
656
    }
657
    
658
    /**
659
     * 
660 607
     * @param guid
661 608
     * @param rev
662 609
     * @return
......
706 653
        }
707 654
        
708 655
        // Register this new pair in the identifier mapping table
709
        System.out.println("creating mapping in generateLocalId");
656
        logMetacat.debug("creating mapping in generateLocalId");
710 657
        if(!isSystemMetadata)
711 658
        { //don't do this if we're generating for system metadata
712 659
            createMapping(guid, localId);
......
727 674
    public String getGUID(String docid, int rev)
728 675
      throws McdbDocNotFoundException
729 676
    {
730
        System.out.println("getting guid for " + docid);
677
        logMetacat.debug("getting guid for " + docid);
731 678
        String query = "select guid from identifier where docid = ? and rev = ?";
732 679
        String guid = null;
733
        boolean found = false;
734 680
        
735 681
        DBConnection dbConn = null;
736 682
        int serialNumber = -1;
......
777 723
    }
778 724
    
779 725
    /**
780
     * creates a mapping for a system metadata document, but DOES NOT add any
781
     * of the extra system metadata information to the table.  You must call 
782
     * insertAdditionalSystemMetadataFields to complete the entry
783
     * 
784
     * @param guid the id to insert
785
     * @param localId the systemMetadata object to get the local id for
786
     */
787
    public void createSystemMetadataMapping(String guid, String localId)
788
    {
789
        createGenericMapping(guid, localId, TYPE_SYSTEM_METADATA);
790
    }
791
    
792
    /**
793 726
     * creates a system metadata mapping and adds additional fields from sysmeta
794 727
     * to the table for quick searching.
795 728
     * 
796 729
     * @param guid the id to insert
797 730
     * @param localId the systemMetadata object to get the local id for
798 731
     */
799
    public void createSystemMetadataMapping(SystemMetadata sysmeta, String localId)
732
    public void createSystemMetadata(SystemMetadata sysmeta)
800 733
    {
801
        createGenericMapping(sysmeta.getIdentifier().getValue(), localId, TYPE_SYSTEM_METADATA);
802
        insertAdditionalSystemMetadataFields(sysmeta);
734
        insertSystemMetadata(sysmeta.getIdentifier().getValue());
735
        updateSystemMetadata(sysmeta);
803 736
    }
737
        
804 738
    
805 739
    /**
806
     * update a system metadata mapping
807
     * @param guid
808
     * @param localId
809
     */
810
    public void updateSystemMetadataMapping(String guid, String localId)
811
    {
812
    	updateMapping(guid, localId, TYPE_SYSTEM_METADATA);
813
    }
814
    
815
    /**
816 740
     * update a mapping
817 741
     * @param guid
818 742
     * @param localId
819 743
     */
820 744
    public void updateMapping(String guid, String localId)
821 745
    {
822
    	updateMapping(guid, localId, TYPE_IDENTIFIER);
823
    }
824
    
825
    /**
826
     * update a mapping
827
     * @param guid
828
     * @param localId
829
     */
830
    private void updateMapping(String guid, String localId, String type)
831
    {
832
    	if (!type.equals(TYPE_IDENTIFIER) && !type.equals(TYPE_SYSTEM_METADATA)) {
833
    		throw new RuntimeException("Cannot create mapping for type " + type +
834
    		            ".  Please choose 'identifier' or 'systemmetadata'.");
835
    	}
836 746
    	
837
        System.out.println("$$$$$$$$$$$$$$ updating mapping table");
747
        logMetacat.debug("$$$$$$$$$$$$$$ updating mapping table");
838 748
        int serialNumber = -1;
839 749
        DBConnection dbConn = null;
840 750
        try {
......
852 762
                DBConnectionPool.getDBConnection("IdentifierManager.updateMapping");
853 763
            serialNumber = dbConn.getCheckOutSerialNumber();
854 764

  
855
            // Execute the insert statement
856
            String query = "update " + type + " set (docid, rev) = (?, ?) where guid='" + guid + "'";
857
            //System.out.println("query: " + query + " for params: (guid:" + guid + ", docid=" + docid + ", rev=" + rev + ")");
765
            // Execute the update statement
766
            String query = "update " + TYPE_IDENTIFIER + " set (docid, rev) = (?, ?) where guid='" + guid + "'";
858 767
            PreparedStatement stmt = dbConn.prepareStatement(query);
859 768
            stmt.setString(1, docid);
860 769
            stmt.setInt(2, rev);
......
877 786
            // Return database connection to the pool
878 787
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
879 788
        }
880
        System.out.println("done updating mapping");
789
        logMetacat.debug("done updating mapping");
881 790
    }
882
    
883
    /**
884
     * return the localId of a system metadata document based on its guid
885
     */
886
    public String getSystemMetadataLocalId(String guid)
887
      throws McdbDocNotFoundException
888
    {
889
      return this.getLocalId(guid, TYPE_SYSTEM_METADATA);
890
    }
891
    
892
    private void insertAdditionalSystemMetadataFields(long dateUploaded, String rightsHolder,
791
        
792
    private void updateSystemMetadataFields(long dateUploaded, String rightsHolder,
893 793
            String checksum, String checksumAlgorithm, String originMemberNode,
894 794
            String authoritativeMemberNode, long modifiedDate, String submitter, 
895 795
            String guid, String objectFormat, long size)
......
924 824
            stmt.setString(10, new Long(size).toString());
925 825
            //where clause
926 826
            stmt.setString(11, guid);
927
            System.out.println("stmt: " + stmt.toString());
827
            logMetacat.debug("stmt: " + stmt.toString());
928 828
            //execute
929 829
            int rows = stmt.executeUpdate();
930 830

  
......
992 892
     * Insert the system metadata fields into the db
993 893
     * @param sm
994 894
     */
995
    public void insertAdditionalSystemMetadataFields(SystemMetadata sm)
895
    public void updateSystemMetadata(SystemMetadata sm)
996 896
    {
997
        insertAdditionalSystemMetadataFields(
897
        updateSystemMetadataFields(
998 898
                sm.getDateUploaded().getTime(),
999 899
                sm.getRightsHolder().getValue(), 
1000 900
                sm.getChecksum().getValue(), 
......
1050 950
    }
1051 951
    
1052 952
    /**
1053
     * return a localId based on a guid.  The type can either be 'identifier' 
1054
     * to get an id from the identifier table or 'systemmetadata' to get
1055
     * the identifier from the systemidentifier table
953
     * Lookup a localId given the GUID. If
954
     * the identifier is not found, throw an exception.
955
     * 
956
     * @param guid the global identifier to look up
957
     * @return String containing the corresponding LocalId
958
     * @throws McdbDocNotFoundException if the identifier is not found
1056 959
     */
1057
    private String getLocalId(String guid, String type)
1058
      throws McdbDocNotFoundException
1059
    {
1060
      if(!type.equals(TYPE_IDENTIFIER) &&
1061
        !type.equals(TYPE_SYSTEM_METADATA))
1062
      {
1063
        throw new RuntimeException("cannot lookup the identifier for type " + type +
1064
          ".  Please choose 'identifier' or 'systemmetadata'.");
1065
      }
960
    public String getLocalId(String guid) throws McdbDocNotFoundException {
1066 961
      
1067 962
      String db_guid = "";
1068 963
      String docid = "";
1069 964
      int rev = 0;
1070 965
      
1071
      String query = "select guid, docid, rev from " + type + " where guid = ?";
1072
      //System.out.println("query: " + query + " for params: (" + guid + ")");
966
      String query = "select guid, docid, rev from " + TYPE_IDENTIFIER + " where guid = ?";
1073 967
      
1074 968
      DBConnection dbConn = null;
1075 969
      int serialNumber = -1;
......
1212 1106
                stmt.setTimestamp(1, new Timestamp(endTime.getTime()));
1213 1107
            }
1214 1108
            
1215
            //System.out.println("LISTOBJECTS QUERY: " + stmt.toString());
1109
            //logMetacat.debug("LISTOBJECTS QUERY: " + stmt.toString());
1216 1110
            
1217 1111
            ResultSet rs = stmt.executeQuery();
1218 1112
            for(int i=0; i<start; i++)
......
1237 1131
                    break;
1238 1132
                }
1239 1133
                String guid = rs.getString(1);
1240
                //System.out.println("query found doc with guid " + guid);
1134
                //logMetacat.debug("query found doc with guid " + guid);
1241 1135
                //Timestamp dateUploaded = rs.getTimestamp(2);
1242 1136
                //String rightsHolder = rs.getString(3);
1243 1137
                String checksum = rs.getString(4);
......
1292 1186
        catch(Exception e)
1293 1187
        {
1294 1188
           e.printStackTrace();
1295
           System.out.println("Error querying system metadata: " + e.getMessage());
1189
           logMetacat.error("Error querying system metadata: " + e.getMessage());
1296 1190
        }
1297 1191
        finally 
1298 1192
        {
......
1308 1202
    }
1309 1203
    
1310 1204
    /**
1311
     * create a mapping in the systemmetadata or identifier table
1205
     * create a mapping in the identifier table
1312 1206
     * @param guid
1313 1207
     * @param localId
1314
     * @param type
1315 1208
     */
1316
    private void createGenericMapping(String guid, String localId, String type)
1209
    public void createMapping(String guid, String localId)
1317 1210
    {        
1318
        if(!type.equals(TYPE_IDENTIFIER) &&
1319
        !type.equals(TYPE_SYSTEM_METADATA))
1320
        {
1321
          throw new RuntimeException("Cannot create mapping for type " + type +
1322
            ".  Please choose 'identifier' or 'systemmetadata'.");
1323
        }
1324 1211
        
1325 1212
        int serialNumber = -1;
1326 1213
        DBConnection dbConn = null;
......
1330 1217
            AccessionNumber acc = new AccessionNumber(localId, "NOACTION");
1331 1218
            String docid = acc.getDocid();
1332 1219
            int rev = 1;
1333
            if(acc.getRev() != null)
1334
            {
1220
            if (acc.getRev() != null) {
1335 1221
              rev = (new Integer(acc.getRev()).intValue());
1336 1222
            }
1337 1223

  
1338 1224
            // Get a database connection from the pool
1339
            dbConn = 
1340
                DBConnectionPool.getDBConnection("IdentifierManager.createMapping");
1225
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.createMapping");
1341 1226
            serialNumber = dbConn.getCheckOutSerialNumber();
1342 1227

  
1343 1228
            // Execute the insert statement
1344
            String query = "insert into " + type + " (guid, docid, rev) values (?, ?, ?)";
1345
            //System.out.println("query: " + query + " for params: (" + guid + ", " + docid + ", " + rev + ")");
1229
            String query = "insert into " + TYPE_IDENTIFIER + " (guid, docid, rev) values (?, ?, ?)";
1346 1230
            PreparedStatement stmt = dbConn.prepareStatement(query);
1347 1231
            stmt.setString(1, guid);
1348 1232
            stmt.setString(2, docid);
1349 1233
            stmt.setInt(3, rev);
1350
            System.out.println("generic mapping query: " + stmt.toString());
1234
            logMetacat.debug("mapping query: " + stmt.toString());
1351 1235
            int rows = stmt.executeUpdate();
1352 1236

  
1353 1237
            stmt.close();
1354 1238
        } catch (SQLException e) {
1355 1239
            e.printStackTrace();
1356
            logMetacat.error("createGenericMapping: SQL error while creating a mapping to the " + type + " identifier: " 
1240
            logMetacat.error("createGenericMapping: SQL error while creating a mapping to the " + TYPE_IDENTIFIER + " identifier: " 
1357 1241
                    + e.getMessage());
1358 1242
        } catch (NumberFormatException e) {
1359 1243
            e.printStackTrace();
1360
            logMetacat.error("createGenericMapping: NumberFormat error while creating a mapping to the " + type + " identifier: " 
1244
            logMetacat.error("createGenericMapping: NumberFormat error while creating a mapping to the " + TYPE_IDENTIFIER + " identifier: " 
1361 1245
                    + e.getMessage());
1362 1246
        } catch (AccessionNumberException e) {
1363 1247
            e.printStackTrace();
1364
            logMetacat.error("createGenericMapping: AccessionNumber error while creating a mapping to the " + type + " identifier: " 
1248
            logMetacat.error("createGenericMapping: AccessionNumber error while creating a mapping to the " + TYPE_IDENTIFIER + " identifier: " 
1365 1249
                    + e.getMessage());
1366 1250
        } finally {
1367 1251
            // Return database connection to the pool
1368 1252
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1369 1253
        }
1370 1254
    }
1255
    
1256
    /**
1257
     * create the systemmetadata record
1258
     * @param guid
1259
     */
1260
    public void insertSystemMetadata(String guid)
1261
    {        
1262
        
1263
        int serialNumber = -1;
1264
        DBConnection dbConn = null;
1265
        try {
1266

  
1267
            // Get a database connection from the pool
1268
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.insertSystemMetadata");
1269
            serialNumber = dbConn.getCheckOutSerialNumber();
1270

  
1271
            // Execute the insert statement
1272
            String query = "insert into " + TYPE_SYSTEM_METADATA + " (guid) values (?)";
1273
            PreparedStatement stmt = dbConn.prepareStatement(query);
1274
            stmt.setString(1, guid);
1275
            logMetacat.debug("system metadata query: " + stmt.toString());
1276
            int rows = stmt.executeUpdate();
1277

  
1278
            stmt.close();
1279
        } catch (Exception e) {
1280
            e.printStackTrace();
1281
            logMetacat.error("Error while creating " + TYPE_SYSTEM_METADATA + " record: " 
1282
                    + e.getMessage());
1283
        } finally {
1284
            // Return database connection to the pool
1285
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1286
        }
1287
    }
1371 1288
}
1372 1289

  
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
248 248
        //v is the list of updated documents
249 249
        Vector<Vector<String>> updateList = new Vector<Vector<String>>(message.getUpdatesVect());
250 250
        logReplication.info("ReplicationHandler.update - The document list size is "+updateList.size()+ " from "+message.getServerName());
251
        //System.out.println("v: " + v.toString());
252 251
        //d is the list of deleted documents
253 252
        Vector<Vector<String>> deleteList = new Vector<Vector<String>>(message.getDeletesVect());
254
        //System.out.println("d: " + d.toString());
255 253
        logReplication.info("ReplicationHandler.update - Update vector size: "+ updateList.size()+" from "+message.getServerName());
256 254
        logReplication.info("ReplicationHandler.update - Delete vector size: "+ deleteList.size()+" from "+message.getServerName());
257 255
        logReplication.info("ReplicationHandler.update - The delete document list size is "+deleteList.size()+" from "+message.getServerName());
......
421 419
      }
422 420
      
423 421
      //process guid
424
      logReplication.debug("Processing guid information from docinfoHash: " + docinfoHash.toString());
425 422
      String guid = docinfoHash.get("guid");
426
      String docName = docinfoHash.get("docname");
427
      System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%guid passed from docinfo hash: " + guid);
428
      IdentifierManager idman = IdentifierManager.getInstance();
429
      
430
      System.out.println("docname: " + docName);
431
      
432
      if(guid != null && !idman.identifierExists(guid))
433
      { //if the guid was passed in, put it in the identifiers table
434
        logReplication.debug("Creating guid/docid mapping for docid " + 
435
          docinfoHash.get("docid") + " and guid: " + guid);
436
        
437
        
438
        System.out.println("creating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
439
        idman.createMapping(guid, docinfoHash.get("docid"));
440
      }
441
      else
442
      {
443
        logReplication.debug("No guid information was included with the replicated document");
444
      }
445
      
446
      //handle systemMetadata
447
      if(docName.trim().equals("systemMetadata"))
448
      {
449
          if (actions.equalsIgnoreCase("UPDATE")) {
450
        	  System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!update mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
451
              idman.updateSystemMetadataMapping(guid, docinfoHash.get("docid"));
452
          } else { 
453
	    	  System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!creating mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
454
	          idman.createSystemMetadataMapping(guid, docinfoHash.get("docid"));
455
          }
456
          
457
          Date dateUploaded = new Date(new Long(docinfoHash.get("date_uploaded")));
423
      logMetacat.debug("Guid passed from docinfo hash: " + guid);
424
      if (guid != null) {
425
          // if the guid was passed in, put it in the identifiers table
426
    	  if (!IdentifierManager.getInstance().identifierExists(guid)) {
427
    		  logReplication.debug("Creating guid/docid mapping for docid " + docinfoHash.get("docid") + " and guid: " + guid);
428
    		  IdentifierManager.getInstance().createMapping(guid, docinfoHash.get("docid"));
429
    	  } else {
430
    		  logReplication.debug("Updating guid/docid mapping for docid " + docinfoHash.get("docid") + " and guid: " + guid);
431
    		  IdentifierManager.getInstance().updateMapping(guid, docinfoHash.get("docid"));
432
    	  }
433
    	  // process system metadata
434
    	  Date dateUploaded = new Date(new Long(docinfoHash.get("date_uploaded")));
458 435
          Date dateModified = new Date(new Long(docinfoHash.get("date_modified")));
459 436
          SystemMetadata sysMeta = IdentifierManager.getInstance().asSystemMetadata(
460 437
                  dateUploaded, 
......
468 445
                  docinfoHash.get("guid"),
469 446
                  docinfoHash.get("object_format"),
470 447
                  new Long(docinfoHash.get("size")).longValue());
471
          IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sysMeta);
472
          
473
          System.out.println("4");
474
      }
475
      
476
      if(guid != null)
477
      {
478
          if(!docName.trim().equals("systemMetadata"))
479
          {
480
              logReplication.info("replicate D1GUID:" + guid + ":D1SCIMETADATA:" + 
481
                      accNumber + ":");
448
          if (actions.equalsIgnoreCase("INSERT")) {
449
	    	  logMetacat.debug("Creating systemMetadata for guid: " + guid);
450
	    	  IdentifierManager.getInstance().createSystemMetadata(sysMeta);
482 451
          }
483
          else
484
          {
485
              logReplication.info("replicate D1GUID:" + guid + ":D1SYSMETADATA:" + 
486
                      accNumber + ":");
487
          }
452
          IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
488 453
      }
489 454
      
490 455
      logReplication.info("ReplicationHandler.handleSingleXMLDocument - Successfully replicated doc " + accNumber);
......
623 588
            }
624 589
        }
625 590
        
591
        //process guid
592
        String guid = docinfoHash.get("guid");
593
        logMetacat.debug("Guid passed from docinfo hash: " + guid);
594
        if (guid != null) {
595
            // if the guid was passed in, put it in the identifiers table
596
      	  if (!IdentifierManager.getInstance().identifierExists(guid)) {
597
      		  logReplication.debug("Creating guid/docid mapping for docid " + docinfoHash.get("docid") + " and guid: " + guid);
598
      		  IdentifierManager.getInstance().createMapping(guid, docinfoHash.get("docid"));
599
      	  } else {
600
      		  logReplication.debug("Updating guid/docid mapping for docid " + docinfoHash.get("docid") + " and guid: " + guid);
601
      		  IdentifierManager.getInstance().updateMapping(guid, docinfoHash.get("docid"));
602
      	  }
603
      	  // process system metadata
604
      	  Date dateUploaded = new Date(new Long(docinfoHash.get("date_uploaded")));
605
            Date dateModified = new Date(new Long(docinfoHash.get("date_modified")));
606
            SystemMetadata sysMeta = IdentifierManager.getInstance().asSystemMetadata(
607
                    dateUploaded, 
608
                    docinfoHash.get("rights_holder"),
609
                    docinfoHash.get("checksum"), 
610
                    docinfoHash.get("checksum_algorithm"), 
611
                    docinfoHash.get("origin_member_node"),
612
                    docinfoHash.get("authoritive_member_node"), 
613
                    dateModified,
614
                    docinfoHash.get("submitter"),
615
                    docinfoHash.get("guid"),
616
                    docinfoHash.get("object_format"),
617
                    new Long(docinfoHash.get("size")).longValue());
618
            if (actions.equalsIgnoreCase("INSERT")) {
619
  	    	  logMetacat.debug("Creating systemMetadata for guid: " + guid);
620
  	    	  IdentifierManager.getInstance().createSystemMetadata(sysMeta);
621
            }
622
            IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
623
        }
624
        
626 625
        logReplication.info("ReplicationHandler.handleSingleDataFile - Successfully to write datafile " + accNumber);
627 626
        /*MetacatReplication.replLog("wrote datafile " + accNumber + " from " +
628 627
                                    remote server);*/
......
706 705
         //because delete method docid should have rev number
707 706
         //so we just add one for it. This rev number is no sence.
708 707
         String accnum=docId+PropertyService.getProperty("document.accNumSeparator")+"1";
709
         //System.out.println("accnum: "+accnum);
710 708
         DocumentImpl.delete(accnum, null, null, notifyServer);
711 709
         logReplication.info("ReplicationHandler.handleDeleteSingleDocument - Successfully deleted doc " + docId);
712 710
         logReplication.info("ReplicationHandler.handleDeleteSingleDocument - Doc " + docId + " deleted");
......
892 890
          Vector<String> v = new Vector<String>(localCatalog.elementAt(i));
893 891
          logReplication.info("ReplicationHandler.updateCatalog - v1: " + v.toString());
894 892
          publicId.add(new String((String)v.elementAt(3)));
895
          //System.out.println("adding " + (String)v.elementAt(3));
896 893
        }
897 894
      }//try
898 895
      catch (Exception e)
......
914 911
                  getDBConnection("ReplicationHandler.updateCatalog");
915 912
            serialNumber=dbConn.getCheckOutSerialNumber();
916 913
            Vector<String> v = remoteCatalog.elementAt(i);
917
            //System.out.println("v2: " + v.toString());
918
            //System.out.println("i: " + i);
919
            //System.out.println("remoteCatalog.size(): " + remoteCatalog.size());
920
            //System.out.println("publicID: " + publicId.toString());
914
            //logMetacat.debug("v2: " + v.toString());
915
            //logMetacat.debug("i: " + i);
916
            //logMetacat.debug("remoteCatalog.size(): " + remoteCatalog.size());
917
            //logMetacat.debug("publicID: " + publicId.toString());
921 918
            logReplication.info
922 919
                              ("ReplicationHandler.updateCatalog - v.elementAt(3): " + (String)v.elementAt(3));
923 920
           if(!publicId.contains(v.elementAt(3)))
924 921
           { //so we don't have this public id in our local table so we need to
925 922
             //add it.
926
             //System.out.println("in if");
923
             //logMetacat.debug("in if");
927 924
             StringBuffer sql = new StringBuffer();
928 925
             sql.append("insert into xml_catalog (entry_type, source_doctype, ");
929 926
             sql.append("target_doctype, public_id, system_id) values (?,?,?,");
930 927
             sql.append("?,?)");
931
             //System.out.println("sql: " + sql.toString());
928
             //logMetacat.debug("sql: " + sql.toString());
932 929
             pstmt = dbConn.prepareStatement(sql.toString());
933 930
             pstmt.setString(1, (String)v.elementAt(0));
934 931
             pstmt.setString(2, (String)v.elementAt(1));
......
1203 1200
				logReplication.error("ReplicationHandler.handleDocList - Could not retrieve data file flag property.  "
1204 1201
						+ "Leaving as false: " + pnfe.getMessage());
1205 1202
			}
1206
			// System.out.println("w: " + w.toString());
1203
			// logMetacat.debug("w: " + w.toString());
1207 1204
			// Get docid
1208 1205
			String docid = (String) w.elementAt(0);
1209 1206
			logReplication.info("docid: " + docid);
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
562 562
			// Get home server of this docid
563 563
			String homeServer = (String) docinfoHash.get("home_server");
564 564
			String guid = (String) docinfoHash.get("guid");
565
			logReplication.info("XXXXXXXXXXXXXXXX GUID found in dociinfoHash: " + guid);
565
			logReplication.debug("GUID found in docinfoHash: " + guid);
566 566
			
567
			logReplication.info("Processing guid " + guid + 
567
			logReplication.debug("Processing guid " + guid + 
568 568
			  " information from handleForceReplicationRequest: " + 
569 569
			  docinfoHash.toString());
570
      IdentifierManager idman = IdentifierManager.getInstance();
571
      if(guid != null)
572
      { //if the guid was passed in, put it in the identifiers table
573
        logReplication.info("YYYYYYYYYYYYYY Creating guid/docid mapping for docid " + 
574
          docinfoHash.get("docid") + " and guid: " + guid);
575
        
576
        docName = (String) docinfoHash.get("docname");
577
        logReplication.info("ZZZZZZZZZZZZ docName: " + docName);
578
        if(docName.trim().equals("systemMetadata"))
579
        {
580
        	if (dbaction.equalsIgnoreCase("UPDATE")) {
581
        		logReplication.info("update mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
582
	            idman.updateSystemMetadataMapping(guid, docinfoHash.get("docid"));
583
	            logReplication.info("handleForceReplicateRequest: updating SM with additional info");
584
        	} else { // insert
585
	            logReplication.info("creating mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
586
	            idman.createSystemMetadataMapping(guid, docinfoHash.get("docid"));
587
        	}
588
        	logReplication.info("handleForceReplicateRequest: updating SM with additional info");
589
        	Date dateUploaded = new Date(new Long(docinfoHash.get("date_uploaded")));
590
	        Date dateModified = new Date(new Long(docinfoHash.get("date_modified")));
591
            SystemMetadata sysMeta = IdentifierManager.getInstance().asSystemMetadata(
592
                    dateUploaded, 
593
                    docinfoHash.get("rights_holder"),
594
                    docinfoHash.get("checksum"), 
595
                    docinfoHash.get("checksum_algorithm"), 
596
                    docinfoHash.get("origin_member_node"),
597
                    docinfoHash.get("authoritive_member_node"), 
598
                    dateModified,
599
                    docinfoHash.get("submitter"),
600
                    docinfoHash.get("guid"),
601
                    docinfoHash.get("object_format"),
602
                    new Long(docinfoHash.get("size")).longValue());
603
            IdentifierManager.getInstance().insertAdditionalSystemMetadataFields(sysMeta);
604
        }
605
        else
606
        {
607
        	if (dbaction.equalsIgnoreCase("UPDATE")) {
608
        		logReplication.info("updating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
609
	            idman.updateMapping(guid, docinfoHash.get("docid"));
610
        	} else { // insert
611
	            logReplication.info("creating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
612
	            idman.createMapping(guid, docinfoHash.get("docid"));
613
        	}
614
        }
615
      }
616
      else
617
      {
618
        logReplication.debug("No guid information was included with the replicated document");
619
      }
570
			
571
			//if the guid was passed in, we have system metadata with the doc
572
			if (guid != null) {
573
				// map the guid to local identifiers
574
	        	if (dbaction.equalsIgnoreCase("UPDATE")) {
575
	        		logReplication.info("updating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
576
	        		IdentifierManager.getInstance().updateMapping(guid, docinfoHash.get("docid"));
577
	        	} else { // insert
578
		            logReplication.info("creating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
579
		            IdentifierManager.getInstance().createMapping(guid, docinfoHash.get("docid"));
580
	        	}
581
	        	// process system metadata
582
	        	logReplication.info("handleForceReplicateRequest: updating system metadata");
583
	        	Date dateUploaded = new Date(new Long(docinfoHash.get("date_uploaded")));
584
		        Date dateModified = new Date(new Long(docinfoHash.get("date_modified")));
585
	            SystemMetadata sysMeta = IdentifierManager.getInstance().asSystemMetadata(
586
	                    dateUploaded, 
587
	                    docinfoHash.get("rights_holder"),
588
	                    docinfoHash.get("checksum"), 
589
	                    docinfoHash.get("checksum_algorithm"), 
590
	                    docinfoHash.get("origin_member_node"),
591
	                    docinfoHash.get("authoritive_member_node"), 
592
	                    dateModified,
593
	                    docinfoHash.get("submitter"),
594
	                    docinfoHash.get("guid"),
595
	                    docinfoHash.get("object_format"),
596
	                    new Long(docinfoHash.get("size")).longValue());
597
	        	if (dbaction.equalsIgnoreCase("INSERT")) {
598
		            logReplication.info("Adding systemMetadata for guid: " + guid);
599
		            IdentifierManager.getInstance().createSystemMetadata(sysMeta);
600
	        	}
601
	            IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
602
			}
620 603
      
604
        	// replicate doc contents
621 605
			String createdDate = (String) docinfoHash.get("date_created");
622 606
			String updatedDate = (String) docinfoHash.get("date_updated");
623 607
			logReplication.info("ReplicationService.handleForceReplicateRequest - homeServer: " + homeServer);
......
815 799
				dbaction = "update";
816 800
			}
817 801

  
818
			logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - force replication request from " + server);
819 802
			logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - Force replication request from: " + server);
820 803
			logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - Force replication docid: " + docid);
821 804
			logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - Force replication action: " + dbaction);
......
843 826
			String updatedDate = (String) docinfoHash.get("date_updated");
844 827
			logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - docHomeServer of datafile: " + docHomeServer);
845 828

  
846
			//if action is delete, we don't delete the data file. Just archieve
847
			//the xml_documents
848
			/*if (dbaction.equals("delete"))
849
			{
850
			  //conn = util.getConnection();
851
			  DocumentImpl.delete(docid,user,null);
852
			  //util.returnConnection(conn);
853
			}*/
854
			//To data file insert or update is same
855 829
			if (dbaction.equals("insert") || dbaction.equals("update")) {
856 830
				//Get data file and store it into local file system.
857 831
				// sending back readdata request to server
......
893 867
		        		}
894 868
		            }
895 869
		        }
870
		        
871
				String guid = (String) docinfoHash.get("guid");
872
				//if the guid was passed in, we have system metadata with the doc
873
				if (guid != null) {
874
					// map the guid to local identifiers
875
		        	if (dbaction.equalsIgnoreCase("UPDATE")) {
876
		        		logReplication.info("updating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
877
		        		IdentifierManager.getInstance().updateMapping(guid, docinfoHash.get("docid"));
878
		        	} else { // insert
879
			            logReplication.info("creating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
880
			            IdentifierManager.getInstance().createMapping(guid, docinfoHash.get("docid"));
881
		        	}
882
		        	// process system metadata
883
		        	logReplication.info("handleForceReplicateRequest: updating system metadata");
884
		        	Date dateUploaded = new Date(new Long(docinfoHash.get("date_uploaded")));
885
			        Date dateModified = new Date(new Long(docinfoHash.get("date_modified")));
886
		            SystemMetadata sysMeta = IdentifierManager.getInstance().asSystemMetadata(
887
		                    dateUploaded, 
888
		                    docinfoHash.get("rights_holder"),
889
		                    docinfoHash.get("checksum"), 
890
		                    docinfoHash.get("checksum_algorithm"), 
891
		                    docinfoHash.get("origin_member_node"),
892
		                    docinfoHash.get("authoritive_member_node"), 
893
		                    dateModified,
894
		                    docinfoHash.get("submitter"),
895
		                    docinfoHash.get("guid"),
896
		                    docinfoHash.get("object_format"),
897
		                    new Long(docinfoHash.get("size")).longValue());
898
		        	if (dbaction.equalsIgnoreCase("INSERT")) {
899
			            logReplication.info("Adding systemMetadata for guid: " + guid);
900
			            IdentifierManager.getInstance().createSystemMetadata(sysMeta);
901
		        	}
902
		            IdentifierManager.getInstance().updateSystemMetadata(sysMeta);
903
				}
896 904

  
897 905
				if (writeException != null) {
898 906
					throw writeException;
899 907
				}
900 908

  
901
				//false means non-timed replication
902 909
				logReplication.info("ReplicationService.handleForceReplicateDataFileRequest - datafile " + docid + " added to DB with "
903 910
						+ "action " + dbaction);
904 911
				EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER,
......
990 997
			{
991 998
			  String guid = idman.getGUID(doc.getDocID(), doc.getRev());
992 999
			  sb.append("<guid>").append(guid).append("</guid>");
993
			  String smLocalId = idman.getSystemMetadataLocalId(guid);
994
			  Hashtable<String, String> sysmetaInfo = idman.getSystemMetadataInfo(smLocalId);
995
			  if(smLocalId != null && !smLocalId.trim().equals(""))
996
			  {
997
			      sb.append("<systemmetadatalocalid>").append(smLocalId).append("</systemmetadatalocalid>");
998
			  }
1000
			  Hashtable<String, String> sysmetaInfo = idman.getSystemMetadataInfo(guid);
999 1001
			  
1000 1002
			  Enumeration<String> sysmetaKeys = sysmetaInfo.keys();
1001 1003
			  while(sysmetaKeys.hasMoreElements())

Also available in: Unified diff