Revision 6332
Added by ben leinfelder almost 13 years ago
MNodeService.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
import org.apache.commons.io.IOUtils; |
35 | 35 |
import org.apache.log4j.Logger; |
36 |
import org.dataone.client.D1Client; |
|
37 |
import org.dataone.client.MNode; |
|
36 | 38 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
37 | 39 |
import org.dataone.service.exceptions.InsufficientResources; |
38 | 40 |
import org.dataone.service.exceptions.InvalidRequest; |
... | ... | |
419 | 421 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, |
420 | 422 |
InsufficientResources, UnsupportedType { |
421 | 423 |
|
422 |
return false; |
|
424 |
boolean result = false; |
|
425 |
|
|
426 |
// TODO: check credentials |
|
427 |
|
|
428 |
// get the referenced object |
|
429 |
Identifier pid = sysmeta.getIdentifier(); |
|
430 |
|
|
431 |
// get from the membernode |
|
432 |
// TODO: switch credentials for the server retrieval? |
|
433 |
MNode mn = D1Client.getMN(sourceNode); |
|
434 |
InputStream object = null; |
|
435 |
|
|
436 |
try { |
|
437 |
object = mn.get(session, pid); |
|
438 |
} catch (InvalidToken e) { |
|
439 |
e.printStackTrace(); |
|
440 |
throw new ServiceFailure("2151", "Could not retrieve object to replicate (InvalidToken): " + e.getMessage()); |
|
441 |
} catch (NotFound e) { |
|
442 |
e.printStackTrace(); |
|
443 |
throw new ServiceFailure("2151", "Could not retrieve object to replicate (NotFound): " + e.getMessage()); |
|
444 |
} |
|
445 |
|
|
446 |
// add it to local store |
|
447 |
Identifier retPid; |
|
448 |
try { |
|
449 |
retPid = create(session, pid, object, sysmeta); |
|
450 |
result = (retPid.getValue().equals(pid.getValue())); |
|
451 |
} catch (InvalidToken e) { |
|
452 |
e.printStackTrace(); |
|
453 |
throw new ServiceFailure("2151", "Could not save object to local store (InvalidToken): " + e.getMessage()); |
|
454 |
} catch (IdentifierNotUnique e) { |
|
455 |
e.printStackTrace(); |
|
456 |
throw new ServiceFailure("2151", "Could not save object to local store (IdentifierNotUnique): " + e.getMessage()); |
|
457 |
} catch (InvalidSystemMetadata e) { |
|
458 |
e.printStackTrace(); |
|
459 |
throw new ServiceFailure("2151", "Could not save object to local store (InvalidSystemMetadata): " + e.getMessage()); |
|
460 |
} |
|
461 |
|
|
462 |
return result; |
|
463 |
|
|
423 | 464 |
} |
424 | 465 |
|
425 | 466 |
/** |
Also available in: Unified diff
provisional replicate() implementation -- does not check if the session's subject is "allowed" to do this.
the test also requires 2 servers -- right now it attempts to replicate with itself which will fail because of duplicate IDs