Revision 6604
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java | ||
---|---|---|
80 | 80 |
import org.jibx.runtime.JiBXException; |
81 | 81 |
import org.xml.sax.SAXException; |
82 | 82 |
|
83 |
import edu.ucsb.nceas.metacat.dataone.CNodeService; |
|
83 | 84 |
import edu.ucsb.nceas.metacat.dataone.MNodeService; |
84 | 85 |
|
85 | 86 |
/** |
... | ... | |
110 | 111 |
* create() - POST /d1/mn/object/PID |
111 | 112 |
* update() - PUT /d1/mn/object/PID |
112 | 113 |
* delete() - DELETE /d1/mn/object/PID |
114 |
* systemMetadataChanged() - POST /dirtyMeta/PID |
|
113 | 115 |
* |
114 | 116 |
* MNReplication |
115 | 117 |
* replicate() - POST /d1/mn/replicate |
118 |
* getReplica() - GET /d1/mn/replica |
|
116 | 119 |
* |
117 | 120 |
* ****************** |
118 | 121 |
* @author leinfelder |
... | ... | |
123 | 126 |
// MN-specific API Resources |
124 | 127 |
protected static final String RESOURCE_MONITOR = "monitor"; |
125 | 128 |
protected static final String RESOURCE_REPLICATE = "replicate"; |
129 |
protected static final String RESOURCE_REPLICAS = "replica"; |
|
126 | 130 |
protected static final String RESOURCE_NODE = "node"; |
127 | 131 |
protected static final String RESOURCE_ERROR = "error"; |
132 |
protected static final String RESOURCE_META_CHANGED = "dirtyMeta"; |
|
128 | 133 |
|
129 | 134 |
/** |
130 | 135 |
* Initializes new instance by setting servlet context,request and response |
... | ... | |
256 | 261 |
syncError(); |
257 | 262 |
status = true; |
258 | 263 |
} |
264 |
} else if (resource.startsWith(RESOURCE_META_CHANGED)) { |
|
265 |
// system metadata changed |
|
266 |
if (httpVerb == POST) { |
|
267 |
extra = parseTrailing(resource, RESOURCE_META_CHANGED); |
|
268 |
systemMetadataChanged(extra); |
|
269 |
status = true; |
|
270 |
} |
|
271 |
} else if (resource.startsWith(RESOURCE_REPLICAS)) { |
|
272 |
// get replica |
|
273 |
if (httpVerb == GET) { |
|
274 |
extra = parseTrailing(resource, RESOURCE_REPLICAS); |
|
275 |
getReplica(extra); |
|
276 |
status = true; |
|
277 |
} |
|
259 | 278 |
} |
260 | 279 |
|
261 | 280 |
if (!status) { |
... | ... | |
287 | 306 |
} |
288 | 307 |
} |
289 | 308 |
|
309 |
|
|
290 | 310 |
/** |
311 |
* Handles notification of system metadata changes for the given identifier |
|
312 |
* |
|
313 |
* @param id the identifier for the object |
|
314 |
* @throws InvalidToken |
|
315 |
* @throws InvalidRequest |
|
316 |
* @throws NotAuthorized |
|
317 |
* @throws ServiceFailure |
|
318 |
* @throws NotImplemented |
|
319 |
*/ |
|
320 |
private void systemMetadataChanged(String id) |
|
321 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, |
|
322 |
InvalidToken { |
|
323 |
|
|
324 |
long serialVersion = 0L; |
|
325 |
String serialVersionStr = null; |
|
326 |
Date dateSysMetaLastModified = null; |
|
327 |
String dateSysMetaLastModifiedStr = null; |
|
328 |
Identifier pid = new Identifier(); |
|
329 |
pid.setValue(id); |
|
330 |
|
|
331 |
// get the serialVersion |
|
332 |
try { |
|
333 |
serialVersionStr = params.get("serialVersion")[0]; |
|
334 |
serialVersion = new Long(serialVersionStr).longValue(); |
|
335 |
|
|
336 |
} catch (NullPointerException e) { |
|
337 |
String msg = "The 'serialVersion' must be provided as a parameter and was not."; |
|
338 |
logMetacat.error(msg); |
|
339 |
throw new InvalidRequest("1334", msg); |
|
340 |
|
|
341 |
} |
|
342 |
|
|
343 |
// get the dateSysMetaLastModified |
|
344 |
try { |
|
345 |
dateSysMetaLastModifiedStr = params.get("dateSysMetaLastModified")[0]; |
|
346 |
dateSysMetaLastModified = DateTimeMarshaller.deserializeDateToUTC(dateSysMetaLastModifiedStr); |
|
347 |
|
|
348 |
} catch (NullPointerException e) { |
|
349 |
String msg = |
|
350 |
"The 'dateSysMetaLastModified' must be provided as a " + |
|
351 |
"parameter and was not, or was an invalid representation of the timestamp."; |
|
352 |
logMetacat.error(msg); |
|
353 |
throw new InvalidRequest("1334", msg); |
|
354 |
|
|
355 |
} |
|
356 |
|
|
357 |
// call the service |
|
358 |
MNodeService.getInstance(request).systemMetadataChanged(session, pid, serialVersion, dateSysMetaLastModified); |
|
359 |
response.setStatus(200); |
|
360 |
} |
|
361 |
|
|
362 |
/** |
|
291 | 363 |
* Checks the access policy |
292 | 364 |
* @param id |
293 | 365 |
* @return |
... | ... | |
539 | 611 |
response.setStatus(200); |
540 | 612 |
|
541 | 613 |
} |
542 |
|
|
614 |
|
|
543 | 615 |
/** |
616 |
* Handle the getReplica action for the MN |
|
617 |
* @param id the identifier for the object |
|
618 |
* @throws NotFound |
|
619 |
* @throws ServiceFailure |
|
620 |
* @throws NotImplemented |
|
621 |
* @throws NotAuthorized |
|
622 |
* @throws InvalidToken |
|
623 |
* @throws InvalidRequest |
|
624 |
*/ |
|
625 |
private void getReplica(String id) |
|
626 |
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented, |
|
627 |
ServiceFailure, NotFound { |
|
628 |
|
|
629 |
Identifier pid = new Identifier(); |
|
630 |
pid.setValue(id); |
|
631 |
OutputStream out = null; |
|
632 |
InputStream dataBytes = null; |
|
633 |
|
|
634 |
try { |
|
635 |
// call the service |
|
636 |
dataBytes = MNodeService.getInstance(request).getReplica(session, pid); |
|
637 |
|
|
638 |
response.setContentType("application/octet-stream"); |
|
639 |
response.setStatus(200); |
|
640 |
out = response.getOutputStream(); |
|
641 |
// write the object to the output stream |
|
642 |
IOUtils.copyLarge(dataBytes, out); |
|
643 |
|
|
644 |
} catch (IOException e) { |
|
645 |
String msg = "There was an error writing the output: " + e.getMessage(); |
|
646 |
logMetacat.error(msg); |
|
647 |
throw new ServiceFailure("2181", msg); |
|
648 |
|
|
649 |
} |
|
650 |
|
|
651 |
} |
|
652 |
|
|
653 |
/** |
|
544 | 654 |
* Get the Node information |
545 | 655 |
* |
546 | 656 |
* @throws JiBXException |
Also available in: Unified diff
Fix getReplica() handling code for getReplica() and systemMetadataChanged(). Calls to getReplica() in MNode were calling get(), so the lack of resource handling was being missed.