Project

General

Profile

Revision 10106

Added by Jing Tao almost 5 years ago

Add methods to check if there are circular obsoletes/obsoletedBy chains in the mn.updateSystemmetadata method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
1790 1790
                          " already obsoletes the pid "+sysmeta.getObsoletes().getValue() +". You can't set the object "+pid.getValue()+" to obsolete the pid "+sysmeta.getObsoletes().getValue()+" again.");
1791 1791
              }
1792 1792
          }
1793
          
1793
          checkCircularObsoletesChain(sysmeta);
1794 1794
          if(currentSysmeta.getObsoletedBy() == null && sysmeta.getObsoletedBy() != null) {
1795 1795
              //we are setting a value to the obsoletedBy field, so we should make sure that the no another object obsoletes the pid we are updating. 
1796 1796
              String obsoletedBy = existsInObsoletedBy(sysmeta.getObsoletedBy());
......
1799 1799
                          " already is obsoleted by the pid "+sysmeta.getObsoletedBy().getValue() +". You can't set the pid "+pid.getValue()+" to be obsoleted by the pid "+sysmeta.getObsoletedBy().getValue()+" again.");
1800 1800
              }
1801 1801
          }
1802
          checkCircularObsoletedByChain(sysmeta);
1802 1803
      }
1803 1804
      
1804 1805
      // do the actual update
......
1920 1921
	        }
1921 1922
	    }
1922 1923
	}
1924
	
1925
	
1926
	/**
1927
	 * Try to check the scenario of a circular obsoletes chain: 
1928
	 * A obsoletes B
1929
	 * B obsoletes C
1930
	 * C obsoletes A
1931
	 * @param sys
1932
	 * @throws InvalidRequest
1933
	 */
1934
	private void checkCircularObsoletesChain(SystemMetadata sys) throws InvalidRequest {
1935
	    if(sys != null && sys.getObsoletes() != null && sys.getObsoletes().getValue() != null && !sys.getObsoletes().getValue().trim().equals("")) {
1936
	        logMetacat.debug("D1NodeService.checkCircularObsoletesChain - the object "+sys.getIdentifier().getValue() +" obsoletes "+sys.getObsoletes().getValue());
1937
	        if(sys.getObsoletes().getValue().equals(sys.getIdentifier().getValue())) {
1938
	            // the obsoletes field points to itself and creates a circular chain
1939
	            throw new InvalidRequest("4869", "The obsoletes field and identifier of the system metadata has the same value "+sys.getObsoletes().getValue()+
1940
	                    ". This creates a circular chain and it is illegal.");
1941
	        } else {
1942
	            Vector <Identifier> pidList = new Vector<Identifier>();
1943
	            pidList.add(sys.getIdentifier());
1944
	            SystemMetadata obsoletesSym = HazelcastService.getInstance().getSystemMetadataMap().get(sys.getObsoletes());
1945
	            while (obsoletesSym != null && obsoletesSym.getObsoletes() != null && obsoletesSym.getObsoletes().getValue() != null && !obsoletesSym.getObsoletes().getValue().trim().equals("")) {
1946
	                pidList.add(obsoletesSym.getIdentifier());
1947
	                logMetacat.debug("D1NodeService.checkCircularObsoletesChain - the object "+obsoletesSym.getIdentifier().getValue() +" obsoletes "+obsoletesSym.getObsoletes().getValue());
1948
	                /*for(Identifier id: pidList) {
1949
	                    logMetacat.debug("D1NodeService.checkCircularObsoletesChain - the pid in the chanin"+id.getValue());
1950
	                }*/
1951
	                if(pidList.contains(obsoletesSym.getObsoletes())) {
1952
	                    logMetacat.error("D1NodeService.checkCircularObsoletesChain - when Metacat updated the system metadata of object "+sys.getIdentifier().getValue()+", it found the obsoletes field value "+sys.getObsoletes().getValue()+
1953
	                            " in its new system metadata creating a circular chain at the object "+obsoletesSym.getObsoletes().getValue()+". This is illegal");
1954
	                    throw new InvalidRequest("4869", "When Metacat updated the system metadata of object "+sys.getIdentifier().getValue()+", it found the obsoletes field value "+sys.getObsoletes().getValue()+
1955
                                " in its new system metadata creating a circular chain at the object "+obsoletesSym.getObsoletes().getValue()+". This is illegal");
1956
	                } else {
1957
	                    obsoletesSym = HazelcastService.getInstance().getSystemMetadataMap().get(obsoletesSym.getObsoletes());
1958
	                }
1959
	            }
1960
	        }
1961
	    }
1962
	}
1963
	
1964
	
1965
	/**
1966
     * Try to check the scenario of a circular obsoletedBy chain: 
1967
     * A obsoletedBy B
1968
     * B obsoletedBy C
1969
     * C obsoletedBy A
1970
     * @param sys
1971
     * @throws InvalidRequest
1972
     */
1973
    private void checkCircularObsoletedByChain(SystemMetadata sys) throws InvalidRequest {
1974
        if(sys != null && sys.getObsoletedBy() != null && sys.getObsoletedBy().getValue() != null && !sys.getObsoletedBy().getValue().trim().equals("")) {
1975
            logMetacat.debug("D1NodeService.checkCircularObsoletedByChain - the object "+sys.getIdentifier().getValue() +" is obsoletedBy "+sys.getObsoletedBy().getValue());
1976
            if(sys.getObsoletedBy().getValue().equals(sys.getIdentifier().getValue())) {
1977
                // the obsoletedBy field points to itself and creates a circular chain
1978
                throw new InvalidRequest("4869", "The obsoletedBy field and identifier of the system metadata has the same value "+sys.getObsoletedBy().getValue()+
1979
                        ". This creates a circular chain and it is illegal.");
1980
            } else {
1981
                Vector <Identifier> pidList = new Vector<Identifier>();
1982
                pidList.add(sys.getIdentifier());
1983
                SystemMetadata obsoletedBySym = HazelcastService.getInstance().getSystemMetadataMap().get(sys.getObsoletedBy());
1984
                while (obsoletedBySym != null && obsoletedBySym.getObsoletedBy() != null && obsoletedBySym.getObsoletedBy().getValue() != null && !obsoletedBySym.getObsoletedBy().getValue().trim().equals("")) {
1985
                    pidList.add(obsoletedBySym.getIdentifier());
1986
                    logMetacat.debug("D1NodeService.checkCircularObsoletedByChain - the object "+obsoletedBySym.getIdentifier().getValue() +" is obsoletedBy "+obsoletedBySym.getObsoletedBy().getValue());
1987
                    /*for(Identifier id: pidList) {
1988
                        logMetacat.debug("D1NodeService.checkCircularObsoletedByChain - the pid in the chanin"+id.getValue());
1989
                    }*/
1990
                    if(pidList.contains(obsoletedBySym.getObsoletedBy())) {
1991
                        logMetacat.error("D1NodeService.checkCircularObsoletedByChain - When Metacat updated the system metadata of object "+sys.getIdentifier().getValue()+", it found the obsoletedBy field value "+sys.getObsoletedBy().getValue()+
1992
                                " in its new system metadata creating a circular chain at the object "+obsoletedBySym.getObsoletedBy().getValue()+". This is illegal");
1993
                        throw new InvalidRequest("4869",  "When Metacat updated the system metadata of object "+sys.getIdentifier().getValue()+", it found the obsoletedBy field value "+sys.getObsoletedBy().getValue()+
1994
                                " in its new system metadata creating a circular chain at the object "+obsoletedBySym.getObsoletedBy().getValue()+". This is illegal");
1995
                    } else {
1996
                        obsoletedBySym = HazelcastService.getInstance().getSystemMetadataMap().get(obsoletedBySym.getObsoletedBy());
1997
                    }
1998
                }
1999
            }
2000
        }
2001
    }
1923 2002
  
1924 2003
  /**
1925 2004
   * Given a Permission, returns a list of all permissions that it encompasses

Also available in: Unified diff