Revision 5332
Added by Matt Jones almost 14 years ago
CrudService.java | ||
---|---|---|
62 | 62 |
import org.jibx.runtime.BindingDirectory; |
63 | 63 |
import org.jibx.runtime.IBindingFactory; |
64 | 64 |
import org.jibx.runtime.IMarshallingContext; |
65 |
import org.jibx.runtime.IUnmarshallingContext; |
|
65 | 66 |
import org.jibx.runtime.JiBXException; |
66 | 67 |
|
67 | 68 |
import com.gc.iotools.stream.is.InputStreamFromOutputStream; |
... | ... | |
271 | 272 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
272 | 273 |
InvalidRequest, NotImplemented { |
273 | 274 |
|
274 |
// TODO: Look up ID of system metadata based on guid |
|
275 |
logMetacat.debug("CrudService.getSystemMetadata - for guid: " + guid.getValue()); |
|
276 |
|
|
277 |
// Retrieve the session information from the AuthToken |
|
278 |
// If the session is expired, then the user is 'public' |
|
279 |
final SessionData sessionData = getSessionData(token); |
|
280 |
|
|
281 |
// TODO: Check access control rules |
|
282 |
|
|
283 |
try { |
|
284 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
285 |
// This is a test id of an existing sysmeta document -- for temporary testing |
|
286 |
String testGuid = "autogen.20101192441566.1"; |
|
287 |
// TODO: Look up ID of system metadata based on guid |
|
275 | 288 |
// TODO: Initially from document, later from entry in table? |
276 |
|
|
277 |
// TODO: Read system metadata from disk and create SystemMetadata object |
|
278 |
// TODO: Follows same implementation plan as get() |
|
279 |
|
|
280 |
// TODO: return it |
|
281 |
throw new NotImplemented(1000, "This method not yet implemented."); |
|
289 |
// String localId = im.getLocalId(guid.getValue()); |
|
290 |
final String localId = im.getLocalId(testGuid); |
|
291 |
|
|
292 |
// Read system metadata from metacat's db |
|
293 |
final InputStreamFromOutputStream<String> objectStream = |
|
294 |
new InputStreamFromOutputStream<String>() { |
|
295 |
|
|
296 |
@Override |
|
297 |
public String produce(final OutputStream dataSink) throws Exception { |
|
298 |
try { |
|
299 |
handler.readFromMetacat(request.getRemoteAddr(), null, |
|
300 |
dataSink, localId, "xml", |
|
301 |
sessionData.getUserName(), |
|
302 |
sessionData.getGroupNames(), true, params); |
|
303 |
} catch (PropertyNotFoundException e) { |
|
304 |
throw new ServiceFailure(1030, e.getMessage()); |
|
305 |
} catch (ClassNotFoundException e) { |
|
306 |
throw new ServiceFailure(1030, e.getMessage()); |
|
307 |
} catch (IOException e) { |
|
308 |
throw new ServiceFailure(1030, e.getMessage()); |
|
309 |
} catch (SQLException e) { |
|
310 |
throw new ServiceFailure(1030, e.getMessage()); |
|
311 |
} catch (McdbException e) { |
|
312 |
throw new ServiceFailure(1030, e.getMessage()); |
|
313 |
} catch (ParseLSIDException e) { |
|
314 |
throw new NotFound(1020, e.getMessage()); |
|
315 |
} catch (InsufficientKarmaException e) { |
|
316 |
throw new NotAuthorized(1000, "Not authorized for get()."); |
|
317 |
} |
|
318 |
|
|
319 |
return "Completed"; |
|
320 |
} |
|
321 |
}; |
|
322 |
|
|
323 |
// Deserialize the xml to create a SystemMetadata object |
|
324 |
SystemMetadata sysmeta = deserializeSystemMetadata(objectStream); |
|
325 |
return sysmeta; |
|
326 |
|
|
327 |
} catch (McdbDocNotFoundException e) { |
|
328 |
throw new NotFound(1000, e.getMessage()); |
|
329 |
} |
|
282 | 330 |
} |
283 | 331 |
|
284 | 332 |
public Identifier update(AuthToken token, Identifier guid, |
... | ... | |
483 | 531 |
handler.handleInsertOrUpdateAction(request.getRemoteAddr(), response, |
484 | 532 |
pw, params, sessionData.getUserName(), |
485 | 533 |
sessionData.getGroupNames()); |
486 |
logMetacat.debug(new String(output.toByteArray())); |
|
534 |
String outputS = new String(output.toByteArray()); |
|
535 |
logMetacat.debug("CrudService.insertDocument - Metacat returned: " + outputS); |
|
536 |
// if (!(outputS.indexOf("<success>") > 0 && outputS.indexOf(localId) > 0)) { |
|
537 |
// throw new ServiceFailure(1190, outputS); |
|
538 |
// } |
|
487 | 539 |
logMetacat.debug("Finsished inserting xml document."); |
488 | 540 |
} |
489 | 541 |
|
490 |
private ByteArrayOutputStream serializeSystemMetadata(SystemMetadata sysmeta)
|
|
542 |
public static ByteArrayOutputStream serializeSystemMetadata(SystemMetadata sysmeta)
|
|
491 | 543 |
throws ServiceFailure { |
492 | 544 |
IBindingFactory bfact; |
493 | 545 |
ByteArrayOutputStream sysmetaOut = null; |
... | ... | |
502 | 554 |
|
503 | 555 |
return sysmetaOut; |
504 | 556 |
} |
557 |
|
|
558 |
public static SystemMetadata deserializeSystemMetadata(InputStream xml) |
|
559 |
throws ServiceFailure { |
|
560 |
try { |
|
561 |
IBindingFactory bfact = BindingDirectory.getFactory(SystemMetadata.class); |
|
562 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
|
563 |
SystemMetadata sysmeta = (SystemMetadata) uctx.unmarshalDocument(xml, null); |
|
564 |
return sysmeta; |
|
565 |
} catch (JiBXException e) { |
|
566 |
throw new ServiceFailure(1190, "Failed to serialize and insert SystemMetadata: " + e.getMessage()); |
|
567 |
} |
|
568 |
} |
|
505 | 569 |
} |
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.