Project

General

Profile

« Previous | Next » 

Revision 9032

Added by Jing Tao about 10 years ago

Modified the get method to handle the sid in the v2 api.

View differences:

src/edu/ucsb/nceas/metacat/dataone/v1/MNodeService.java
24 24
package edu.ucsb.nceas.metacat.dataone.v1;
25 25

  
26 26
import java.io.InputStream;
27
import java.sql.SQLException;
27 28
import java.util.Date;
28 29

  
29 30
import javax.servlet.http.HttpServletRequest;
......
62 63
import org.dataone.service.types.v1_1.QueryEngineList;
63 64
import org.dataone.service.util.TypeMarshaller;
64 65

  
66
import edu.ucsb.nceas.metacat.IdentifierManager;
67

  
65 68
/**
66 69
 * Represents Metacat's implementation of the DataONE Member Node 
67 70
 * service API, v1. Methods typically pass through to the current 
......
270 273
	@Override
271 274
	public InputStream get(Identifier pid) throws InvalidToken, NotAuthorized,
272 275
			NotImplemented, ServiceFailure, NotFound, InsufficientResources {
276
	    boolean exists = false;
277
	    try {
278
	        exists = IdentifierManager.getInstance().systemMetadataPIDExists(pid);
279
	    } catch (SQLException e) {
280
	        throw new ServiceFailure("1030", "The object specified by "+ pid.getValue()+
281
                    " couldn't be identified if it exists at this node since "+e.getMessage());
282
	    }
283
	    if(!exists) {
284
	        //the v1 method only handles a pid.
285
	        throw new NotFound("1020", "The object specified by "+pid.getValue()+" does not exist at this node");
286
	    }
273 287
		return impl.get(null, pid);
274 288
	}
275 289

  
......
278 292
	public InputStream get(Session session, Identifier pid) throws InvalidToken,
279 293
			NotAuthorized, NotImplemented, ServiceFailure, NotFound,
280 294
			InsufficientResources {
295
	    boolean exists = false;
296
        try {
297
            exists = IdentifierManager.getInstance().systemMetadataPIDExists(pid);
298
        } catch (SQLException e) {
299
            throw new ServiceFailure("1030", "The object specified by "+ pid.getValue()+
300
                    " couldn't be identified if it exists at this node since "+e.getMessage());
301
        }
302
        if(!exists) {
303
            //the v1 method only handles a pid.
304
            throw new NotFound("1020", "The object specified by "+pid.getValue()+" does not exist at this node");
305
        }
281 306
		return impl.get(session, pid);
282 307
	}
283 308

  
src/edu/ucsb/nceas/metacat/dataone/v1/CNodeService.java
24 24
package edu.ucsb.nceas.metacat.dataone.v1;
25 25

  
26 26
import java.io.InputStream;
27
import java.sql.SQLException;
27 28
import java.util.Date;
28 29

  
29 30
import javax.servlet.http.HttpServletRequest;
......
70 71
import org.dataone.service.types.v1_1.QueryEngineList;
71 72
import org.dataone.service.util.TypeMarshaller;
72 73

  
74
import edu.ucsb.nceas.metacat.IdentifierManager;
75

  
73 76
/**
74 77
 * Represents Metacat's implementation of the DataONE Coordinating Node service
75 78
 * API. Methods implement the various CN* interfaces, and methods common to both
......
205 208
	@Override
206 209
	public InputStream get(Identifier pid) throws InvalidToken,
207 210
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
211
	    boolean exists = false;
212
        try {
213
            exists = IdentifierManager.getInstance().systemMetadataPIDExists(pid);
214
        } catch (SQLException e) {
215
            throw new ServiceFailure("1030", "The object specified by "+ pid.getValue()+
216
                    " couldn't be identified if it exists at this node since "+e.getMessage());
217
        }
218
        if(!exists) {
219
          //the v1 method only handles a pid.
220
            throw new NotFound("1020", "The object specified by "+pid.getValue()+" does not exist at this node");
221
        }
208 222
		return impl.get(null, pid);
209 223
	}
210 224

  
......
212 226
	@Deprecated
213 227
	public InputStream get(Session session, Identifier pid) throws InvalidToken,
214 228
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
229
	    boolean exists = false;
230
        try {
231
            exists = IdentifierManager.getInstance().systemMetadataPIDExists(pid);
232
        } catch (SQLException e) {
233
            throw new ServiceFailure("1030", "The object specified by "+ pid.getValue()+
234
                    " couldn't be identified if it exists at this node since "+e.getMessage());
235
        }
236
        if(!exists) {
237
          //the v1 method only handles a pid.
238
            throw new NotFound("1020", "The object specified by "+pid.getValue()+" does not exist at this node");
239
        }
215 240
		return impl.get(session, pid);
216 241
	}
217 242

  
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
561 561
    throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
562 562
    NotImplemented {
563 563
    
564
    try {
565
        //determine if the given pid is a sid or not.
566
        if(IdentifierManager.getInstance().systemMetadataSIDExists(pid)) {
567
            try {
568
                //set the header pid for the sid if the identifier is a sid.
569
                pid = IdentifierManager.getInstance().getHeadPID(pid);
570
            } catch (SQLException sqle) {
571
                throw new ServiceFailure("1030", "The current pid associated with the sid "+ pid.getValue()+
572
                        " couldn't be identified at this node since "+sqle.getMessage());
573
            }
574
            
575
        }
576
    } catch (SQLException e) {
577
        throw new ServiceFailure("1030", "The object specified by "+ pid.getValue()+
578
                " couldn't be identified at this node since "+e.getMessage());
579
    }
580
    
564 581
    InputStream inputStream = null; // bytes to be returned
565 582
    handler = new MetacatHandler(new Timer());
566 583
    boolean allowed = false;
src/edu/ucsb/nceas/metacat/IdentifierManager.java
980 980
    }
981 981
    
982 982
    /**
983
     * Check if the specified sid object exists on the serial id field on the system metadata table
984
     * @param sid
985
     * @return true if it exists; false otherwise.
986
     * @throws SQLException
987
     */
988
    public boolean systemMetadataSIDExists(Identifier sid) throws SQLException {
989
        if (sid != null && sid.getValue() != null && !sid.getValue().trim().equals("")) {
990
            return systemMetadataSIDExists(sid.getValue());
991
        } else {
992
            return false;
993
        }
994
    }
995
    
996
    /**
983 997
     * Check if the specified sid exists on the serial id field on the system metadata table
984 998
     * @param id
985 999
     * @return true if it exists; false otherwise.
986 1000
     */
987 1001
    public boolean systemMetadataSIDExists(String sid) throws SQLException {
988 1002
        boolean exists = false;
1003
        logMetacat.debug("Check if the  sid: " + sid +" exists on the series_id field of the system metadata table.");
989 1004
        if(sid != null && !sid.trim().equals("")) {
990
            logMetacat.debug("Check if the  sid: " + sid +" exists on the series_id field of the system metadata table.");
991 1005
            String sql = "select guid from systemMetadata where series_id = ?";
992 1006
            DBConnection dbConn = null;
993 1007
            int serialNumber = -1;
......
1016 1030
        return exists;
1017 1031
    }
1018 1032
    
1033
    /**
1034
     * Determine if the specified identifier object exists or not.
1035
     * @param pid - the specified identifier
1036
     * @return true if it is exists.
1037
     * @throws SQLException
1038
     * @throws NullPointerException
1039
     */
1040
    public boolean systemMetadataPIDExists(Identifier pid) throws SQLException {
1041
        if (pid != null && pid.getValue() != null && !pid.getValue().trim().equals("")) {
1042
            return systemMetadataPIDExists(pid.getValue());
1043
        } else {
1044
            return false;
1045
        }
1046
    }
1047
    
1019 1048
    public boolean systemMetadataPIDExists(String guid) throws SQLException {
1020 1049
		logMetacat.debug("looking up system metadata for guid " + guid);
1021 1050
		boolean exists = false;
1022 1051
		String query = "select guid from systemmetadata where guid = ?";
1023

  
1024 1052
		DBConnection dbConn = null;
1025 1053
		int serialNumber = -1;
1026
		try {
1027
			// Get a database connection from the pool
1028
			dbConn = DBConnectionPool.getDBConnection("IdentifierManager.systemMetadataExisits");
1029
			serialNumber = dbConn.getCheckOutSerialNumber();
1054
		if(guid != null && !guid.trim().equals("")) {
1055
		    try {
1056
	            // Get a database connection from the pool
1057
	            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.systemMetadataExisits");
1058
	            serialNumber = dbConn.getCheckOutSerialNumber();
1030 1059

  
1031
			// Execute the insert statement
1032
			PreparedStatement stmt = dbConn.prepareStatement(query);
1033
			stmt.setString(1, guid);
1034
			ResultSet rs = stmt.executeQuery();
1035
			if (rs.next()) {
1036
				exists = true;
1037
			}
1060
	            // Execute the insert statement
1061
	            PreparedStatement stmt = dbConn.prepareStatement(query);
1062
	            stmt.setString(1, guid);
1063
	            ResultSet rs = stmt.executeQuery();
1064
	            if (rs.next()) {
1065
	                exists = true;
1066
	            }
1038 1067

  
1039
		} catch (SQLException e) {
1040
			logMetacat.error("Error while looking up the system metadata: "
1041
					+ e.getMessage());
1042
			throw e;
1043
		} finally {
1044
			// Return database connection to the pool
1045
			DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1068
	        } catch (SQLException e) {
1069
	            logMetacat.error("Error while looking up the system metadata: "
1070
	                    + e.getMessage());
1071
	            throw e;
1072
	        } finally {
1073
	            // Return database connection to the pool
1074
	            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1075
	        }
1046 1076
		}
1047

  
1048 1077
		return exists;
1049 1078
	}
1050 1079
    

Also available in: Unified diff