Project

General

Profile

« Previous | Next » 

Revision 9354

Added by Jing Tao over 8 years ago

Add the case the mn.updateSystemMetadata and cn.updateSystemMetadata will call the archive method internally.

View differences:

D1NodeService.java
1717 1717
     * @throws InvalidToken
1718 1718
     */
1719 1719
	protected boolean updateSystemMetadata(Session session, Identifier pid,
1720
			SystemMetadata sysmeta, boolean needUpdateModificationDate, SystemMetadata currentSysmeta) throws NotImplemented, NotAuthorized,
1720
			SystemMetadata sysmeta, boolean needUpdateModificationDate, SystemMetadata currentSysmeta, boolean fromCN) throws NotImplemented, NotAuthorized,
1721 1721
			ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken {
1722 1722
		
1723 1723
	  // The lock to be used for this identifier
......
1801 1801
      }
1802 1802
      
1803 1803
      // do the actual update
1804
      updateSystemMetadataWithoutLock(sysmeta, needUpdateModificationDate);
1805
      
1804
      if(sysmeta.getArchived() != null && sysmeta.getArchived() == true && 
1805
                 ((currentSysmeta.getArchived() != null && currentSysmeta.getArchived() == false ) || currentSysmeta.getArchived() == null)) {
1806
          if(fromCN) {
1807
              logMetacat.debug("D1Node.update - this is to archive a cn object "+pid.getValue());
1808
              try {
1809
                  archiveCNObject(session, pid, sysmeta, needUpdateModificationDate);
1810
              } catch (NotFound e) {
1811
                  throw new InvalidRequest("4869", "Can't find the pid "+pid.getValue()+" for archive.");
1812
              }
1813
          } else {
1814
              logMetacat.debug("D1Node.update - this is to archive a MN object "+pid.getValue());
1815
              try {
1816
                  archiveObject(session, pid, sysmeta, needUpdateModificationDate);
1817
              } catch (NotFound e) {
1818
                  throw new InvalidRequest("4869", "Can't find the pid "+pid.getValue()+" for archive.");
1819
              }
1820
          }
1821
      } else {
1822
          logMetacat.debug("D1Node.update - regularly update the system metadata of the pid "+pid.getValue());
1823
          updateSystemMetadataWithoutLock(sysmeta, needUpdateModificationDate);
1824
      }
1825

  
1806 1826
      try {
1807 1827
    	  String localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
1808 1828
    	  EventLog.getInstance().log(request.getRemoteAddr(), 
......
2012 2032
   * @throws NotImplemented
2013 2033
   * @throws InvalidRequest
2014 2034
   */
2015
  protected Identifier archiveObject(Session session, Identifier pid, SystemMetadata sysMeta) 
2035
  protected Identifier archiveObject(Session session, Identifier pid, SystemMetadata sysMeta, boolean needModifyDate) 
2016 2036
      throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
2017 2037

  
2018 2038
      String localId = null;
......
2053 2073
              
2054 2074
              // archive it
2055 2075
              sysMeta.setArchived(true);
2056
              sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
2057
              sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE));
2076
              if(needModifyDate) {
2077
                  sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
2078
                  sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE));
2079
              }
2058 2080
              HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta);
2059 2081
              
2060 2082
              // submit for indexing
......
2079 2101
      return pid;
2080 2102
  }
2081 2103
  
2104
  /**
2105
   * Archive a object on cn and notify the replica. This method doesn't lock the system metadata map. The caller should lock it.
2106
   * This method doesn't check the authorization; this method only accept a pid.
2107
   * It wouldn't notify the replca that the system metadata has been changed.
2108
   * @param session
2109
   * @param pid
2110
   * @param sysMeta
2111
   * @param notifyReplica
2112
   * @return
2113
   * @throws InvalidToken
2114
   * @throws ServiceFailure
2115
   * @throws NotAuthorized
2116
   * @throws NotFound
2117
   * @throws NotImplemented
2118
   */
2119
  protected void archiveCNObject(Session session, Identifier pid, SystemMetadata sysMeta, boolean needModifyDate) 
2120
          throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
2121

  
2122
          String localId = null; // The corresponding docid for this pid
2123
          
2124
          // Check for the existing identifier
2125
          try {
2126
              localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
2127
              archiveObject(session, pid, sysMeta, needModifyDate);
2128
          
2129
          } catch (McdbDocNotFoundException e) {
2130
              // This object is not registered in the identifier table. Assume it is of formatType DATA,
2131
              // and set the archive flag. (i.e. the *object* doesn't exist on the CN)
2132
              
2133
              try {
2134
                  if ( sysMeta != null ) {
2135
                    sysMeta.setArchived(true);
2136
                    if (needModifyDate) {
2137
                        sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE));
2138
                        sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
2139
                    }
2140
                    HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta);
2141
                      
2142
                  } else {
2143
                      throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() +
2144
                          ". Couldn't obtain the system metadata record.");
2145
                      
2146
                  }
2147
                  
2148
              } catch (RuntimeException re) {
2149
                  throw new ServiceFailure("4972", "Couldn't archive " + pid.getValue() + 
2150
                      ". The error message was: " + re.getMessage());
2151
                  
2152
              } 
2153

  
2154
          } catch (SQLException e) {
2155
              throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() +
2156
                      ". The local id of the object with the identifier can't be identified since "+e.getMessage());
2157
          }
2158
          
2159
    }
2082 2160
  
2161
  
2083 2162
  /**
2084 2163
   * A utility method for v1 api to check the specified identifier exists as a pid
2085 2164
   * @param identifier  the specified identifier

Also available in: Unified diff