Project

General

Profile

« Previous | Next » 

Revision 6079

use update method to update the mapping between local and guid (d1) when we get a force replication request that is an "update

View differences:

src/edu/ucsb/nceas/metacat/IdentifierManager.java
622 622
    }
623 623
    
624 624
    /**
625
     * update a mapping
625
     * update a system metadata mapping
626 626
     * @param guid
627 627
     * @param localId
628 628
     */
629 629
    public void updateSystemMetadataMapping(String guid, String localId)
630 630
    {
631
        System.out.println("$$$$$$$$$$$$$$ updating systemmetadata table with additional info");
631
    	updateMapping(guid, localId, TYPE_SYSTEM_METADATA);
632
    }
633
    
634
    /**
635
     * update a mapping
636
     * @param guid
637
     * @param localId
638
     */
639
    public void updateMapping(String guid, String localId)
640
    {
641
    	updateMapping(guid, localId, TYPE_IDENTIFIER);
642
    }
643
    
644
    /**
645
     * update a mapping
646
     * @param guid
647
     * @param localId
648
     */
649
    private void updateMapping(String guid, String localId, String type)
650
    {
651
    	if (!type.equals(TYPE_IDENTIFIER) && !type.equals(TYPE_SYSTEM_METADATA)) {
652
    		throw new RuntimeException("Cannot create mapping for type " + type +
653
    		            ".  Please choose 'identifier' or 'systemmetadata'.");
654
    	}
655
    	
656
        System.out.println("$$$$$$$$$$$$$$ updating mapping table");
632 657
        int serialNumber = -1;
633 658
        DBConnection dbConn = null;
634 659
        try {
......
643 668

  
644 669
            // Get a database connection from the pool
645 670
            dbConn = 
646
                DBConnectionPool.getDBConnection("IdentifierManager.createMapping");
671
                DBConnectionPool.getDBConnection("IdentifierManager.updateMapping");
647 672
            serialNumber = dbConn.getCheckOutSerialNumber();
648 673

  
649 674
            // Execute the insert statement
650
            String query = "update systemmetadata set (docid, rev) = (?, ?) where guid='" + guid + "'";
675
            String query = "update " + type + " set (docid, rev) = (?, ?) where guid='" + guid + "'";
651 676
            //System.out.println("query: " + query + " for params: (guid:" + guid + ", docid=" + docid + ", rev=" + rev + ")");
652 677
            PreparedStatement stmt = dbConn.prepareStatement(query);
653 678
            stmt.setString(1, docid);
......
657 682
            stmt.close();
658 683
        } catch (SQLException e) {
659 684
            e.printStackTrace();
660
            logMetacat.error("SQL error while updating a mapping to the system metadata identifier: " 
685
            logMetacat.error("SQL error while updating a mapping identifier: " 
661 686
                    + e.getMessage());
662 687
        } catch (NumberFormatException e) {
663 688
            e.printStackTrace();
664
            logMetacat.error("NumberFormat error while updating a mapping to the system metadata identifier: " 
689
            logMetacat.error("NumberFormat error while updating a mapping identifier: " 
665 690
                    + e.getMessage());
666 691
        } catch (AccessionNumberException e) {
667 692
            e.printStackTrace();
668
            logMetacat.error("AccessionNumber error while updating a mapping to the system metadata identifier: " 
693
            logMetacat.error("AccessionNumber error while updating a mapping identifier: " 
669 694
                    + e.getMessage());
670 695
        } finally {
671 696
            // Return database connection to the pool
672 697
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
673 698
        }
674
        System.out.println("done updating systemmetadata");
699
        System.out.println("done updating mapping");
675 700
    }
676 701
    
677 702
    /**
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
445 445
      //handle systemMetadata
446 446
      if(docName.trim().equals("systemMetadata"))
447 447
      {
448
          System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!creating mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
449
          idman.createSystemMetadataMapping(guid, docinfoHash.get("docid"));
448
          if (actions.equalsIgnoreCase("UPDATE")) {
449
        	  System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!update mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
450
              idman.updateSystemMetadataMapping(guid, docinfoHash.get("docid"));
451
          } else { 
452
	    	  System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!creating mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
453
	          idman.createSystemMetadataMapping(guid, docinfoHash.get("docid"));
454
          }
455
          
450 456
          Long dateUploadedLong = new Long(docinfoHash.get("date_uploaded"));
451 457
          Long dateModifiedLong = new Long(docinfoHash.get("date_modified"));
452 458
          idman.insertAdditionalSystemMetadataFields(
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
576 576
        logReplication.info("ZZZZZZZZZZZZ docName: " + docName);
577 577
        if(docName.trim().equals("systemMetadata"))
578 578
        {
579
            logReplication.info("creating mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
580
            idman.createSystemMetadataMapping(guid, docinfoHash.get("docid"));
581
            logReplication.info("handleForceReplicateRequest: updating SM with additional info");
582
            System.out.println("!!!!!!!!!!!!!handleForceReplicateRequest: updating SM with additional info");
583
            Long dateUploadedLong = new Long(docinfoHash.get("date_uploaded"));
584
            Long dateModifiedLong = new Long(docinfoHash.get("date_modified"));
579
        	if (dbaction.equalsIgnoreCase("UPDATE")) {
580
        		logReplication.info("update mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
581
	            idman.updateSystemMetadataMapping(guid, docinfoHash.get("docid"));
582
	            logReplication.info("handleForceReplicateRequest: updating SM with additional info");
583
        	} else { // insert
584
	            logReplication.info("creating mapping for systemMetadata: guid: " + guid + " localId: " + docinfoHash.get("docid"));
585
	            idman.createSystemMetadataMapping(guid, docinfoHash.get("docid"));
586
        	}
587
        	logReplication.info("handleForceReplicateRequest: updating SM with additional info");
588
        	Long dateUploadedLong = new Long(docinfoHash.get("date_uploaded"));
589
	        Long dateModifiedLong = new Long(docinfoHash.get("date_modified"));
585 590
            idman.insertAdditionalSystemMetadataFields(
586 591
                    dateUploadedLong.longValue(), 
587 592
                    docinfoHash.get("rights_holder"),
......
597 602
        }
598 603
        else
599 604
        {
600
            logReplication.info("creating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
601
            idman.createMapping(guid, docinfoHash.get("docid"));
605
        	if (dbaction.equalsIgnoreCase("UPDATE")) {
606
        		logReplication.info("updating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
607
	            idman.updateMapping(guid, docinfoHash.get("docid"));
608
        	} else { // insert
609
	            logReplication.info("creating mapping: guid: " + guid + " localId: " + docinfoHash.get("docid"));
610
	            idman.createMapping(guid, docinfoHash.get("docid"));
611
        	}
602 612
        }
603 613
      }
604 614
      else
......
639 649
			serialNumber = dbConn.getCheckOutSerialNumber();
640 650
			// write the document to local database
641 651
			DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false);
642
			//try this independently so we can set
643
//			Exception writeException = null;
652
			//try this independently so we can set access even if the update action is invalid (i.e docid has not changed)
644 653
			try {
645 654
				wrapper.writeReplication(dbConn, xmldoc, null, null,
646 655
						dbaction, docid, null, null, homeServer, server, createdDate,
647 656
						updatedDate);
648 657
			} finally {
649
//				writeException = e;
650 658

  
651 659
				//process extra access rules before dealing with the write exception (doc exist already)			
652 660
		        Vector<XMLAccessDAO> accessControlList = dih.getAccessControlList();
......
682 690
                                docid + ":");
683 691
                    }
684 692
                }
685
				EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid,
686
						dbaction);
693
				EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid, dbaction);
687 694
			}
688 695
		} catch (SQLException sqle) {
689 696
			logMetacat.error("ReplicationService.handleForceReplicateRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG);                         

Also available in: Unified diff