Project

General

Profile

« Previous | Next » 

Revision 9067

Added by Jing Tao over 9 years ago

Add the code to check if a sid is legitimate in the method create and registerSystemMetadata.

View differences:

CNodeService.java
1178 1178
              ") does not match identifier in system metadata (" +
1179 1179
              sysmeta.getIdentifier().getValue() + ").");
1180 1180
      }
1181
      
1182
      //check if the sid is legitimate in the system metadata
1183
      checkSidInRegisterSystemMetadata(sysmeta, "4864", "4862");
1181 1184

  
1182 1185
      try {
1183 1186
          lock = HazelcastService.getInstance().getLock(sysmeta.getIdentifier().getValue());
......
1562 1565

  
1563 1566
          // proceed if we're called by a CN
1564 1567
          if ( isAllowed ) {
1568
              //check if the series id is legitimate. It uses the same rules of the method registerSystemMetadata
1569
              checkSidInRegisterSystemMetadata(sysmeta, "4896", "4893");
1565 1570
              // create the coordinating node version of the document      
1566 1571
              lock.lock();
1567 1572
              logMetacat.debug("Locked identifier " + pid.getValue());
......
1980 1985
	}
1981 1986
	
1982 1987
	
1988
    /*
1989
     * Determine if the sid is legitimate in CN.create and CN.registerSystemMetadata methods. Here are the rules:
1990
     * A. If the sysmeta doesn't have an SID, nothing needs to be checked for the SID.
1991
     * B. If the sysmeta does have an SID, it may be an identifier which doesn't exist in the system.
1992
     * C. If the sysmeta does have an SID and it exists as an SID in the system, those scenarios are acceptable:
1993
     *    i. The sysmeta has an obsoletes field, the SID has the same value as the SID of the system metadata of the obsoleting pid.
1994
     *    ii. The sysmeta has an obsoletedBy field, the SID has the same value as the SID of the system metadata of the obsoletedBy pid. 
1995
	 */
1996
	protected boolean checkSidInRegisterSystemMetadata(SystemMetadata sysmeta, String invalidSystemMetadataCode, String serviceFailureCode) throws InvalidSystemMetadata, ServiceFailure{
1997
	    boolean pass = false;
1998
	    if(sysmeta == null) {
1999
	        throw new InvalidSystemMetadata(invalidSystemMetadataCode, "The system metadata is null in the request.");
2000
	    }
2001
	    Identifier sid = sysmeta.getSeriesId();
2002
	    if(sid != null) {
2003
	        // the series id exists
2004
	        if (!isValidIdentifier(sid)) {
2005
	            throw new InvalidSystemMetadata(invalidSystemMetadataCode, "The series id "+sid.getValue()+"in the system metadata is invalid in the request.");
2006
	        }
2007
	        try {
2008
	            if (IdentifierManager.getInstance().identifierExists(sid.getValue())) {
2009
	                //the sid exists in system
2010
	                if(sysmeta.getObsoletes() != null) {
2011
	                    SystemMetadata obsoletesSysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(sysmeta.getObsoletes());
2012
	                    if(obsoletesSysmeta != null) {
2013
	                        Identifier obsoletesSid = obsoletesSysmeta.getSeriesId();
2014
	                        if(obsoletesSid != null && obsoletesSid.getValue() != null && !obsoletesSid.getValue().trim().equals("")) {
2015
	                            if(sid.getValue().equals(obsoletesSid.getValue())) {
2016
	                                pass = true;// the i of rule C
2017
	                            }
2018
	                        }
2019
	                    } else {
2020
	                        throw new ServiceFailure(serviceFailureCode, "Can't find the system metadata for the pid "+sysmeta.getObsoletes().getValue()+
2021
	                                                                       " which is the value of the obsoletes. So we can't check if the sid " +sid.getValue()+" is legitimate ");
2022
	                    }
2023
	                }
2024
	                if(!pass) {
2025
	                    // the sid doesn't match the sid of the obsoleting identifier. So we check the obsoletedBy
2026
	                    if(sysmeta.getObsoletedBy() != null) {
2027
	                        SystemMetadata obsoletedBySysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(sysmeta.getObsoletedBy());
2028
	                        if(obsoletedBySysmeta != null) {
2029
	                            Identifier obsoletedBySid = obsoletedBySysmeta.getSeriesId();
2030
	                            if(obsoletedBySid != null && obsoletedBySid.getValue() != null && !obsoletedBySid.getValue().trim().equals("")) {
2031
	                                if(sid.getValue().equals(obsoletedBySid.getValue())) {
2032
	                                    pass = true;// the ii of the rule C
2033
	                                }
2034
	                            }
2035
	                        } else {
2036
	                            throw new ServiceFailure(serviceFailureCode, "Can't find the system metadata for the pid "+sysmeta.getObsoletes().getValue() 
2037
	                                                                          +" which is the value of the obsoletedBy. So we can't check if the sid "+sid.getValue()+" is legitimate.");
2038
	                        }
2039
	                    }
2040
	                }
2041
	                if(!pass) {
2042
	                    throw new InvalidSystemMetadata(invalidSystemMetadataCode, "The series id "+sid.getValue()+
2043
	                            " in the system metadata exists in the system. And it doesn't match either previous object's sid or the next object's sid");
2044
	                }
2045
	            } else {
2046
	                pass = true; //Rule B
2047
	            }
2048
	        } catch (SQLException e) {
2049
	            throw new ServiceFailure(serviceFailureCode, "Can't determine if the sid in the system metadata is unique or not since "+e.getMessage());
2050
	        }
2051
	        
2052
	    } else {
2053
	        //no sid. Rule A.
2054
	        pass = true;
2055
	    }
2056
	    return pass;
2057
	    
2058
	}
1983 2059
}

Also available in: Unified diff