Revision 5887
Added by berkley about 13 years ago
IdentifierManager.java | ||
---|---|---|
31 | 31 |
import java.sql.SQLException; |
32 | 32 |
|
33 | 33 |
import org.apache.log4j.Logger; |
34 |
import org.dataone.service.types.SystemMetadata; |
|
34 | 35 |
|
35 | 36 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
36 | 37 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
38 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
37 | 39 |
import edu.ucsb.nceas.metacat.util.DocumentUtil; |
38 | 40 |
|
39 | 41 |
/** |
... | ... | |
49 | 51 |
|
50 | 52 |
public static final String TYPE_SYSTEM_METADATA = "systemmetadata"; |
51 | 53 |
public static final String TYPE_IDENTIFIER = "identifier"; |
52 |
public static final String DATAONE_SM_DOCTYPE = "http://dataone.org/service/types/SystemMetadata/0.1";
|
|
54 |
public static String DATAONE_SM_DOCTYPE;
|
|
53 | 55 |
|
54 | 56 |
/** |
55 | 57 |
* The single instance of the manager that is always returned. |
... | ... | |
63 | 65 |
*/ |
64 | 66 |
private IdentifierManager() |
65 | 67 |
{ |
68 |
try |
|
69 |
{ |
|
70 |
DATAONE_SM_DOCTYPE = PropertyService.getProperty("crudService.listObjects.ReturnDoctype"); |
|
71 |
} |
|
72 |
catch(Exception e) |
|
73 |
{ |
|
74 |
throw new RuntimeException("Error getting System Metadata doctype from " + |
|
75 |
"the properties file. Please make sure crudService.listObjects.ReturnDoctype " + |
|
76 |
"exists in metacat.properties."); |
|
77 |
} |
|
66 | 78 |
} |
67 | 79 |
|
68 | 80 |
/** |
... | ... | |
491 | 503 |
} |
492 | 504 |
|
493 | 505 |
/** |
494 |
* insert a system metadata id for a local id |
|
506 |
* creates a mapping for a system metadata document, but DOES NOT add any |
|
507 |
* of the extra system metadata information to the table. You must call |
|
508 |
* insertAdditionalSystemMetadataFields to complete the entry |
|
495 | 509 |
* |
496 | 510 |
* @param guid the id to insert |
497 | 511 |
* @param localId the systemMetadata object to get the local id for |
... | ... | |
502 | 516 |
} |
503 | 517 |
|
504 | 518 |
/** |
519 |
* creates a system metadata mapping and adds additional fields from sysmeta |
|
520 |
* to the table for quick searching. |
|
521 |
* |
|
522 |
* @param guid the id to insert |
|
523 |
* @param localId the systemMetadata object to get the local id for |
|
524 |
*/ |
|
525 |
public void createSystemMetadataMapping(SystemMetadata sysmeta, String localId) |
|
526 |
{ |
|
527 |
createGenericMapping(sysmeta.getIdentifier().getValue(), localId, TYPE_SYSTEM_METADATA); |
|
528 |
insertAdditionalSystemMetadataFields(sysmeta); |
|
529 |
} |
|
530 |
|
|
531 |
/** |
|
505 | 532 |
* update a mapping |
506 | 533 |
* @param guid |
507 | 534 |
* @param localId |
... | ... | |
561 | 588 |
return this.getLocalId(guid, TYPE_SYSTEM_METADATA); |
562 | 589 |
} |
563 | 590 |
|
591 |
public void insertAdditionalSystemMetadataFields(long dateUploaded, String rightsHolder, |
|
592 |
String checksum, String checksumAlgorithm, String originMemberNode, |
|
593 |
String authoritativeMemberNode, long modifiedDate, String submitter, String guid) |
|
594 |
{ |
|
595 |
DBConnection dbConn = null; |
|
596 |
int serialNumber = -1; |
|
597 |
try { |
|
598 |
// Get a database connection from the pool |
|
599 |
dbConn = |
|
600 |
DBConnectionPool.getDBConnection("IdentifierManager.createMapping"); |
|
601 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
|
602 |
|
|
603 |
// Execute the insert statement |
|
604 |
String query = "update " + TYPE_SYSTEM_METADATA + |
|
605 |
" set (date_uploaded, rights_holder, checksum, checksum_algorithm, " + |
|
606 |
"origin_member_node, authoritive_member_node, date_modified, submitter) " + |
|
607 |
"= (?, ?, ?, ?, ?, ?, ?, ?) where guid = ?"; |
|
608 |
PreparedStatement stmt = dbConn.prepareStatement(query); |
|
609 |
|
|
610 |
//data values |
|
611 |
stmt.setTimestamp(1, new java.sql.Timestamp(dateUploaded)); |
|
612 |
stmt.setString(2, rightsHolder); |
|
613 |
stmt.setString(3, checksum); |
|
614 |
stmt.setString(4, checksumAlgorithm); |
|
615 |
stmt.setString(5, originMemberNode); |
|
616 |
stmt.setString(6, authoritativeMemberNode); |
|
617 |
stmt.setTimestamp(7, new java.sql.Timestamp(modifiedDate)); |
|
618 |
stmt.setString(8, submitter); |
|
619 |
//where clause |
|
620 |
stmt.setString(9, guid); |
|
621 |
System.out.println("stmt: " + stmt.toString()); |
|
622 |
//execute |
|
623 |
int rows = stmt.executeUpdate(); |
|
624 |
|
|
625 |
stmt.close(); |
|
626 |
} catch (SQLException e) { |
|
627 |
e.printStackTrace(); |
|
628 |
logMetacat.error("SQL error while creating a mapping to the system metadata identifier: " |
|
629 |
+ e.getMessage()); |
|
630 |
} catch (NumberFormatException e) { |
|
631 |
e.printStackTrace(); |
|
632 |
logMetacat.error("NumberFormat error while creating a mapping to the system metadata identifier: " |
|
633 |
+ e.getMessage()); |
|
634 |
} finally { |
|
635 |
// Return database connection to the pool |
|
636 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
|
637 |
} |
|
638 |
} |
|
639 |
|
|
564 | 640 |
/** |
641 |
* Insert the system metadata fields into the db |
|
642 |
* @param sm |
|
643 |
*/ |
|
644 |
public void insertAdditionalSystemMetadataFields(SystemMetadata sm) |
|
645 |
{ |
|
646 |
insertAdditionalSystemMetadataFields( |
|
647 |
sm.getDateUploaded().getTime(), |
|
648 |
sm.getRightsHolder().getValue(), |
|
649 |
sm.getChecksum().getValue(), |
|
650 |
sm.getChecksum().getAlgorithm().name(), |
|
651 |
sm.getOriginMemberNode().getValue(), |
|
652 |
sm.getAuthoritativeMemberNode().getValue(), |
|
653 |
sm.getDateSysMetadataModified().getTime(), |
|
654 |
sm.getSubmitter().getValue(), |
|
655 |
sm.getIdentifier().getValue()); |
|
656 |
} |
|
657 |
|
|
658 |
/** |
|
565 | 659 |
* return a localId based on a guid. The type can either be 'identifier' |
566 | 660 |
* to get an id from the identifier table or 'systemmetadata' to get |
567 | 661 |
* the identifier from the systemidentifier table |
... | ... | |
653 | 747 |
stmt.setString(1, guid); |
654 | 748 |
stmt.setString(2, docid); |
655 | 749 |
stmt.setInt(3, rev); |
750 |
System.out.println("generic mapping query: " + stmt.toString()); |
|
656 | 751 |
int rows = stmt.executeUpdate(); |
657 | 752 |
|
658 | 753 |
stmt.close(); |
659 | 754 |
} catch (SQLException e) { |
660 | 755 |
e.printStackTrace(); |
661 |
logMetacat.error("SQL error while creating a mapping to the system metadata identifier: "
|
|
756 |
logMetacat.warn("SQL error while creating a mapping to the system metadata identifier: "
|
|
662 | 757 |
+ e.getMessage()); |
663 | 758 |
} catch (NumberFormatException e) { |
664 | 759 |
e.printStackTrace(); |
Also available in: Unified diff
adding fields for additional system metadata info