Project

General

Profile

« Previous | Next » 

Revision 6337

use objectFormatIdentifier for listObjects()
remove provisional system metadata indicator - Metacat will not implement reserveIdentifier()

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
59 59
import org.dataone.service.types.Node;
60 60
import org.dataone.service.types.NodeReference;
61 61
import org.dataone.service.types.ObjectFormat;
62
import org.dataone.service.types.ObjectFormatIdentifier;
62 63
import org.dataone.service.types.ObjectList;
63 64
import org.dataone.service.types.Permission;
64 65
import org.dataone.service.types.Session;
......
618 619
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
619 620
		    Date startTime = sdf.parse("2010-01-01");
620 621
		    Date endTime = new Date();
621
		    ObjectFormat objectFormat = null;
622
		    ObjectFormatIdentifier objectFormatId = null;
622 623
		    boolean replicaStatus = false;
623 624
		    int start = 0;
624 625
		    int count = 1;
......
628 629
		    // now check that we have at least one
629 630
		    ObjectList objectList = 
630 631
		    	MNodeService.getInstance().listObjects(session, startTime, endTime, 
631
		    		objectFormat, replicaStatus, start, count);
632
		    			objectFormatId, replicaStatus, start, count);
632 633
		    assertNotNull(objectList);
633 634
		    assertTrue(objectList.getCount() == count);
634 635
		    assertTrue(objectList.getStart() == 0);
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
408 407
   date_uploaded DATE, -- the date/time the document was first submitted
409 408
   rights_holder VARCHAR2(250), --the user who has rights to the document, usually the first persons to upload it
410 409
   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
300 299
	date_uploaded TIMESTAMP, -- the date/time the document was first submitted
301 300
	rights_holder VARCHAR(250), --the user who has rights to the document, usually the first persons to upload it
302 301
	checksum VARCHAR(512), --the checksum of the doc using the given algorithm (see below)
......
317 316
 * ALTER TABLE systemMetadata DROP COLUMN rev;
318 317
 * ALTER TABLE systemMetadata ADD COLUMN replication_allowed boolean;
319 318
 * ALTER TABLE systemMetadata ADD COLUMN number_replicas INT8;
320
 * ALTER TABLE systemMetadata ADD COLUMN provisional boolean;
321 319
 */
322 320

  
323 321
/*
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
759 759
           
760 760
            ObjectList ol = 
761 761
            	MNodeService.getInstance().listObjects(session, startTime, endTime, 
762
                    objectFormat, replicaStatus, start, count);
762
                    objectFormat.getFmtid(), replicaStatus, start, count);
763 763
            
764 764
            out = response.getOutputStream();  
765 765
            response.setStatus(200);
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
1354 1354
                        " start: " + start + " count: " + count);
1355 1355
               
1356 1356
                ObjectList ol = MNodeService.getInstance().listObjects(session, startTime, endTime, 
1357
                        objectFormat, replicaStatus, start, count);
1357
                        objectFormat.getFmtid(), replicaStatus, start, count);
1358 1358
                
1359 1359
                StringReader sr = new StringReader(ol.toString());                
1360 1360
                out = response.getOutputStream();  
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
597 597
   */
598 598
  @Override
599 599
  public ObjectList listObjects(Session session, Date startTime, Date endTime,
600
    ObjectFormat objectFormat, Boolean replicaStatus, Integer start, Integer count)
600
    ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start, Integer count)
601 601
    throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure,
602 602
    InvalidToken {
603 603

  
......
605 605
    
606 606
    try {
607 607
	    objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
608
	        objectFormat, replicaStatus, start, count);
608
	        objectFormatId, replicaStatus, start, count);
609 609
    } catch (Exception e) {
610 610
		throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
611 611
	}
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
541 541
	      logMetacat.debug("Checking if identifier exists...");
542 542
	      // Check that the identifier does not already exist
543 543
	      if (IdentifierManager.getInstance().identifierExists(guid.getValue())) {
544
			// check if we reserved the id
545
			boolean reserved = IdentifierManager.getInstance().hasReservation(guid, session);
546
			// throw an exception if not
547
			if (!reserved) {
548 544
	          throw new InvalidRequest("4863", 
549 545
	              "GUID is already in use by an existing object.");
550
			}
546
			
551 547
	      }
552 548

  
553 549
	      // insert the system metadata into the object store
......
600 596
	  throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
601 597
	  NotImplemented, InvalidRequest {
602 598

  
603
		// generate a pid if not provided
604
		if (pid == null) {
605
			pid = new Identifier();
606
			// TODO: go to EZID
607
			StringBuffer sb = new StringBuffer();
608
			if (scope != null) {
609
				sb.append(scope);
610
				sb.append(".");
611
			}
612
			sb.append(System.currentTimeMillis());
613
			pid.setValue(sb.toString());
614
		}
615
		// does this identifier exist?
616
		if (IdentifierManager.getInstance().identifierExists(pid.getValue())) {
617
			// check if it was reserved already
618
			if (IdentifierManager.getInstance().hasReservation(pid, session)) {
619
				throw new IdentifierNotUnique("4210", "Identifier already reserved: " + pid.getValue());
620
			}
621
			throw new IdentifierNotUnique("4210", "Identifier already exists: " + pid.getValue());
622
		}
623
		
624
		// if we got this far, save it
625
		SystemMetadata provisoinalSystemMetadata = new SystemMetadata();
626
		provisoinalSystemMetadata.setIdentifier(pid);
627
		provisoinalSystemMetadata.setRightsHolder(session.getSubject());
628
		provisoinalSystemMetadata.setSubmitter(session.getSubject());
629
		provisoinalSystemMetadata.setDateSysMetadataModified(new Date());
630
		provisoinalSystemMetadata.setDateUploaded(new Date());
631
		provisoinalSystemMetadata.setSize(0);
632
		try {
633
			IdentifierManager.getInstance().createSystemMetadata(provisoinalSystemMetadata);
634
			IdentifierManager.getInstance().setProvisional(pid.getValue(), true);
635
		} catch (McdbDocNotFoundException e) {
636
			throw new ServiceFailure("4210", e.getMessage());
637
		}
638
		
639
		return pid;
599
		throw new NotImplemented("4191", "reserveIdentifier not implemented on this node");
640 600
	}
641 601

  
642 602
	/**
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
173 173
    logMetacat.debug("Checking if identifier exists...");
174 174
    // Check that the identifier does not already exist
175 175
    if (IdentifierManager.getInstance().identifierExists(pid.getValue())) {
176
    	// check if we reserved the id
177
    	boolean reserved = IdentifierManager.getInstance().hasReservation(pid, session);
178
    	// throw an exception if not
179
    	if (!reserved) {
180 176
	    	throw new IdentifierNotUnique("1120", 
181 177
			          "The requested identifier " + pid.getValue() +
182 178
			          " is already used by another object and" +
183 179
			          "therefore can not be used for this object. Clients should choose" +
184 180
			          "a new identifier that is unique and retry the operation or " +
185 181
			          "use CN_crud.reserveIdentifier() to reserve one.");
186
    	}
182
    	
187 183
    }
188 184

  
189 185
    // check for permission
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
535 535
    	ObjectList objectList = null;
536 536
        try {
537 537
    	    objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime,
538
    	              objectFormat, replicaStatus, start, count);
538
    	              objectFormat.getFmtid(), replicaStatus, start, count);
539 539
        } catch (Exception e) {
540 540
    		throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
541 541
    	}
src/edu/ucsb/nceas/metacat/IdentifierManager.java
782 782
        } catch (McdbDocNotFoundException e) {
783 783
        	// try system metadata only
784 784
        	try {
785
        		boolean provisional = false;
786
        		idExists = systemMetadataExisits(guid, provisional);
785
        		idExists = systemMetadataExisits(guid);
787 786
            } catch (McdbDocNotFoundException e2) {
788 787
            	idExists = false;
789 788
            }
......
791 790
        return idExists;
792 791
    }
793 792
    
794
    public boolean hasReservation(Identifier pid, Session session) {
795
    	// check if it was reserved
796
      	boolean reserved = false;
797
      	try {
798
    		// check that we reserved it
799
    		if (IdentifierManager.getInstance().systemMetadataExisits(pid.getValue(), true)) {    		    	
800
    	    	SystemMetadata provisionalMetadata = IdentifierManager.getInstance().getSystemMetadata(pid.getValue());
801
    	    	Subject rightsHolder = provisionalMetadata.getRightsHolder();
802
    	    	// TODO: check groups?
803
    	    	if (session.getSubject().equals(rightsHolder)) {
804
    	    		reserved = true;
805
    	    	}
806
    		}
807
    	} catch (McdbDocNotFoundException e) {
808
    		reserved = false;
809
    	}
810
    	return reserved;
811
      }
812
    
813 793
    /**
814 794
     * 
815 795
     * @param guid
......
918 898
        return guid;
919 899
    }
920 900
    
921
    public boolean systemMetadataExisits(String guid, boolean provisional)
901
    public boolean systemMetadataExisits(String guid)
922 902
			throws McdbDocNotFoundException {
923 903
		logMetacat.debug("looking up system metadata for guid " + guid);
924 904
		boolean exists = false;
925
		String query = "select guid from systemmetadata where guid = ? and provisional = ?";
905
		String query = "select guid from systemmetadata where guid = ?";
926 906

  
927 907
		DBConnection dbConn = null;
928 908
		int serialNumber = -1;
......
934 914
			// Execute the insert statement
935 915
			PreparedStatement stmt = dbConn.prepareStatement(query);
936 916
			stmt.setString(1, guid);
937
			stmt.setBoolean(2, provisional);
938 917
			ResultSet rs = stmt.executeQuery();
939 918
			if (rs.next()) {
940 919
				exists = true;
......
965 944
    public void createSystemMetadata(SystemMetadata sysmeta) throws McdbDocNotFoundException
966 945
    {
967 946
    	String guid = sysmeta.getIdentifier().getValue();
968
    	// remove any provisional records -- it is the responsibility of the caller to check this
969
    	try {
970
	    	if (systemMetadataExisits(guid, true)) {
971
	    		deleteSystemMetadata(guid);
972
	    	}
973
    	} catch (McdbDocNotFoundException e) {
974
			// ignore
975
		}
976
    	// insert the true record
977
        insertSystemMetadata(guid, false);
947
    	// insert the record
948
        insertSystemMetadata(guid);
949
        // update with the values
978 950
        updateSystemMetadata(sysmeta);
979 951
    }
980 952
        
......
1089 1061
        }
1090 1062
    }
1091 1063
    
1092
    public void setProvisional(String guid, boolean provisional) {
1093
        DBConnection dbConn = null;
1094
        int serialNumber = -1;
1095
        
1096
        try {
1097
            // Get a database connection from the pool
1098
            dbConn = 
1099
                DBConnectionPool.getDBConnection("IdentifierManager.setProvisional");
1100
            serialNumber = dbConn.getCheckOutSerialNumber();
1101

  
1102
            // Execute the insert statement
1103
            String query = "update " + TYPE_SYSTEM_METADATA + 
1104
                " set provisional = ? where guid = ?";
1105
            PreparedStatement stmt = dbConn.prepareStatement(query);
1106
            
1107
            //data values
1108
            stmt.setBoolean(1, provisional);
1109
            //where clause
1110
            stmt.setString(2, guid);
1111
            logMetacat.debug("stmt: " + stmt.toString());
1112
            //execute
1113
            int rows = stmt.executeUpdate();
1114

  
1115
            stmt.close();
1116
        } catch (SQLException e) {
1117
            e.printStackTrace();
1118
            logMetacat.error("setProvisional: SQL error while creating a mapping to the system metadata identifier: " 
1119
                    + e.getMessage());
1120
        } finally {
1121
            // Return database connection to the pool
1122
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1123
        }
1124
    }
1125
    
1126 1064
    private void insertSystemMetadataProvenance(String guid, String relationship, List<String> targetGuids)
1127 1065
    {
1128 1066
        DBConnection dbConn = null;
......
1525 1463
     * @throws PropertyNotFoundException 
1526 1464
     */
1527 1465
    public ObjectList querySystemMetadata(Date startTime, Date endTime, 
1528
            ObjectFormat objectFormat, boolean replicaStatus, int start, int count) throws SQLException, PropertyNotFoundException, ServiceException
1466
            ObjectFormatIdentifier objectFormatId, boolean replicaStatus, int start, int count) throws SQLException, PropertyNotFoundException, ServiceException
1529 1467
    {
1530 1468
        ObjectList ol = new ObjectList();
1531 1469
        int total = 0;
......
1556 1494
                f2 = true;
1557 1495
            }
1558 1496
            
1559
            if (objectFormat != null) {
1497
            if (objectFormatId != null) {
1560 1498
                if (!f1 && !f2) {
1561 1499
                    sql += " where object_format = ?";
1562 1500
                }
......
1583 1521
            if (f1 && f2 && f3) {
1584 1522
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1585 1523
                stmt.setTimestamp(2, new Timestamp(endTime.getTime()));
1586
                stmt.setString(3, objectFormat.getFmtid().getValue());
1524
                stmt.setString(3, objectFormatId.getValue());
1587 1525
            }
1588 1526
            else if (f1 && f2 && !f3) {
1589 1527
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
......
1591 1529
            }
1592 1530
            else if (f1 && !f2 && f3) {
1593 1531
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1594
                stmt.setString(2, objectFormat.getFmtid().getValue());
1532
                stmt.setString(2, objectFormatId.getValue());
1595 1533
            }
1596 1534
            else if (f1 && !f2 && !f3) {
1597 1535
                stmt.setTimestamp(1, new Timestamp(startTime.getTime()));
1598 1536
            }
1599 1537
            else if (!f1 && f2 && f3) {
1600 1538
                stmt.setTimestamp(1, new Timestamp(endTime.getTime()));
1601
                stmt.setString(2, objectFormat.getFmtid().getValue());
1539
                stmt.setString(2, objectFormatId.getValue());
1602 1540
            }
1603 1541
            else if (!f1 && !f2 && f3) {
1604
                stmt.setString(1, objectFormat.getFmtid().getValue());
1542
                stmt.setString(1, objectFormatId.getValue());
1605 1543
            }
1606 1544
            else if (!f1 && f2 && !f3) {
1607 1545
                stmt.setTimestamp(1, new Timestamp(endTime.getTime()));
......
1753 1691
     * create the systemmetadata record
1754 1692
     * @param guid
1755 1693
     */
1756
    private void insertSystemMetadata(String guid, boolean provisional)
1694
    private void insertSystemMetadata(String guid)
1757 1695
    {        
1758 1696
        
1759 1697
        int serialNumber = -1;
......
1765 1703
            serialNumber = dbConn.getCheckOutSerialNumber();
1766 1704

  
1767 1705
            // Execute the insert statement
1768
            String query = "insert into " + TYPE_SYSTEM_METADATA + " (guid, provisional) values (?, ?)";
1706
            String query = "insert into " + TYPE_SYSTEM_METADATA + " (guid) values (?)";
1769 1707
            PreparedStatement stmt = dbConn.prepareStatement(query);
1770 1708
            stmt.setString(1, guid);
1771
            stmt.setBoolean(2, provisional);
1772 1709
            logMetacat.debug("system metadata query: " + stmt.toString());
1773 1710
            int rows = stmt.executeUpdate();
1774 1711

  

Also available in: Unified diff