Revision 6120
Added by ben leinfelder almost 13 years ago
ResourceHandler.java | ||
---|---|---|
74 | 74 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
75 | 75 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
76 | 76 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
77 |
import edu.ucsb.nceas.metacat.dataone.CNCoreImpl; |
|
77 | 78 |
import edu.ucsb.nceas.metacat.dataone.CrudService; |
78 | 79 |
import edu.ucsb.nceas.metacat.dataone.HealthService; |
79 | 80 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
... | ... | |
324 | 325 |
} |
325 | 326 |
} else if (resource.equals(RESOURCE_META)) { |
326 | 327 |
System.out.println("Using resource 'meta'"); |
327 |
if(params != null && params.get(FUNCTION_KEYWORD) != null && |
|
328 |
if (params != null && params.get(FUNCTION_KEYWORD) != null &&
|
|
328 | 329 |
params.get(FUNCTION_KEYWORD)[0].equals(FUNCTION_NAME_GENERATE_MISSING_SYSTEM_METADATA)) |
329 | 330 |
{ |
330 | 331 |
status = true; |
... | ... | |
336 | 337 |
{ |
337 | 338 |
objectId = request.getPathInfo().substring(1); |
338 | 339 |
} |
339 |
getSystemMetadataObject(objectId); |
|
340 |
status = true; |
|
340 |
|
|
341 |
// get |
|
342 |
if (httpVerb == GET) { |
|
343 |
getSystemMetadataObject(objectId); |
|
344 |
status = true; |
|
345 |
} |
|
346 |
|
|
347 |
// post to register system metadata |
|
348 |
if (httpVerb == POST) { |
|
349 |
registerSystemMetadata(objectId); |
|
350 |
status = true; |
|
351 |
} |
|
352 |
|
|
341 | 353 |
} |
342 | 354 |
|
343 | 355 |
} else if (resource.equals(RESOURCE_OBJECTS)) { |
... | ... | |
1985 | 1997 |
return sm; |
1986 | 1998 |
} |
1987 | 1999 |
|
2000 |
/** |
|
2001 |
* Register System Metadata without data or metadata object |
|
2002 |
* @param pid identifier for System Metadata entry |
|
2003 |
*/ |
|
2004 |
private void registerSystemMetadata(String pid) { |
|
2005 |
logMetacat.debug("Entering registerSystemMetadata: " + pid); |
|
2006 |
OutputStream out = null; |
|
2007 |
try { |
|
2008 |
out = response.getOutputStream(); |
|
2009 |
response.setStatus(200); |
|
2010 |
response.setContentType("text/xml"); |
|
2011 |
} catch (IOException e1) { |
|
2012 |
logMetacat.error("Could not get the output stream for writing in putObject"); |
|
2013 |
} |
|
2014 |
try { |
|
2015 |
|
|
2016 |
// Read the incoming data from its Mime Multipart encoding |
|
2017 |
logMetacat.debug("Disassembling MIME multipart form"); |
|
2018 |
InputStream sysmeta = null; |
|
2019 |
Map<String, List<String>> multipartparams; |
|
2020 |
|
|
2021 |
try { |
|
2022 |
|
|
2023 |
// handle MMP inputs |
|
2024 |
File tmpDir = getTempDirectory(); |
|
2025 |
|
|
2026 |
logMetacat.debug("temp dir: " + tmpDir.getAbsolutePath()); |
|
2027 |
MultipartRequestResolver mrr = new MultipartRequestResolver( |
|
2028 |
tmpDir.getAbsolutePath(), 1000000000, 0); |
|
2029 |
MultipartRequest mr = mrr.resolveMultipart(request); |
|
2030 |
logMetacat.debug("resolved multipart request"); |
|
2031 |
Map<String, File> files = mr.getMultipartFiles(); |
|
2032 |
if (files == null) { |
|
2033 |
throw new ServiceFailure("1202", |
|
2034 |
"register meta must have multipart file with name 'sysmeta'"); |
|
2035 |
} |
|
2036 |
logMetacat.debug("got multipart files"); |
|
2037 |
|
|
2038 |
if (files.keySet() == null) { |
|
2039 |
logMetacat.error("No file keys in MMP request."); |
|
2040 |
throw new ServiceFailure( |
|
2041 |
"1202", |
|
2042 |
"No file keys found in MMP. " |
|
2043 |
+ "register meta must have multipart file with name 'sysmeta'"); |
|
2044 |
} |
|
2045 |
|
|
2046 |
// for logging purposes, dump out the key-value pairs that |
|
2047 |
// constitute the request |
|
2048 |
// 3 types exist: request params, multipart params, and |
|
2049 |
// multipart files |
|
2050 |
Iterator it = files.keySet().iterator(); |
|
2051 |
logMetacat.debug("iterating through request parts: " + it); |
|
2052 |
while (it.hasNext()) { |
|
2053 |
String key = (String) it.next(); |
|
2054 |
logMetacat.debug("files key: " + key); |
|
2055 |
logMetacat.debug("files value: " + files.get(key)); |
|
2056 |
} |
|
2057 |
|
|
2058 |
multipartparams = mr.getMultipartParameters(); |
|
2059 |
it = multipartparams.keySet().iterator(); |
|
2060 |
while (it.hasNext()) { |
|
2061 |
String key = (String) it.next(); |
|
2062 |
logMetacat.debug("multipartparams key: " + key); |
|
2063 |
logMetacat.debug("multipartparams value: " |
|
2064 |
+ multipartparams.get(key)); |
|
2065 |
} |
|
2066 |
|
|
2067 |
it = params.keySet().iterator(); |
|
2068 |
while (it.hasNext()) { |
|
2069 |
String key = (String) it.next(); |
|
2070 |
logMetacat.debug("param key: " + key); |
|
2071 |
logMetacat.debug("param value: " + params.get(key)); |
|
2072 |
} |
|
2073 |
logMetacat.debug("done iterating the request..."); |
|
2074 |
|
|
2075 |
File smFile = files.get("sysmeta"); |
|
2076 |
if (smFile == null) { |
|
2077 |
throw new InvalidRequest("1102", |
|
2078 |
"Missing the required file-part 'sysmeta' from the multipart request."); |
|
2079 |
} |
|
2080 |
logMetacat.debug("smFile: " + smFile.getAbsolutePath()); |
|
2081 |
sysmeta = new FileInputStream(smFile); |
|
2082 |
|
|
2083 |
} catch (org.apache.commons.fileupload.FileUploadException fue) { |
|
2084 |
throw new ServiceFailure("1202", "Could not upload MMP files: " |
|
2085 |
+ fue.getMessage()); |
|
2086 |
} catch (IOException ioe) { |
|
2087 |
throw new ServiceFailure("1202", |
|
2088 |
"IOException when processing Mime Multipart: " |
|
2089 |
+ ioe.getMessage()); |
|
2090 |
} catch (Exception e) { |
|
2091 |
throw new ServiceFailure("1202", "Error handling MMP upload: " |
|
2092 |
+ e.getClass() + ": " + e.getMessage()); |
|
2093 |
} |
|
2094 |
|
|
2095 |
// Check if the objectId exists |
|
2096 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
2097 |
if (im.identifierExists(pid)) { |
|
2098 |
throw new IdentifierNotUnique("1000", |
|
2099 |
"Identifier is already in use: " + pid); |
|
2100 |
} |
|
2101 |
|
|
2102 |
logMetacat.debug("Commence creation..."); |
|
2103 |
IBindingFactory bfact = BindingDirectory |
|
2104 |
.getFactory(SystemMetadata.class); |
|
2105 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
|
2106 |
SystemMetadata systemMetadata = (SystemMetadata) uctx |
|
2107 |
.unmarshalDocument(sysmeta, null); |
|
2108 |
|
|
2109 |
// TODO: get session |
|
2110 |
Session session = null; |
|
2111 |
Identifier guid = new Identifier(); |
|
2112 |
guid.setValue(pid); |
|
2113 |
logMetacat.debug("registering system metadata with pid " |
|
2114 |
+ guid.getValue()); |
|
2115 |
boolean result = CNCoreImpl.getInstance().registerSystemMetaData( |
|
2116 |
session, guid, systemMetadata); |
|
2117 |
serializeServiceType(Boolean.class, result, out); |
|
2118 |
|
|
2119 |
} catch (NotAuthorized e) { |
|
2120 |
response.setStatus(500); |
|
2121 |
serializeException(e, out); |
|
2122 |
} catch (ServiceFailure e) { |
|
2123 |
response.setStatus(500); |
|
2124 |
serializeException(e, out); |
|
2125 |
} catch (IdentifierNotUnique e) { |
|
2126 |
response.setStatus(500); |
|
2127 |
serializeException(e, out); |
|
2128 |
} catch (NotImplemented e) { |
|
2129 |
response.setStatus(500); |
|
2130 |
serializeException(e, out); |
|
2131 |
} catch (InvalidRequest e) { |
|
2132 |
response.setStatus(500); |
|
2133 |
serializeException(e, out); |
|
2134 |
} catch (JiBXException e) { |
|
2135 |
response.setStatus(500); |
|
2136 |
e.printStackTrace(System.out); |
|
2137 |
InvalidSystemMetadata ism = new InvalidSystemMetadata("1080", e |
|
2138 |
.getMessage()); |
|
2139 |
serializeException(ism, out); |
|
2140 |
} |
|
2141 |
} |
|
2142 |
|
|
1988 | 2143 |
} |
Also available in: Unified diff
include CNCore implementation - only registerSystemMetadata is implemented at the moment. also - updated d1 jar (0.6.2) should be used since that is where the method is defined.
would like to consider making ResourceHandler more modular - seems like it does A LOT of different things