Package org.mycore.datamodel.metadata
Class MCRObjectUtils
java.lang.Object
org.mycore.datamodel.metadata.MCRObjectUtils
This class contains several helper methods for
MCRObject
.- Author:
- Matthias Eichner
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetAncestors
(MCRObject mcrObject) Retrieves a list of all ancestors of the given object.getAncestorsAndSelf
(MCRObject mcrObject) Returns a list of all ancestors and the object itself.static List<MCRCategoryID>
getCategories
(MCRObject object) Returns a list ofMCRCategoryID
s which are used in the given object.getChildren
(MCRObject mcrObject) Returns all children of the given object.static List<MCRObjectID>
getDerivates
(MCRObjectID mcrObjectID) Returns all derivates connected with this object.getDescendants
(MCRObject mcrObject) Returns a list of all descendants of the given object.getDescendantsAndSelf
(MCRObject mcrObject) Returns a list of all descendants and the object itself.getLinkedObjects
(MCRObject object) Returns a list ofMCRObject
s which are linked in the given object by anMCRMetaLinkID
.static MCRObject
Returns the root ancestor of the given object.static boolean
removeLink
(MCRObject source, MCRObjectID linkToRemove) Removes the linkToRemove in the metadata and the structure part of the source object.removeLinks
(MCRObjectID sourceId) Removes all links of the source object.static <T extends MCRBase>
Trestore
(MCRObjectID mcrId, String revision) Restores a MyCoRe Object to the selected revision.
-
Constructor Details
-
MCRObjectUtils
public MCRObjectUtils()
-
-
Method Details
-
getAncestors
Retrieves a list of all ancestors of the given object. The first entry is the parent object, the last entry is the root node. Returns an empty list if no ancestor is found.- Returns:
- list of ancestors
-
getAncestorsAndSelf
Returns a list of all ancestors and the object itself. The first entry is the object itself, the last entry is the root node. Returns a list with one entry if no ancestor is found.- Returns:
- list of ancestors
-
getRoot
Returns the root ancestor of the given object. If the object has no parent null is returned.- Parameters:
mcrObject
- object to get the root node- Returns:
- root
MCRObject
-
getChildren
Returns all children of the given object. If the object has no children, an empty list is returned.- Parameters:
mcrObject
- the mycore object- Returns:
- list of all children
-
getDescendantsAndSelf
Returns a list of all descendants and the object itself. For more information seegetDescendants(org.mycore.datamodel.metadata.MCRObject)
.- Returns:
- list of all descendants and the object itself
-
getDescendants
Returns a list of all descendants of the given object. Be aware that there is no specific order. The list is empty if the object has no children.- Returns:
- list of all descendants
-
getDerivates
Returns all derivates connected with this object. This includes derivates which are defined in the structure part and also derivate links.- Parameters:
mcrObjectID
- object identifier to get the root node- Returns:
- set of derivates
-
getLinkedObjects
Returns a list ofMCRObject
s which are linked in the given object by anMCRMetaLinkID
. This does not return anyMCRObjectStructure
links or anyMCRMetaDerivateLink
s.- Parameters:
object
- the object where to get the entitylinks from- Returns:
- a list of linked objects
- Throws:
MCRPersistenceException
- one of the linked objects does not exists
-
removeLinks
Removes all links of the source object. This includes parent links, children links and metadata links. A list of all updated objects is returned.
Be aware that this method does not take care of storing the returned objects.
- Parameters:
sourceId
- id of the object- Returns:
- a stream of updated objects where a link of the source was removed
-
removeLink
Removes the linkToRemove in the metadata and the structure part of the source object. Be aware that this can lead to a zombie source object without a parent! Use this method with care!
This method does not take care of storing the source object.
- Parameters:
source
- the source object where the links should be removed fromlinkToRemove
- the link id to remove- Returns:
- true if a link was removed (the source object changed)
-
getCategories
Returns a list ofMCRCategoryID
s which are used in the given object.- Parameters:
object
- the object where to get the categories from- Returns:
- a list of linked categories
-
restore
public static <T extends MCRBase> T restore(MCRObjectID mcrId, String revision) throws IOException, MCRPersistenceException Restores a MyCoRe Object to the selected revision. Please note that children and derivates are not deleted or reverted!- Parameters:
mcrId
- the mycore object identifierrevision
- The revision to restore to. If this is lower than zero, the last revision is used.- Returns:
- the new
MCRObject
- Throws:
IOException
- An error occurred while retrieving the revision information. This is most likely due an svn error.MCRPersistenceException
- There is no such object with the given id and revision.ClassCastException
- The returning type must be the same as the type of the restored object
-