Revision 5332
Added by Matt Jones almost 14 years ago
ResourceHandler.java | ||
---|---|---|
22 | 22 |
*/ |
23 | 23 |
package edu.ucsb.nceas.metacat.restservice; |
24 | 24 |
|
25 |
import java.io.ByteArrayOutputStream; |
|
25 | 26 |
import java.io.IOException; |
26 | 27 |
import java.io.InputStream; |
27 | 28 |
import java.io.OutputStream; |
... | ... | |
54 | 55 |
import org.dataone.service.types.SystemMetadata; |
55 | 56 |
import org.jibx.runtime.BindingDirectory; |
56 | 57 |
import org.jibx.runtime.IBindingFactory; |
58 |
import org.jibx.runtime.IMarshallingContext; |
|
57 | 59 |
import org.jibx.runtime.IUnmarshallingContext; |
58 | 60 |
import org.jibx.runtime.JiBXException; |
59 | 61 |
|
... | ... | |
190 | 192 |
* API Resources |
191 | 193 |
*/ |
192 | 194 |
private static final String RESOURCE_OBJECTS = "object"; |
195 |
private static final String RESOURCE_META = "/meta"; |
|
193 | 196 |
private static final String RESOURCE_SESSION = "session"; |
194 | 197 |
private static final String RESOURCE_IDENTIFIER = "identifier"; |
195 | 198 |
|
... | ... | |
299 | 302 |
logMetacat.debug("D1 Rest: Starting resource processing..."); |
300 | 303 |
loadSessionData(); |
301 | 304 |
|
305 |
boolean isSysmetaRequest = false; |
|
302 | 306 |
String objectId = request.getPathInfo(); |
303 |
if (objectId != null && objectId.length() > 1) |
|
307 |
if (objectId != null && objectId.length() > 1) {
|
|
304 | 308 |
objectId = request.getPathInfo().substring(1); //trim the slash |
309 |
|
|
310 |
// Check if this is a request for SystemMetadata |
|
311 |
// TODO: Note that this REST uri means that GUIDs can not contain the RESOURCE_META string |
|
312 |
int start = objectId.indexOf(RESOURCE_META); |
|
313 |
if (start >= 0) { |
|
314 |
logMetacat.debug("Pruning meta at start value: " + start); |
|
315 |
objectId = objectId.substring(0, start); |
|
316 |
logMetacat.debug("New objectId for meta is: " + objectId); |
|
317 |
isSysmetaRequest = true; |
|
318 |
} |
|
319 |
} |
|
305 | 320 |
logMetacat.debug("Processing objectId: " + objectId); |
306 | 321 |
logMetacat.debug("verb:" + httpVerb); |
307 | 322 |
|
308 | 323 |
logMetacat.debug("objectId:" + objectId); |
309 | 324 |
|
310 | 325 |
if (httpVerb == GET) { |
311 |
getObject(objectId); |
|
326 |
if (isSysmetaRequest) { |
|
327 |
getSystemMetadataObject(objectId); |
|
328 |
} else { |
|
329 |
getObject(objectId); |
|
330 |
} |
|
312 | 331 |
status = true; |
313 | 332 |
} else if (httpVerb == POST) { |
314 | 333 |
putObject(objectId, FUNCTION_NAME_INSERT); |
... | ... | |
482 | 501 |
} |
483 | 502 |
|
484 | 503 |
/** |
504 |
* Implements REST version of DataONE CRUD API --> getSystemMetadata |
|
505 |
* @param guid ID of data object to be read |
|
506 |
*/ |
|
507 |
private void getSystemMetadataObject(String guid) { |
|
508 |
CrudService cs = new CrudService(servletContext, request, response); |
|
509 |
AuthToken token = null; |
|
510 |
OutputStream out = null; |
|
511 |
try { |
|
512 |
out = response.getOutputStream(); |
|
513 |
Identifier id = new Identifier(); |
|
514 |
id.setValue(guid); |
|
515 |
SystemMetadata sysmeta = cs.getSystemMetadata(token, id); |
|
516 |
logMetacat.debug("Got sysmeta for: " + sysmeta.getIdentifier().getValue()); |
|
517 |
|
|
518 |
// Serialize and write it to the output stream |
|
519 |
try { |
|
520 |
IBindingFactory bfact = BindingDirectory.getFactory(SystemMetadata.class); |
|
521 |
IMarshallingContext mctx = bfact.createMarshallingContext(); |
|
522 |
mctx.marshalDocument(sysmeta, "UTF-8", null, out); |
|
523 |
} catch (JiBXException e) { |
|
524 |
throw new ServiceFailure(1190, "Failed to serialize SystemMetadata: " + e.getMessage()); |
|
525 |
} |
|
526 |
} catch (BaseException e) { |
|
527 |
serializeException(e, out); |
|
528 |
} catch (IOException e) { |
|
529 |
ServiceFailure sf = new ServiceFailure(1030, e.getMessage()); |
|
530 |
serializeException(sf, out); |
|
531 |
} finally { |
|
532 |
IOUtils.closeQuietly(out); |
|
533 |
} |
|
534 |
} |
|
535 |
|
|
536 |
/** |
|
485 | 537 |
* Earthgrid API > Query Service > Query Function : translates ecogrid query document to metacat query |
486 | 538 |
* then calls DBQuery > createResultDocument function and then again translate resultset to ecogrid resultset |
487 | 539 |
* |
Also available in: Unified diff
Added initial implementation of getSystemMetadata and its associated REST service. Current implementation is returning a hardcoded system metadata document -- need to look up the real document for each guid and return that.