Index: src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java	(revision 6119)
+++ src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java	(revision 6120)
@@ -74,6 +74,7 @@
 import edu.ucsb.nceas.metacat.MetaCatServlet;
 import edu.ucsb.nceas.metacat.MetacatHandler;
 import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
+import edu.ucsb.nceas.metacat.dataone.CNCoreImpl;
 import edu.ucsb.nceas.metacat.dataone.CrudService;
 import edu.ucsb.nceas.metacat.dataone.HealthService;
 import edu.ucsb.nceas.metacat.properties.PropertyService;
@@ -324,7 +325,7 @@
                     }
                 } else if (resource.equals(RESOURCE_META)) {
                     System.out.println("Using resource 'meta'");
-                    if(params != null && params.get(FUNCTION_KEYWORD) != null &&
+                    if (params != null && params.get(FUNCTION_KEYWORD) != null &&
                             params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA))
                     { 
                         status = true;
@@ -336,8 +337,19 @@
                         {
                             objectId = request.getPathInfo().substring(1);
                         }
-                        getSystemMetadataObject(objectId);
-                        status = true;
+                        
+                        // get
+                        if (httpVerb == GET) {
+	                        getSystemMetadataObject(objectId);
+	                        status = true;
+                        }
+                        
+                        // post to register system metadata
+                        if (httpVerb == POST) {
+                        	registerSystemMetadata(objectId);
+                        	status = true;
+                        }
+                        
                     }
 
                 } else if (resource.equals(RESOURCE_OBJECTS)) {
@@ -1985,4 +1997,147 @@
         return sm;
     }
 
+    /**
+     * Register System Metadata without data or metadata object
+     * @param pid identifier for System Metadata entry
+     */
+	private void registerSystemMetadata(String pid) {
+		logMetacat.debug("Entering registerSystemMetadata: " + pid);
+		OutputStream out = null;
+		try {
+			out = response.getOutputStream();
+			response.setStatus(200);
+			response.setContentType("text/xml");
+		} catch (IOException e1) {
+			logMetacat.error("Could not get the output stream for writing in putObject");
+		}
+		try {
+
+			// Read the incoming data from its Mime Multipart encoding
+			logMetacat.debug("Disassembling MIME multipart form");
+			InputStream sysmeta = null;
+			Map<String, List<String>> multipartparams;
+
+			try {
+
+				// handle MMP inputs
+				File tmpDir = getTempDirectory();
+
+				logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath());
+				MultipartRequestResolver mrr = new MultipartRequestResolver(
+						tmpDir.getAbsolutePath(), 1000000000, 0);
+				MultipartRequest mr = mrr.resolveMultipart(request);
+				logMetacat.debug("resolved multipart request");
+				Map<String, File> files = mr.getMultipartFiles();
+				if (files == null) {
+					throw new ServiceFailure("1202",
+							"register meta must have multipart file with name 'sysmeta'");
+				}
+				logMetacat.debug("got multipart files");
+
+				if (files.keySet() == null) {
+					logMetacat.error("No file keys in MMP request.");
+					throw new ServiceFailure(
+							"1202",
+							"No file keys found in MMP.  "
+									+ "register meta must have multipart file with name 'sysmeta'");
+				}
+
+				// for logging purposes, dump out the key-value pairs that
+				// constitute the request
+				// 3 types exist: request params, multipart params, and
+				// multipart files
+				Iterator it = files.keySet().iterator();
+				logMetacat.debug("iterating through request parts: " + it);
+				while (it.hasNext()) {
+					String key = (String) it.next();
+					logMetacat.debug("files key: " + key);
+					logMetacat.debug("files value: " + files.get(key));
+				}
+
+				multipartparams = mr.getMultipartParameters();
+				it = multipartparams.keySet().iterator();
+				while (it.hasNext()) {
+					String key = (String) it.next();
+					logMetacat.debug("multipartparams key: " + key);
+					logMetacat.debug("multipartparams value: "
+							+ multipartparams.get(key));
+				}
+
+				it = params.keySet().iterator();
+				while (it.hasNext()) {
+					String key = (String) it.next();
+					logMetacat.debug("param key: " + key);
+					logMetacat.debug("param value: " + params.get(key));
+				}
+				logMetacat.debug("done iterating the request...");
+
+				File smFile = files.get("sysmeta");
+				if (smFile == null) {
+					throw new InvalidRequest("1102",
+							"Missing the required file-part 'sysmeta' from the multipart request.");
+				}
+				logMetacat.debug("smFile: " + smFile.getAbsolutePath());
+				sysmeta = new FileInputStream(smFile);
+
+			} catch (org.apache.commons.fileupload.FileUploadException fue) {
+				throw new ServiceFailure("1202", "Could not upload MMP files: "
+						+ fue.getMessage());
+			} catch (IOException ioe) {
+				throw new ServiceFailure("1202",
+						"IOException when processing Mime Multipart: "
+								+ ioe.getMessage());
+			} catch (Exception e) {
+				throw new ServiceFailure("1202", "Error handling MMP upload: "
+						+ e.getClass() + ": " + e.getMessage());
+			}
+
+			// Check if the objectId exists
+			IdentifierManager im = IdentifierManager.getInstance();
+			if (im.identifierExists(pid)) {
+				throw new IdentifierNotUnique("1000",
+						"Identifier is already in use: " + pid);
+			}
+
+			logMetacat.debug("Commence creation...");
+			IBindingFactory bfact = BindingDirectory
+					.getFactory(SystemMetadata.class);
+			IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
+			SystemMetadata systemMetadata = (SystemMetadata) uctx
+					.unmarshalDocument(sysmeta, null);
+
+			// TODO: get session
+			Session session = null;
+			Identifier guid = new Identifier();
+			guid.setValue(pid);
+			logMetacat.debug("registering system metadata with pid "
+					+ guid.getValue());
+			boolean result = CNCoreImpl.getInstance().registerSystemMetaData(
+					session, guid, systemMetadata);
+			serializeServiceType(Boolean.class, result, out);
+
+		} catch (NotAuthorized e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (ServiceFailure e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (IdentifierNotUnique e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (NotImplemented e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (InvalidRequest e) {
+			response.setStatus(500);
+			serializeException(e, out);
+		} catch (JiBXException e) {
+			response.setStatus(500);
+			e.printStackTrace(System.out);
+			InvalidSystemMetadata ism = new InvalidSystemMetadata("1080", e
+					.getMessage());
+			serializeException(ism, out);
+		}
+	}
+
 }
Index: src/edu/ucsb/nceas/metacat/dataone/CNCoreImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/dataone/CNCoreImpl.java	(nonexistent)
+++ src/edu/ucsb/nceas/metacat/dataone/CNCoreImpl.java	(revision 6120)
@@ -0,0 +1,152 @@
+/**
+ *  '$RCSfile$'
+ *  Copyright: 2000 Regents of the University of California and the
+ *              National Center for Ecological Analysis and Synthesis
+ *
+ *   '$Author$'
+ *     '$Date$'
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+package edu.ucsb.nceas.metacat.dataone;
+
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Timer;
+
+import org.apache.log4j.Logger;
+import org.dataone.service.cn.tier1.CNCore;
+import org.dataone.service.exceptions.IdentifierNotUnique;
+import org.dataone.service.exceptions.InsufficientResources;
+import org.dataone.service.exceptions.InvalidRequest;
+import org.dataone.service.exceptions.InvalidSystemMetadata;
+import org.dataone.service.exceptions.InvalidToken;
+import org.dataone.service.exceptions.NotAuthorized;
+import org.dataone.service.exceptions.NotFound;
+import org.dataone.service.exceptions.NotImplemented;
+import org.dataone.service.exceptions.ServiceFailure;
+import org.dataone.service.exceptions.UnsupportedType;
+import org.dataone.service.types.Event;
+import org.dataone.service.types.Identifier;
+import org.dataone.service.types.Log;
+import org.dataone.service.types.NodeList;
+import org.dataone.service.types.ObjectFormat;
+import org.dataone.service.types.Session;
+import org.dataone.service.types.SystemMetadata;
+import org.joda.time.DateTime;
+
+import edu.ucsb.nceas.metacat.EventLog;
+import edu.ucsb.nceas.metacat.IdentifierManager;
+
+/**
+ * 
+ * Implements DataONE MemberNode CRUD API for Metacat. 
+ * 
+ * @author Matthew Jones
+ */
+public class CNCoreImpl implements CNCore
+{
+    private static CNCoreImpl instance = null;
+
+    private Logger logMetacat = null;
+        
+    /**
+     * singleton accessor
+     */
+    public static CNCoreImpl getInstance() 
+    {
+      if (instance == null) {
+        instance = new CNCoreImpl();
+      }
+      
+      return instance;
+    }
+    
+    /**
+     * Constructor, private for singleton access
+     */
+    private CNCoreImpl() {
+        logMetacat = Logger.getLogger(CNCoreImpl.class);
+        
+    }
+    
+    /**
+     * register System Metadata
+     */
+    public boolean registerSystemMetaData(Session session, Identifier guid,
+            SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
+            ServiceFailure, InvalidRequest {
+        logMetacat.debug("Starting CrudService.create()...");
+        
+        // TODO: control who can call this?
+        if (session == null) {
+            //TODO: many of the thrown exceptions do not use the correct error codes
+            //check these against the docs and correct them
+            throw new NotAuthorized("4861", "No Session - could not authorize to registration." +
+                    "  If you are not logged in, please do so and retry the request.");
+        }
+        
+        // verify that guid == SystemMetadata.getIdentifier()
+        logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + sysmeta.getIdentifier().getValue());
+        if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
+            throw new InvalidRequest("4863", 
+                "GUID in method call (" + guid.getValue() + ") does not match GUID in system metadata (" +
+                sysmeta.getIdentifier().getValue() + ").");
+        }
+
+        logMetacat.debug("Checking if identifier exists...");
+        // Check that the identifier does not already exist
+        IdentifierManager im = IdentifierManager.getInstance();
+        if (im.identifierExists(guid.getValue())) {
+            throw new InvalidRequest("4863", 
+                "GUID is already in use by an existing object.");
+        }
+
+        // insert the system metadata into the object store
+        logMetacat.debug("Starting to insert SystemMetadata...");
+        sysmeta.setDateSysMetadataModified(new Date());
+        try {
+			IdentifierManager.getInstance().createSystemMetadata(sysmeta);
+			IdentifierManager.getInstance().updateSystemMetadata(sysmeta);
+		} catch (Exception e) {
+            throw new ServiceFailure("4862", "Error inserting system metadata: " + e.getClass() + ": " + e.getMessage());
+		}
+        
+        logMetacat.debug("Returning from registerSystemMetadata");
+        EventLog.getInstance().log(null, session.getSubject().getValue(), guid.getValue(), "registerSystemMetadata");
+        return true;
+    }
+
+	@Override
+	public ObjectFormat getFormat(Identifier arg0) throws InvalidRequest,
+			ServiceFailure, NotFound, InsufficientResources, NotImplemented {
+		throw new NotImplemented("4845", "Not implemented");
+	}
+
+	@Override
+	public Log getLogRecords(DateTime arg0, DateTime arg1, Event arg2)
+			throws InvalidToken, InvalidRequest, ServiceFailure, NotAuthorized,
+			NotImplemented {
+		throw new NotImplemented("1461", "Not implemented");
+
+	}
+
+	@Override
+	public NodeList listNodes() throws NotImplemented, ServiceFailure {
+		throw new NotImplemented("4800", "Not implemented");
+
+	}
+}
+

Property changes on: src/edu/ucsb/nceas/metacat/dataone/CNCoreImpl.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
