Revision 6297
Added by Chris Jones over 13 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
35 | 35 |
import java.util.Date; |
36 | 36 |
import java.util.Enumeration; |
37 | 37 |
import java.util.Map; |
38 |
import java.util.TimeZone; |
|
38 | 39 |
|
39 | 40 |
import javax.servlet.ServletContext; |
40 | 41 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
67 | 68 |
import org.dataone.service.types.NodeList; |
68 | 69 |
import org.dataone.service.types.NodeReference; |
69 | 70 |
import org.dataone.service.types.ObjectFormat; |
71 |
import org.dataone.service.types.ObjectFormatIdentifier; |
|
70 | 72 |
import org.dataone.service.types.ObjectList; |
71 | 73 |
import org.dataone.service.types.Permission; |
72 | 74 |
import org.dataone.service.types.Subject; |
... | ... | |
99 | 101 |
* isAuthorized() - GET /d1/mn/isAuthorized/PID |
100 | 102 |
* setAccessPolicy() - PUT /d1/mn/accessRules/PID |
101 | 103 |
* |
102 |
* MNStorage |
|
104 |
* MNStorage - DONE
|
|
103 | 105 |
* create() - POST /d1/mn/object/PID |
104 | 106 |
* update() - PUT /d1/mn/object/PID |
105 | 107 |
* delete() - DELETE /d1/mn/object/PID |
... | ... | |
119 | 121 |
protected static final String RESOURCE_NODE = "node"; |
120 | 122 |
protected static final String RESOURCE_ERROR = "error"; |
121 | 123 |
|
122 |
|
|
123 | 124 |
/** |
124 | 125 |
* Initializes new instance by setting servlet context,request and response |
125 | 126 |
* */ |
... | ... | |
332 | 333 |
* @throws IOException |
333 | 334 |
* @throws JiBXException |
334 | 335 |
*/ |
335 |
private boolean monitor(String pathInfo) throws NotFound, ParseException, NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType, IOException, JiBXException { |
|
336 |
private boolean monitor(String pathInfo) |
|
337 |
throws NotFound, ParseException, NotImplemented, ServiceFailure, |
|
338 |
NotAuthorized, InvalidRequest, InsufficientResources, UnsupportedType, |
|
339 |
IOException, JiBXException { |
|
336 | 340 |
logMetacat.debug("processing monitor request"); |
337 | 341 |
|
338 | 342 |
logMetacat.debug("verb is GET"); |
... | ... | |
369 | 373 |
|
370 | 374 |
} else if (pathInfo.toLowerCase().equals("event")) { |
371 | 375 |
logMetacat.debug("processing event request"); |
372 |
ObjectFormat format = null; |
|
373 |
Integer period = null; |
|
376 |
ObjectFormatIdentifier fmtid = null; |
|
377 |
String fromDateStr = null; |
|
378 |
Date fromDate = null; |
|
379 |
String toDateStr = null; |
|
380 |
Date toDate = null; |
|
374 | 381 |
String requestor = null; |
375 | 382 |
Subject subject = null; |
376 | 383 |
String eventName = null; |
377 | 384 |
Event event = null; |
378 | 385 |
|
379 |
if (params.containsKey("format")) { |
|
380 |
String f = params.get("format")[0]; |
|
381 |
format = ObjectFormatCache.getInstance().getFormat(f);
|
|
386 |
if (params.containsKey("formatId")) {
|
|
387 |
String f = params.get("formatId")[0];
|
|
388 |
fmtid = ObjectFormatCache.getInstance().getFormat(f).getFmtid();
|
|
382 | 389 |
} |
383 |
if (params.containsKey("period")) { |
|
384 |
String t = params.get("period")[0]; |
|
385 |
period = Integer.valueOf(t); |
|
390 |
|
|
391 |
if (params.containsKey("fromDate")) { |
|
392 |
fromDateStr = params.get("fromDate")[0]; |
|
393 |
fromDate = getDateAsUTC(fromDateStr); |
|
386 | 394 |
} |
395 |
|
|
396 |
if (params.containsKey("toDate")) { |
|
397 |
toDateStr = params.get("toDate")[0]; |
|
398 |
toDate = getDateAsUTC(toDateStr); |
|
399 |
} |
|
400 |
|
|
387 | 401 |
if (params.containsKey("requestor")) { |
388 | 402 |
requestor = params.get("requestor")[0]; |
389 | 403 |
subject = new Subject(); |
390 | 404 |
subject.setValue(requestor); |
391 | 405 |
} |
406 |
|
|
392 | 407 |
if (params.containsKey("event")) { |
393 | 408 |
eventName = params.get("event")[0]; |
394 | 409 |
event = Event.valueOf(eventName); |
395 | 410 |
} |
396 | 411 |
|
397 |
MonitorList monitorList = MNodeService.getInstance().getOperationStatistics(session, period, subject, event, format);
|
|
412 |
MonitorList monitorList = MNodeService.getInstance().getOperationStatistics(session, fromDate, toDate, subject, event, fmtid);
|
|
398 | 413 |
|
399 | 414 |
OutputStream out = response.getOutputStream(); |
400 | 415 |
response.setStatus(200); |
... | ... | |
409 | 424 |
return false; |
410 | 425 |
} |
411 | 426 |
|
412 |
/** |
|
427 |
/* |
|
428 |
* Parse an ISO8601 date string, returning a Date in UTC time if the string |
|
429 |
* ends in 'Z'. |
|
430 |
* |
|
431 |
* @param fromDateStr - the date string to be parsed |
|
432 |
* @return date - the date object represented by the string |
|
433 |
*/ |
|
434 |
private Date getDateAsUTC(String fromDateStr) |
|
435 |
throws ParseException { |
|
436 |
|
|
437 |
Date date = null; |
|
438 |
|
|
439 |
try { |
|
440 |
// try the expected date format |
|
441 |
// a date format for date string arguments |
|
442 |
DateFormat dateFormat = |
|
443 |
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); |
|
444 |
|
|
445 |
date = dateFormat.parse(fromDateStr); |
|
446 |
|
|
447 |
} catch (ParseException e) { |
|
448 |
// try the date with the UTC indicator |
|
449 |
DateFormat utcDateFormat = |
|
450 |
new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); |
|
451 |
utcDateFormat.setTimeZone(TimeZone.getTimeZone("GMT-0")); |
|
452 |
date = utcDateFormat.parse(fromDateStr); |
|
453 |
|
|
454 |
} |
|
455 |
|
|
456 |
return date; |
|
457 |
} |
|
458 |
|
|
459 |
/** |
|
413 | 460 |
* Calculate the checksum |
414 | 461 |
* @throws NotImplemented |
415 | 462 |
* @throws JiBXException |
Also available in: Unified diff
Modify monitor() to accept new parameters for getOperationStatisics() (fromDate, toDate) instead of 'period'. Added getDateAsUTC() to parse incoming fromDate and toDate parameter strings.