Revision 9353
Added by Jing Tao about 9 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
591 | 591 |
throw new NotAuthorized("4970", msg); |
592 | 592 |
} |
593 | 593 |
|
594 |
// Check for the existing identifier |
|
595 | 594 |
try { |
596 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
|
|
597 |
super.archive(session, pid);
|
|
595 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
596 |
logMetacat.debug("CNodeService.archive - lock the system metadata for "+pid.getValue());
|
|
598 | 597 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
599 |
notifyReplicaNodes(sysMeta); |
|
598 |
boolean notifyReplica = true; |
|
599 |
archiveCNObject(session, pid, sysMeta, notifyReplica); |
|
600 | 600 |
|
601 |
} catch (McdbDocNotFoundException e) { |
|
602 |
// This object is not registered in the identifier table. Assume it is of formatType DATA, |
|
603 |
// and set the archive flag. (i.e. the *object* doesn't exist on the CN) |
|
604 |
|
|
605 |
try { |
|
606 |
lock = HazelcastService.getInstance().getLock(pid.getValue()); |
|
607 |
lock.lock(); |
|
608 |
logMetacat.debug("Locked identifier " + pid.getValue()); |
|
609 |
|
|
610 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
611 |
if ( sysMeta != null ) { |
|
612 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
|
613 |
sysMeta.setArchived(true); |
|
614 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
615 |
HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta); |
|
616 |
// notify the replicas |
|
617 |
notifyReplicaNodes(sysMeta); |
|
618 |
|
|
619 |
} else { |
|
620 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
621 |
". Couldn't obtain the system metadata record."); |
|
622 |
|
|
623 |
} |
|
624 |
|
|
625 |
} catch (RuntimeException re) { |
|
626 |
throw new ServiceFailure("4972", "Couldn't archive " + pid.getValue() + |
|
627 |
". The error message was: " + re.getMessage()); |
|
628 |
|
|
629 |
} finally { |
|
630 |
lock.unlock(); |
|
631 |
logMetacat.debug("Unlocked identifier " + pid.getValue()); |
|
632 |
|
|
633 |
} |
|
634 |
|
|
635 |
// NOTE: cannot log the archive without localId |
|
636 |
// EventLog.getInstance().log(request.getRemoteAddr(), |
|
637 |
// request.getHeader("User-Agent"), session.getSubject().getValue(), |
|
638 |
// pid.getValue(), Event.DELETE.xmlValue()); |
|
639 |
|
|
640 |
} catch (SQLException e) { |
|
641 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
642 |
". The local id of the object with the identifier can't be identified since "+e.getMessage()); |
|
601 |
} finally { |
|
602 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
603 |
logMetacat.debug("CNodeService.archive - unlock the system metadata for "+pid.getValue()); |
|
643 | 604 |
} |
644 | 605 |
|
645 | 606 |
return pid; |
646 | 607 |
|
647 | 608 |
} |
648 | 609 |
|
610 |
|
|
649 | 611 |
/** |
612 |
* Archive a object on cn. This method doesn't lock the system metadata map. The caller should lock it. |
|
613 |
* This method doesn't check the authorization; this method only accept a pid. |
|
614 |
* @param session |
|
615 |
* @param pid |
|
616 |
* @param sysMeta |
|
617 |
* @param notifyReplica |
|
618 |
* @return |
|
619 |
* @throws InvalidToken |
|
620 |
* @throws ServiceFailure |
|
621 |
* @throws NotAuthorized |
|
622 |
* @throws NotFound |
|
623 |
* @throws NotImplemented |
|
624 |
*/ |
|
625 |
public Identifier archiveCNObject(Session session, Identifier pid, SystemMetadata sysMeta, boolean notifyReplica) |
|
626 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
627 |
|
|
628 |
String localId = null; // The corresponding docid for this pid |
|
629 |
|
|
630 |
// Check for the existing identifier |
|
631 |
try { |
|
632 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
|
633 |
super.archiveObject(session, pid, sysMeta); |
|
634 |
|
|
635 |
} catch (McdbDocNotFoundException e) { |
|
636 |
// This object is not registered in the identifier table. Assume it is of formatType DATA, |
|
637 |
// and set the archive flag. (i.e. the *object* doesn't exist on the CN) |
|
638 |
|
|
639 |
try { |
|
640 |
if ( sysMeta != null ) { |
|
641 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
|
642 |
sysMeta.setArchived(true); |
|
643 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
644 |
HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta); |
|
645 |
|
|
646 |
} else { |
|
647 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
648 |
". Couldn't obtain the system metadata record."); |
|
649 |
|
|
650 |
} |
|
651 |
|
|
652 |
} catch (RuntimeException re) { |
|
653 |
throw new ServiceFailure("4972", "Couldn't archive " + pid.getValue() + |
|
654 |
". The error message was: " + re.getMessage()); |
|
655 |
|
|
656 |
} |
|
657 |
|
|
658 |
} catch (SQLException e) { |
|
659 |
throw new ServiceFailure("4972", "Couldn't archive the object " + pid.getValue() + |
|
660 |
". The local id of the object with the identifier can't be identified since "+e.getMessage()); |
|
661 |
} |
|
662 |
if(notifyReplica) { |
|
663 |
// notify the replicas |
|
664 |
notifyReplicaNodes(sysMeta); |
|
665 |
} |
|
666 |
return pid; |
|
667 |
|
|
668 |
} |
|
669 |
|
|
670 |
|
|
671 |
|
|
672 |
/** |
|
650 | 673 |
* Set the obsoletedBy attribute in System Metadata |
651 | 674 |
* @param session |
652 | 675 |
* @param pid |
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
1999 | 1999 |
/** |
2000 | 2000 |
* Archives an object, where the object is either a |
2001 | 2001 |
* data object or a science metadata object. |
2002 |
* |
|
2002 |
* Note: it doesn't check the authorization; it doesn't lock the system metadata;it only accept pid.
|
|
2003 | 2003 |
* @param session - the Session object containing the credentials for the Subject |
2004 | 2004 |
* @param pid - The object identifier to be archived |
2005 | 2005 |
* |
... | ... | |
2012 | 2012 |
* @throws NotImplemented |
2013 | 2013 |
* @throws InvalidRequest |
2014 | 2014 |
*/ |
2015 |
public Identifier archive(Session session, Identifier pid)
|
|
2015 |
protected Identifier archiveObject(Session session, Identifier pid, SystemMetadata sysMeta)
|
|
2016 | 2016 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
2017 | 2017 |
|
2018 | 2018 |
String localId = null; |
2019 | 2019 |
boolean allowed = false; |
2020 | 2020 |
String username = Constants.SUBJECT_PUBLIC; |
2021 |
String[] groupnames = null; |
|
2022 | 2021 |
if (session == null) { |
2023 | 2022 |
throw new InvalidToken("1330", "No session has been provided"); |
2024 | 2023 |
} else { |
2025 | 2024 |
username = session.getSubject().getValue(); |
2026 |
if (session.getSubjectInfo() != null) { |
|
2027 |
List<Group> groupList = session.getSubjectInfo().getGroupList(); |
|
2028 |
if (groupList != null) { |
|
2029 |
groupnames = new String[groupList.size()]; |
|
2030 |
for (int i = 0; i < groupList.size(); i++) { |
|
2031 |
groupnames[i] = groupList.get(i).getGroupName(); |
|
2032 |
} |
|
2033 |
} |
|
2034 |
} |
|
2035 | 2025 |
} |
2036 |
|
|
2037 | 2026 |
// do we have a valid pid? |
2038 | 2027 |
if (pid == null || pid.getValue().trim().equals("")) { |
2039 | 2028 |
throw new ServiceFailure("1350", "The provided identifier was invalid."); |
2040 | 2029 |
} |
2041 | 2030 |
|
2042 |
String serviceFailureCode = "1350"; |
|
2043 |
Identifier sid = getPIDForSID(pid, serviceFailureCode); |
|
2044 |
if(sid != null) { |
|
2045 |
pid = sid; |
|
2031 |
if(sysMeta == null) { |
|
2032 |
throw new NotFound("2911", "There is no system metadata associated with "+pid.getValue()); |
|
2046 | 2033 |
} |
2047 |
|
|
2034 |
|
|
2048 | 2035 |
// check for the existing identifier |
2049 | 2036 |
try { |
2050 | 2037 |
localId = IdentifierManager.getInstance().getLocalId(pid.getValue()); |
... | ... | |
2054 | 2041 |
throw new ServiceFailure("1350", "The object with the provided identifier "+pid.getValue()+" couldn't be identified since "+e.getMessage()); |
2055 | 2042 |
} |
2056 | 2043 |
|
2057 |
// does the subject have archive (a D1 CHANGE_PERMISSION level) privileges on the pid? |
|
2058 |
try { |
|
2059 |
allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION); |
|
2060 |
} catch (InvalidRequest e) { |
|
2061 |
throw new ServiceFailure("1350", e.getDescription()); |
|
2062 |
} |
|
2063 |
|
|
2064 | 2044 |
|
2065 |
if (allowed) { |
|
2066 | 2045 |
try { |
2067 | 2046 |
// archive the document |
2068 | 2047 |
DocumentImpl.delete(localId, null, null, null, false); |
2069 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue()); |
|
2070 |
|
|
2048 |
try { |
|
2049 |
EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue()); |
|
2050 |
} catch (Exception e) { |
|
2051 |
logMetacat.warn("D1NodeService.archiveObject - can't log the delete event since "+e.getMessage()); |
|
2052 |
} |
|
2053 |
|
|
2071 | 2054 |
// archive it |
2072 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
|
2073 |
SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
2074 | 2055 |
sysMeta.setArchived(true); |
2075 | 2056 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
2076 | 2057 |
sysMeta.setSerialVersion(sysMeta.getSerialVersion().add(BigInteger.ONE)); |
... | ... | |
2092 | 2073 |
|
2093 | 2074 |
} catch (Exception e) { // for some reason DocumentImpl throws a general Exception |
2094 | 2075 |
throw new ServiceFailure("1350", "There was a problem archiving the object." + "The error message was: " + e.getMessage()); |
2095 |
} finally { |
|
2096 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
2097 |
logMetacat.debug("D1NodeService.archive - unlock the system metadata map in hazelcast for the pid "+pid.getValue()); |
|
2098 |
} |
|
2076 |
} |
|
2099 | 2077 |
|
2100 |
} else { |
|
2101 |
throw new NotAuthorized("1320", "The provided identity does not have " + "permission to archive the object on the Node."); |
|
2102 |
} |
|
2103 | 2078 |
|
2104 | 2079 |
return pid; |
2105 | 2080 |
} |
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
100 | 100 |
import org.dataone.service.types.v1.NodeState; |
101 | 101 |
import org.dataone.service.types.v1.NodeType; |
102 | 102 |
import org.dataone.service.types.v2.ObjectFormat; |
103 |
import org.dataone.service.types.v1.Group; |
|
103 | 104 |
import org.dataone.service.types.v1.ObjectFormatIdentifier; |
104 | 105 |
import org.dataone.service.types.v1.ObjectList; |
105 | 106 |
import org.dataone.service.types.v1.Permission; |
... | ... | |
2312 | 2313 |
|
2313 | 2314 |
return bagInputStream; |
2314 | 2315 |
} |
2316 |
|
|
2317 |
/** |
|
2318 |
* Archives an object, where the object is either a |
|
2319 |
* data object or a science metadata object. |
|
2320 |
* |
|
2321 |
* @param session - the Session object containing the credentials for the Subject |
|
2322 |
* @param pid - The object identifier to be archived |
|
2323 |
* |
|
2324 |
* @return pid - the identifier of the object used for the archiving |
|
2325 |
* |
|
2326 |
* @throws InvalidToken |
|
2327 |
* @throws ServiceFailure |
|
2328 |
* @throws NotAuthorized |
|
2329 |
* @throws NotFound |
|
2330 |
* @throws NotImplemented |
|
2331 |
* @throws InvalidRequest |
|
2332 |
*/ |
|
2333 |
public Identifier archive(Session session, Identifier pid) |
|
2334 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
2335 |
boolean allowed = false; |
|
2336 |
// do we have a valid pid? |
|
2337 |
if (pid == null || pid.getValue().trim().equals("")) { |
|
2338 |
throw new ServiceFailure("1350", "The provided identifier was invalid."); |
|
2339 |
} |
|
2340 |
|
|
2341 |
String serviceFailureCode = "1350"; |
|
2342 |
Identifier sid = getPIDForSID(pid, serviceFailureCode); |
|
2343 |
if(sid != null) { |
|
2344 |
pid = sid; |
|
2345 |
} |
|
2346 |
// does the subject have archive (a D1 CHANGE_PERMISSION level) privileges on the pid? |
|
2347 |
try { |
|
2348 |
allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION); |
|
2349 |
} catch (InvalidRequest e) { |
|
2350 |
throw new ServiceFailure("1350", e.getDescription()); |
|
2351 |
} |
|
2352 |
|
|
2353 |
if (allowed) { |
|
2354 |
try { |
|
2355 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
|
2356 |
logMetacat.debug("MNodeService.archive - lock the identifier "+pid.getValue()+" in the system metadata map."); |
|
2357 |
SystemMetadata sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
2358 |
super.archiveObject(session, pid, sysmeta); |
|
2359 |
} finally { |
|
2360 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
2361 |
logMetacat.debug("MNodeService.archive - unlock the identifier "+pid.getValue()+" in the system metadata map."); |
|
2362 |
} |
|
2363 |
|
|
2364 |
|
|
2365 |
} else { |
|
2366 |
throw new NotAuthorized("1320", "The provided identity does not have " + "permission to archive the object on the Node."); |
|
2367 |
} |
|
2368 |
|
|
2369 |
return pid; |
|
2370 |
} |
|
2315 | 2371 |
|
2316 | 2372 |
/** |
2317 | 2373 |
* Update the system metadata of the specified pid. |
Also available in: Unified diff
Refactory the mn.archive and cn.archive method so the mn.update and cn.update can reuse them.