Class MCRObjectUtils

java.lang.Object
org.mycore.datamodel.metadata.MCRObjectUtils

public abstract class MCRObjectUtils extends Object
This class contains several helper methods for MCRObject.
Author:
Matthias Eichner
  • Constructor Details

    • MCRObjectUtils

      public MCRObjectUtils()
  • Method Details

    • getAncestors

      public static List<MCRObject> getAncestors(MCRObject mcrObject)
      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

      public static List<MCRObject> getAncestorsAndSelf(MCRObject mcrObject)
      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

      public static MCRObject getRoot(MCRObject mcrObject)
      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

      public static List<MCRObject> getChildren(MCRObject mcrObject)
      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

      public static List<MCRObject> getDescendantsAndSelf(MCRObject mcrObject)
      Returns a list of all descendants and the object itself. For more information see getDescendants(org.mycore.datamodel.metadata.MCRObject).
      Returns:
      list of all descendants and the object itself
    • getDescendants

      public static List<MCRObject> getDescendants(MCRObject mcrObject)
      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

      public static List<MCRObjectID> getDerivates(MCRObjectID mcrObjectID)
      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

      public static List<MCRObject> getLinkedObjects(MCRObject object) throws MCRPersistenceException
      Returns a list of MCRObjects which are linked in the given object by an MCRMetaLinkID. This does not return any MCRObjectStructure links or any MCRMetaDerivateLinks.
      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

      public static Stream<MCRObject> removeLinks(MCRObjectID sourceId)

      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

      public static boolean removeLink(MCRObject source, MCRObjectID linkToRemove)

      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 from
      linkToRemove - the link id to remove
      Returns:
      true if a link was removed (the source object changed)
    • getCategories

      public static List<MCRCategoryID> getCategories(MCRObject object)
      Returns a list of MCRCategoryIDs 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 identifier
      revision - 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