Project

General

Profile

« Previous | Next » 

Revision 6277

allow for provisional SystemMetadata records (provisional=true)

View differences:

src/xmltables-oracle.sql
404 404
 */
405 405
CREATE TABLE systemMetadata (
406 406
   guid   VARCHAR2(2000),    -- the globally unique string identifier
407
   provisional boolean,	 -- for reserving IDs
407 408
   date_uploaded DATE, -- the date/time the document was first submitted
408 409
   rights_holder VARCHAR2(250), --the user who has rights to the document, usually the first persons to upload it
409 410
   checksum VARCHAR2(512), --the checksum of the doc using the given algorithm (see below)
src/xmltables-postgres.sql
296 296
 */
297 297
CREATE TABLE systemMetadata (
298 298
	guid   text,          -- the globally unique string identifier of the object that the system metadata describes
299
	provisional boolean, -- for reserved identifiers
299 300
	date_uploaded TIMESTAMP, -- the date/time the document was first submitted
300 301
	rights_holder VARCHAR(250), --the user who has rights to the document, usually the first persons to upload it
301 302
	checksum VARCHAR(512), --the checksum of the doc using the given algorithm (see below)
......
316 317
 * ALTER TABLE systemMetadata DROP COLUMN rev;
317 318
 * ALTER TABLE systemMetadata ADD COLUMN replication_allowed boolean;
318 319
 * ALTER TABLE systemMetadata ADD COLUMN number_replicas INT8;
320
 * ALTER TABLE systemMetadata ADD COLUMN provisional boolean;
319 321
 */
320 322

  
321 323
/*
src/edu/ucsb/nceas/metacat/IdentifierManager.java
51 51
import org.dataone.service.types.Replica;
52 52
import org.dataone.service.types.ReplicationPolicy;
53 53
import org.dataone.service.types.ReplicationStatus;
54
import org.dataone.service.types.Session;
54 55
import org.dataone.service.types.Subject;
55 56
import org.dataone.service.types.SystemMetadata;
56 57

  
......
779 780
        } catch (McdbDocNotFoundException e) {
780 781
        	// try system metadata only
781 782
        	try {
782
        		idExists = systemMetadataExisits(guid);
783
        		boolean provisional = false;
784
        		idExists = systemMetadataExisits(guid, provisional);
783 785
            } catch (McdbDocNotFoundException e2) {
784 786
            	idExists = false;
785 787
            }
......
787 789
        return idExists;
788 790
    }
789 791
    
792
    public boolean hasReservation(Identifier pid, Session session) {
793
    	// check if it was reserved
794
      	boolean reserved = false;
795
      	try {
796
    		// check that we reserved it
797
    		if (IdentifierManager.getInstance().systemMetadataExisits(pid.getValue(), true)) {    		    	
798
    	    	SystemMetadata provisionalMetadata = IdentifierManager.getInstance().getSystemMetadata(pid.getValue());
799
    	    	Subject rightsHolder = provisionalMetadata.getRightsHolder();
800
    	    	// TODO: check groups?
801
    	    	if (session.getSubject().equals(rightsHolder)) {
802
    	    		reserved = true;
803
    	    	}
804
    		}
805
    	} catch (McdbDocNotFoundException e) {
806
    		reserved = false;
807
    	}
808
    	return reserved;
809
      }
810
    
790 811
    /**
791 812
     * 
792 813
     * @param guid
......
895 916
        return guid;
896 917
    }
897 918
    
898
    public boolean systemMetadataExisits(String guid)
919
    public boolean systemMetadataExisits(String guid, boolean provisional)
899 920
			throws McdbDocNotFoundException {
900 921
		logMetacat.debug("looking up system metadata for guid " + guid);
901 922
		boolean exists = false;
902
		String query = "select guid from systemmetadata where guid = ?";
923
		String query = "select guid from systemmetadata where guid = ? and provisional = ?";
903 924

  
904 925
		DBConnection dbConn = null;
905 926
		int serialNumber = -1;
......
911 932
			// Execute the insert statement
912 933
			PreparedStatement stmt = dbConn.prepareStatement(query);
913 934
			stmt.setString(1, guid);
914

  
935
			stmt.setBoolean(2, provisional);
915 936
			ResultSet rs = stmt.executeQuery();
916 937
			if (rs.next()) {
917 938
				exists = true;
......
941 962
     */
942 963
    public void createSystemMetadata(SystemMetadata sysmeta) throws McdbDocNotFoundException
943 964
    {
944
        insertSystemMetadata(sysmeta.getIdentifier().getValue());
965
    	String guid = sysmeta.getIdentifier().getValue();
966
    	// remove any provisional records -- it is the responsibility of the caller to check this
967
    	if (systemMetadataExisits(guid, true)) {
968
    		deleteSystemMetadata(guid);
969
    	}
970
    	// insert the true record
971
        insertSystemMetadata(guid, false);
945 972
        updateSystemMetadata(sysmeta);
946 973
    }
947 974
        
......
1691 1718
     * create the systemmetadata record
1692 1719
     * @param guid
1693 1720
     */
1694
    public void insertSystemMetadata(String guid)
1721
    private void insertSystemMetadata(String guid, boolean provisional)
1695 1722
    {        
1696 1723
        
1697 1724
        int serialNumber = -1;
......
1703 1730
            serialNumber = dbConn.getCheckOutSerialNumber();
1704 1731

  
1705 1732
            // Execute the insert statement
1706
            String query = "insert into " + TYPE_SYSTEM_METADATA + " (guid) values (?)";
1733
            String query = "insert into " + TYPE_SYSTEM_METADATA + " (guid, provisional) values (?, ?)";
1707 1734
            PreparedStatement stmt = dbConn.prepareStatement(query);
1708 1735
            stmt.setString(1, guid);
1736
            stmt.setBoolean(2, provisional);
1709 1737
            logMetacat.debug("system metadata query: " + stmt.toString());
1710 1738
            int rows = stmt.executeUpdate();
1711 1739

  
1712 1740
            stmt.close();
1713 1741
        } catch (Exception e) {
1714 1742
            e.printStackTrace();
1715
            logMetacat.error("Error while creating " + TYPE_SYSTEM_METADATA + " record: " 
1716
                    + e.getMessage());
1743
            logMetacat.error("Error while creating " + TYPE_SYSTEM_METADATA + " record: " + guid, e );
1717 1744
        } finally {
1718 1745
            // Return database connection to the pool
1719 1746
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1720 1747
        }
1721 1748
    }
1749
    
1750
    private void deleteSystemMetadata(String guid)
1751
    {        
1752
        
1753
        int serialNumber = -1;
1754
        DBConnection dbConn = null;
1755
        try {
1756

  
1757
            // Get a database connection from the pool
1758
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.insertSystemMetadata");
1759
            serialNumber = dbConn.getCheckOutSerialNumber();
1760

  
1761
            // Execute the statement
1762
            String query = "delete from " + TYPE_SYSTEM_METADATA + " where guid = ? ";
1763
            PreparedStatement stmt = dbConn.prepareStatement(query);
1764
            stmt.setString(1, guid);
1765
            logMetacat.debug("delete system metadata: " + stmt.toString());
1766
            int rows = stmt.executeUpdate();
1767

  
1768
            stmt.close();
1769
        } catch (Exception e) {
1770
            e.printStackTrace();
1771
            logMetacat.error("Error while deleting " + TYPE_SYSTEM_METADATA + " record: " + guid, e );
1772
        } finally {
1773
            // Return database connection to the pool
1774
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1775
        }
1776
    }
1722 1777
}
1723 1778

  

Also available in: Unified diff