Project

General

Profile

« Previous | Next » 

Revision 9017

Added by Jing Tao over 9 years ago

1. In the identifierExists method, the code to check if the identifier exist on the serial-id fields of the system metadata table.
2. Fixed a bug on the identifierExists - it considered an identifier didn't exist when the determining process threw an exception.

View differences:

src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
350 350

  
351 351
    logMetacat.debug("Checking if identifier exists: " + pid.getValue());
352 352
    // Check that the identifier does not already exist
353
    if (IdentifierManager.getInstance().identifierExists(pid.getValue())) {
353
    boolean idExists = false;
354
    try {
355
        idExists = IdentifierManager.getInstance().identifierExists(pid.getValue());
356
    } catch (SQLException e) {
357
        throw new ServiceFailure("1190", 
358
                                "The requested identifier " + pid.getValue() +
359
                                " couldn't be determined if it is unique since : "+e.getMessage());
360
    }
361
    if (idExists) {
354 362
	    	throw new IdentifierNotUnique("1120", 
355 363
			          "The requested identifier " + pid.getValue() +
356 364
			          " is already used by another object and" +
src/edu/ucsb/nceas/metacat/IdentifierManager.java
766 766
     * @param guid the global identifier to look up
767 767
     * @return boolean true if the identifier exists
768 768
     */
769
    public boolean identifierExists(String guid)
769
    public boolean identifierExists(String guid) throws SQLException
770 770
    {
771 771
        boolean idExists = false;
772 772
        try {
......
776 776
            }
777 777
        } catch (McdbDocNotFoundException e) {
778 778
        	// try system metadata only
779
        	try {
780
        		idExists = systemMetadataExists(guid);
781
            } catch (Exception e2) {
782
            	idExists = false;
783
            }
779
        	    //this will check if the guid field on the system metadata table has the id
780
        		idExists = systemMetadataGUIDExists(guid);
781
        		if(!idExists) {
782
        		    //if the guid field of the system metadata table doesn't have the id,
783
        		    //we will check if the serial_id field of the system metadata table has it
784
        		    idExists=systemMetadataSIDExists(guid);
785
        		}
786
            
784 787
        }
785 788
        return idExists;
786 789
    }
......
967 970
     * @param id
968 971
     * @return true if it exists; false otherwise.
969 972
     */
970
    public boolean serialIdExists(String sid) throws SQLException {
973
    public boolean systemMetadataSIDExists(String sid) throws SQLException {
971 974
        boolean exists = false;
972 975
        if(sid != null && !sid.trim().equals("")) {
973 976
            logMetacat.debug("Check if the  sid: " + sid +" exists on the series_id field of the system metadata table.");
......
999 1002
        return exists;
1000 1003
    }
1001 1004
    
1002
    public boolean systemMetadataExists(String guid) throws SQLException {
1005
    public boolean systemMetadataGUIDExists(String guid) throws SQLException {
1003 1006
		logMetacat.debug("looking up system metadata for guid " + guid);
1004 1007
		boolean exists = false;
1005 1008
		String query = "select guid from systemmetadata where guid = ?";
......
1054 1057
        	dbConn.setAutoCommit(false);
1055 1058
        	
1056 1059
	    	// insert the record if needed
1057
        	if (!IdentifierManager.getInstance().systemMetadataExists(guid)) {
1060
        	if (!IdentifierManager.getInstance().systemMetadataGUIDExists(guid)) {
1058 1061
    	        insertSystemMetadata(guid, dbConn);
1059 1062
			}
1060 1063
	        // update with the values

Also available in: Unified diff