Revision 9230
Added by Jing Tao over 9 years ago
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
52 | 52 |
import org.dataone.service.types.v1.ReplicationPolicy; |
53 | 53 |
import org.dataone.service.types.v1.ReplicationStatus; |
54 | 54 |
import org.dataone.service.types.v1.Subject; |
55 |
import org.dataone.service.types.v2.MediaType; |
|
56 |
import org.dataone.service.types.v2.MediaTypeProperty; |
|
55 | 57 |
import org.dataone.service.types.v2.SystemMetadata; |
56 | 58 |
|
57 | 59 |
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessAccess; |
... | ... | |
107 | 109 |
return self; |
108 | 110 |
} |
109 | 111 |
|
110 |
public SystemMetadata asSystemMetadata(Date dateUploaded, String rightsHolder, |
|
112 |
/*public SystemMetadata asSystemMetadata(Date dateUploaded, String rightsHolder,
|
|
111 | 113 |
String checksum, String checksumAlgorithm, String originMemberNode, |
112 | 114 |
String authoritativeMemberNode, Date dateModified, String submitter, |
113 | 115 |
String guid, String fmtidStr, BigInteger size, BigInteger serialVersion) { |
... | ... | |
153 | 155 |
sysMeta.setSerialVersion(serialVersion); |
154 | 156 |
|
155 | 157 |
return sysMeta; |
156 |
} |
|
158 |
}*/
|
|
157 | 159 |
|
158 | 160 |
/** |
159 | 161 |
* return a hash of all of the info that is in the systemmetadata table |
160 | 162 |
* @param localId |
161 | 163 |
* @return |
162 | 164 |
*/ |
163 |
public Hashtable<String, String> getSystemMetadataInfo(String localId) |
|
165 |
/*public Hashtable<String, String> getSystemMetadataInfo(String localId)
|
|
164 | 166 |
throws McdbDocNotFoundException |
165 | 167 |
{ |
166 | 168 |
try |
... | ... | |
236 | 238 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
237 | 239 |
} |
238 | 240 |
return h; |
239 |
} |
|
241 |
}*/
|
|
240 | 242 |
|
241 | 243 |
/** |
242 | 244 |
* return a hash of all of the info that is in the systemmetadata table |
... | ... | |
251 | 253 |
SystemMetadata sysMeta = new SystemMetadata(); |
252 | 254 |
String sql = "select guid, date_uploaded, rights_holder, checksum, checksum_algorithm, " + |
253 | 255 |
"origin_member_node, authoritive_member_node, date_modified, submitter, object_format, size, " + |
254 |
"replication_allowed, number_replicas, obsoletes, obsoleted_by, serial_version, archived, series_id " + |
|
256 |
"replication_allowed, number_replicas, obsoletes, obsoleted_by, serial_version, archived, series_id, file_name, media_type " +
|
|
255 | 257 |
"from systemmetadata where guid = ?"; |
256 | 258 |
DBConnection dbConn = null; |
257 | 259 |
int serialNumber = -1; |
... | ... | |
289 | 291 |
serialVersion = new BigInteger(rs.getString(16)); |
290 | 292 |
archived = new Boolean(rs.getBoolean(17)); |
291 | 293 |
String series_id = rs.getString(18); |
294 |
String file_name = rs.getString(19); |
|
295 |
String media_type = rs.getString(20); |
|
292 | 296 |
|
293 | 297 |
Identifier sysMetaId = new Identifier(); |
294 | 298 |
sysMetaId.setValue(guid); |
... | ... | |
338 | 342 |
seriesId.setValue(series_id); |
339 | 343 |
sysMeta.setSeriesId(seriesId); |
340 | 344 |
} |
345 |
if(file_name != null ) { |
|
346 |
sysMeta.setFileName(file_name); |
|
347 |
} |
|
348 |
|
|
349 |
if(media_type != null ) { |
|
350 |
MediaType mediaType = new MediaType(); |
|
351 |
mediaType.setName(media_type); |
|
352 |
// get media type properties from another table. |
|
353 |
String mediaTypePropertyQuery = "select name, value from smmediatypeproperties where guid = ?"; |
|
354 |
PreparedStatement stmt2 = dbConn.prepareStatement(mediaTypePropertyQuery); |
|
355 |
stmt2.setString(1, guid); |
|
356 |
ResultSet rs2 = stmt2.executeQuery(); |
|
357 |
while (rs2.next()) { |
|
358 |
String name = rs2.getString(1); |
|
359 |
String value = rs2.getString(2); |
|
360 |
MediaTypeProperty property = new MediaTypeProperty(); |
|
361 |
property.setName(name); |
|
362 |
property.setValue(value); |
|
363 |
mediaType.addProperty(property); |
|
364 |
} |
|
365 |
sysMeta.setMediaType(mediaType); |
|
366 |
rs2.close(); |
|
367 |
stmt2.close(); |
|
368 |
} |
|
341 | 369 |
stmt.close(); |
342 | 370 |
} |
343 | 371 |
else |
... | ... | |
1249 | 1277 |
String authoritativeMemberNode, long modifiedDate, String submitter, |
1250 | 1278 |
String guid, String objectFormat, BigInteger size, boolean archived, |
1251 | 1279 |
boolean replicationAllowed, int numberReplicas, String obsoletes, |
1252 |
String obsoletedBy, BigInteger serialVersion, String seriesId, DBConnection dbConn) throws SQLException { |
|
1253 |
|
|
1254 |
// Execute the insert statement |
|
1255 |
String query = "update " + TYPE_SYSTEM_METADATA + |
|
1256 |
" set (date_uploaded, rights_holder, checksum, checksum_algorithm, " + |
|
1257 |
"origin_member_node, authoritive_member_node, date_modified, " + |
|
1258 |
"submitter, object_format, size, archived, replication_allowed, number_replicas, " + |
|
1259 |
"obsoletes, obsoleted_by, serial_version, series_id) " + |
|
1260 |
"= (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) where guid = ?"; |
|
1261 |
PreparedStatement stmt = dbConn.prepareStatement(query); |
|
1280 |
String obsoletedBy, BigInteger serialVersion, String seriesId, |
|
1281 |
String fileName, MediaType mediaType, DBConnection dbConn) throws SQLException { |
|
1282 |
PreparedStatement stmt = null; |
|
1283 |
PreparedStatement stmt2 = null; |
|
1284 |
try { |
|
1285 |
dbConn.setAutoCommit(false); |
|
1286 |
// Execute the insert statement |
|
1287 |
String query = "update " + TYPE_SYSTEM_METADATA + |
|
1288 |
" set (date_uploaded, rights_holder, checksum, checksum_algorithm, " + |
|
1289 |
"origin_member_node, authoritive_member_node, date_modified, " + |
|
1290 |
"submitter, object_format, size, archived, replication_allowed, number_replicas, " + |
|
1291 |
"obsoletes, obsoleted_by, serial_version, series_id) " + |
|
1292 |
"= (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?) where guid = ?"; |
|
1293 |
stmt = dbConn.prepareStatement(query); |
|
1294 |
|
|
1295 |
//data values |
|
1296 |
stmt.setTimestamp(1, new java.sql.Timestamp(dateUploaded)); |
|
1297 |
stmt.setString(2, rightsHolder); |
|
1298 |
stmt.setString(3, checksum); |
|
1299 |
stmt.setString(4, checksumAlgorithm); |
|
1300 |
stmt.setString(5, originMemberNode); |
|
1301 |
stmt.setString(6, authoritativeMemberNode); |
|
1302 |
stmt.setTimestamp(7, new java.sql.Timestamp(modifiedDate)); |
|
1303 |
stmt.setString(8, submitter); |
|
1304 |
stmt.setString(9, objectFormat); |
|
1305 |
stmt.setString(10, size.toString()); |
|
1306 |
stmt.setBoolean(11, archived); |
|
1307 |
stmt.setBoolean(12, replicationAllowed); |
|
1308 |
stmt.setInt(13, numberReplicas); |
|
1309 |
stmt.setString(14, obsoletes); |
|
1310 |
stmt.setString(15, obsoletedBy); |
|
1311 |
stmt.setString(16, serialVersion.toString()); |
|
1312 |
stmt.setString(17, seriesId); |
|
1313 |
stmt.setString(18, fileName); |
|
1314 |
if (mediaType == null) { |
|
1315 |
stmt.setString(19, null); |
|
1316 |
} else { |
|
1317 |
stmt.setString(19, mediaType.getName()); |
|
1318 |
} |
|
1319 |
//where clause |
|
1320 |
stmt.setString(20, guid); |
|
1321 |
logMetacat.debug("stmt: " + stmt.toString()); |
|
1322 |
//execute |
|
1323 |
int rows = stmt.executeUpdate(); |
|
1324 |
|
|
1325 |
//insert media type properties into another table |
|
1326 |
if(mediaType != null && mediaType.getPropertyList() != null) { |
|
1327 |
String sql2 = "insert into smmediatypeproperties " + |
|
1328 |
"(guid, name, value) " + "values (?, ?, ?)"; |
|
1329 |
stmt2 = dbConn.prepareStatement(sql2); |
|
1330 |
for(MediaTypeProperty item : mediaType.getPropertyList()) { |
|
1331 |
if(item != null) { |
|
1332 |
String name = item.getName(); |
|
1333 |
String value = item.getValue(); |
|
1334 |
stmt2.setString(1, guid); |
|
1335 |
stmt2.setString(2, name); |
|
1336 |
stmt2.setString(3, value); |
|
1337 |
logMetacat.debug("insert media type properties query: " + stmt2.toString()); |
|
1338 |
int row =stmt2.executeUpdate(); |
|
1339 |
} |
|
1340 |
|
|
1341 |
} |
|
1342 |
} |
|
1343 |
dbConn.commit(); |
|
1344 |
dbConn.setAutoCommit(true); |
|
1345 |
} catch (Exception e) { |
|
1346 |
dbConn.rollback(); |
|
1347 |
dbConn.setAutoCommit(true); |
|
1348 |
throw new SQLException(e.getMessage()); |
|
1349 |
} finally { |
|
1350 |
if(stmt != null) { |
|
1351 |
stmt.close(); |
|
1352 |
} |
|
1353 |
if(stmt2 != null) { |
|
1354 |
stmt2.close(); |
|
1355 |
} |
|
1356 |
} |
|
1262 | 1357 |
|
1263 |
//data values |
|
1264 |
stmt.setTimestamp(1, new java.sql.Timestamp(dateUploaded)); |
|
1265 |
stmt.setString(2, rightsHolder); |
|
1266 |
stmt.setString(3, checksum); |
|
1267 |
stmt.setString(4, checksumAlgorithm); |
|
1268 |
stmt.setString(5, originMemberNode); |
|
1269 |
stmt.setString(6, authoritativeMemberNode); |
|
1270 |
stmt.setTimestamp(7, new java.sql.Timestamp(modifiedDate)); |
|
1271 |
stmt.setString(8, submitter); |
|
1272 |
stmt.setString(9, objectFormat); |
|
1273 |
stmt.setString(10, size.toString()); |
|
1274 |
stmt.setBoolean(11, archived); |
|
1275 |
stmt.setBoolean(12, replicationAllowed); |
|
1276 |
stmt.setInt(13, numberReplicas); |
|
1277 |
stmt.setString(14, obsoletes); |
|
1278 |
stmt.setString(15, obsoletedBy); |
|
1279 |
stmt.setString(16, serialVersion.toString()); |
|
1280 |
stmt.setString(17, seriesId); |
|
1281 |
|
|
1282 |
|
|
1283 |
//where clause |
|
1284 |
stmt.setString(18, guid); |
|
1285 |
logMetacat.debug("stmt: " + stmt.toString()); |
|
1286 |
//execute |
|
1287 |
int rows = stmt.executeUpdate(); |
|
1288 |
|
|
1289 |
stmt.close(); |
|
1290 | 1358 |
|
1291 | 1359 |
} |
1292 | 1360 |
|
... | ... | |
1405 | 1473 |
sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue(), |
1406 | 1474 |
sm.getSerialVersion(), |
1407 | 1475 |
sm.getSeriesId() == null ? null: sm.getSeriesId().getValue(), |
1476 |
sm.getFileName() == null ? null: sm.getFileName(), |
|
1477 |
sm.getMediaType() == null ? null: sm.getMediaType(), |
|
1408 | 1478 |
dbConn |
1409 | 1479 |
); |
1410 | 1480 |
|
... | ... | |
2059 | 2129 |
rows = stmt.executeUpdate(); |
2060 | 2130 |
stmt.close(); |
2061 | 2131 |
|
2132 |
// remove the smmediatypeproperties |
|
2133 |
query = "delete from smmediatypeproperties " + |
|
2134 |
"where guid = ?"; |
|
2135 |
stmt = dbConn.prepareStatement(query); |
|
2136 |
stmt.setString(1, guid); |
|
2137 |
logMetacat.debug("delete smmediatypeproperties: " + stmt.toString()); |
|
2138 |
rows = stmt.executeUpdate(); |
|
2139 |
stmt.close(); |
|
2140 |
|
|
2062 | 2141 |
// remove main system metadata entry |
2063 | 2142 |
query = "delete from " + TYPE_SYSTEM_METADATA + " where guid = ? "; |
2064 | 2143 |
stmt = dbConn.prepareStatement(query); |
Also available in: Unified diff
Add the code to read/write the new system metadata fields - file name, media type and media type properties into the db tables.