Project

General

Profile

« Previous | Next » 

Revision 6188

implement registerSystemMetadata

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
66 66
import org.dataone.service.types.SubjectList;
67 67
import org.dataone.service.types.SystemMetadata;
68 68

  
69
import edu.ucsb.nceas.metacat.EventLog;
70
import edu.ucsb.nceas.metacat.IdentifierManager;
71
import edu.ucsb.nceas.metacat.replication.ForceReplicationSystemMetadataHandler;
72

  
69 73
/**
70 74
 * Represents Metacat's implementation of the DataONE Coordinating Node 
71 75
 * service API. Methods implement the various CN* interfaces, and methods common
......
710 714
	 * @throws InvalidSystemMetadata
711 715
	 */
712 716
	@Override
713
	public boolean registerSystemMetadata(Session session, Identifier pid,
717
	public boolean registerSystemMetadata(Session session, Identifier guid,
714 718
	  SystemMetadata sysmeta) 
715 719
	  throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest, 
716 720
	  InvalidSystemMetadata {
717 721

  
718
		return false;
722
		// TODO: control who can call this?
723
	      if (session == null) {
724
	          //TODO: many of the thrown exceptions do not use the correct error codes
725
	          //check these against the docs and correct them
726
	          throw new NotAuthorized("4861", "No Session - could not authorize to registration." +
727
	                  "  If you are not logged in, please do so and retry the request.");
728
	      }
729
	      
730
	      // verify that guid == SystemMetadata.getIdentifier()
731
	      logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
732
	      if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
733
	          throw new InvalidRequest("4863", 
734
	              "GUID in method call (" + guid.getValue() + ") does not match GUID in system metadata (" +
735
	              sysmeta.getIdentifier().getValue() + ").");
736
	      }
737

  
738
	      logMetacat.debug("Checking if identifier exists...");
739
	      // Check that the identifier does not already exist
740
	      IdentifierManager im = IdentifierManager.getInstance();
741
	      if (im.identifierExists(guid.getValue())) {
742
	          throw new InvalidRequest("4863", 
743
	              "GUID is already in use by an existing object.");
744
	      }
745

  
746
	      // insert the system metadata into the object store
747
	      logMetacat.debug("Starting to insert SystemMetadata...");
748
	      sysmeta.setDateSysMetadataModified(new Date());
749
	      try {
750
			    IdentifierManager.getInstance().createSystemMetadata(sysmeta);
751
			    IdentifierManager.getInstance().updateSystemMetadata(sysmeta);
752
			    // force replication of this record
753
			    ForceReplicationSystemMetadataHandler forceReplication = 
754
			    	new ForceReplicationSystemMetadataHandler(guid.getValue(), null);
755
		    } catch (Exception e) {
756
	          throw new ServiceFailure("4862", "Error inserting system metadata: " + e.getClass() + ": " + e.getMessage());
757
		    }
758
	      
759
	      logMetacat.debug("Returning from registerSystemMetadata");
760
	      EventLog.getInstance().log(null, session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata");
761
	      return true;
719 762
	}
720 763

  
721 764
	/**

Also available in: Unified diff