Class MCRObjectCommands

java.lang.Object
org.mycore.frontend.cli.MCRAbstractCommands
org.mycore.frontend.cli.MCRObjectCommands
All Implemented Interfaces:
MCRExternalCommandInterface

@MCRCommandGroup(name="Object Commands") public class MCRObjectCommands extends MCRAbstractCommands
Provides static methods that implement commands for the MyCoRe command line interface. Robert: Ideas for clean-up - "transform ..." and "xslt..." do the same thing and should thereform be named uniquely - "transformm ...." - "delete by Query ..." can be deleted - "select ..." and "delete selected ..." supply the same behaviour in 2 commands - "list objects matching ..." can be deleted - "select ..." and "list selected" supply the same behaviour in 2 commands
Version:
$Revision$ $Date$
Author:
Jens Kupferschmidt, Frank Lützenkirchen, Robert Stephan
  • Field Details

  • Constructor Details

    • MCRObjectCommands

      public MCRObjectCommands()
  • Method Details

    • setSelectedObjectIDs

      public static void setSelectedObjectIDs(List<String> selected)
    • getSelectedObjectIDs

      public static List<String> getSelectedObjectIDs()
    • selectObjectsWithXpath

      @MCRCommand(syntax="select objects with xpath {0}", help="Selects MCRObjects with XPath {0}, if that XPath evaluates to a non-empty result list (this command may take a while, use with care in case of a large number of objects)", order=10) public static void selectObjectsWithXpath(String xPath) throws Exception
      Throws:
      Exception
    • selectDescendantObjects

      @MCRCommand(syntax="select descendants of object {0}", help="Selects MCRObjects that are descendants of {0} (children, grandchildren, ...) and {0} itself.", order=15) public static void selectDescendantObjects(String id) throws Exception
      Throws:
      Exception
    • deleteAllObjects

      @MCRCommand(syntax="delete all objects of type {0}", help="Removes MCRObjects of type {0}.", order=20) public static List<String> deleteAllObjects(String type)
      Delete all MCRObject from the datastore for a given type.
      Parameters:
      type - the type of the MCRObjects that should be deleted
    • deleteTopologicalAllObjects

      @MCRCommand(syntax="delete all objects in topological order", help="Removes all MCRObjects in topological order.", order=25) public static List<String> deleteTopologicalAllObjects()
      Delete all MCRObjects from the datastore in topological order
    • checkForCircles

      @MCRCommand(syntax="check for circles in topological order", help="Checks if there are circular dependencies in the parent child relationships of MCRObjects.", order=25) public static void checkForCircles()
    • delete

      @MCRCommand(syntax="delete object {0}", help="Removes a MCRObject with the MCRObjectID {0}", order=40) public static void delete(String id) throws MCRPersistenceException, MCRActiveLinkException, MCRAccessException
      Delete a MCRObject from the datastore.
      Parameters:
      id - the id of the MCRObject that should be deleted
      Throws:
      MCRPersistenceException - if a persistence problem is occurred
      MCRAccessException - see MCRMetadataManager.deleteMCRObject(MCRObjectID)
      MCRActiveLinkException - if object is referenced by other objects
    • clearLinks

      @MCRCommand(syntax="clear links of object {0}", help="removes all links of this object, including parent/child relations and all MetaLinkID\'s in the metadata section", order=45) public static void clearLinks(String id) throws MCRPersistenceException
      Runs though all mycore objects which are linked with the given object and removes its link. This includes parent/child relations and all MCRMetaLinkID in the metadata section.
      Parameters:
      id - the id of the MCRObject that should be deleted
      Throws:
      MCRPersistenceException - if a persistence problem is occurred
    • deleteFromTo

      @MCRCommand(syntax="delete object from {0} to {1}", help="Removes MCRObjects in the number range between the MCRObjectID {0} and {1}.", order=30) public static List<String> deleteFromTo(String idFrom, String idTo)
      Delete MCRObject's form ID to ID from the datastore.
      Parameters:
      idFrom - the start ID for deleting the MCRObjects
      idTo - the stop ID for deleting the MCRObjects
      Returns:
      list of delete commands
    • loadTopologicalFromDirectory

      @MCRCommand(syntax="load all objects in topological order from directory {0}", help="Loads all MCRObjects form the directory {0} to the system respecting the order of parents and children.", order=75) public static List<String> loadTopologicalFromDirectory(String directory)
      Load MCRObject's from all XML files in a directory in proper order (respecting parent-child-relationships).
      Parameters:
      directory - the directory containing the XML files
    • updateTopologicalFromDirectory

      @MCRCommand(syntax="update all objects in topological order from directory {0}", help="Updates all MCRObjects from the directory {0} in the system respecting the order of parents and children.", order=95) public static List<String> updateTopologicalFromDirectory(String directory)
      Update MCRObject's from all XML files in a directory in proper order (respecting parent-child-relationships).
      Parameters:
      directory - the directory containing the XML files
    • loadFromDirectory

      @MCRCommand(syntax="load all objects from directory {0}", help="Loads all MCRObjects from the directory {0} to the system. If the numerical part of a provided ID is zero, a new ID with the same project ID and type is assigned.", order=70) public static List<String> loadFromDirectory(String directory)
      Load MCRObject's from all XML files in a directory.
      Parameters:
      directory - the directory containing the XML files
    • updateFromDirectory

      @MCRCommand(syntax="update all objects from directory {0}", help="Updates all MCRObjects from the directory {0} in the system.", order=90) public static List<String> updateFromDirectory(String directory)
      Update MCRObject's from all XML files in a directory.
      Parameters:
      directory - the directory containing the XML files
    • loadFromFile

      @MCRCommand(syntax="load object from file {0}", help="Loads an MCRObject from the file {0} to the system. If the numerical part of the provided ID is zero, a new ID with the same project ID and type is assigned.", order=60) public static boolean loadFromFile(String file) throws MCRException, SAXParseException, IOException, MCRAccessException
      Load a MCRObjects from an XML file.
      Parameters:
      file - the location of the xml file
      Throws:
      MCRAccessException - see MCRMetadataManager.create(MCRObject)
      MCRException
      SAXParseException
      IOException
    • loadFromFile

      public static boolean loadFromFile(String file, boolean importMode) throws MCRException, SAXParseException, IOException, MCRAccessException
      Load a MCRObjects from an XML file.
      Parameters:
      file - the location of the xml file
      importMode - if true, servdates are taken from xml file
      Throws:
      MCRAccessException - see MCRMetadataManager.update(MCRObject)
      MCRException
      SAXParseException
      IOException
    • updateFromFile

      @MCRCommand(syntax="update object from file {0}", help="Updates a MCRObject from the file {0} in the system.", order=80) public static boolean updateFromFile(String file) throws MCRException, SAXParseException, IOException, MCRAccessException
      Update a MCRObject's from an XML file.
      Parameters:
      file - the location of the xml file
      Throws:
      MCRAccessException - see MCRMetadataManager.update(MCRObject)
      MCRException
      SAXParseException
      IOException
    • updateFromFile

      public static boolean updateFromFile(String file, boolean importMode) throws MCRException, SAXParseException, IOException, MCRAccessException
      Update a MCRObject's from an XML file.
      Parameters:
      file - the location of the xml file
      importMode - if true, servdates are taken from xml file
      Throws:
      MCRAccessException - see MCRMetadataManager.update(MCRObject)
      MCRException
      SAXParseException
      IOException
    • showNextID

      public static void showNextID(String base)
      Shows the next free MCRObjectIDs.
      Parameters:
      base - the base String of the MCRObjectID
    • showLastID

      public static void showLastID(String base)
      Shows the last used MCRObjectIDs.
      Parameters:
      base - the base String of the MCRObjectID
    • exportWithStylesheet

      @MCRCommand(syntax="export object {0} to directory {1} with stylesheet {2}", help="Stores the MCRObject with the MCRObjectID {0} to the directory {1} with the stylesheet {2}-object.xsl. For {2}, the default is xsl/save.", order=110) public static void exportWithStylesheet(String id, String dirname, String style)
      Export an MCRObject to a file named MCRObjectID.xml in a directory named dirname. The method uses the converter stylesheet style.xsl.
      Parameters:
      id - the id of the MCRObject to be save.
      dirname - the dirname to store the object
      style - the type of the stylesheet
    • exportWithTransformer

      @MCRCommand(syntax="export object {0} to directory {1} with transformer {2}", help="Stores the MCRObject with the MCRObjectID {0} to the directory {1} with the transformer {2}.", order=110) public static void exportWithTransformer(String id, String dirname, String transname)
      Export an MCRObject to a file named MCRObjectID.xml in a directory named dirname. The method use the content transformer transnamexsl.
      Parameters:
      id - the id of the MCRObject to be save.
      dirname - the dirname to store the object
      transname - the name of the transformer
    • exportWithStylesheet

      @MCRCommand(syntax="export objects from {0} to {1} to directory {2} with stylesheet {3}", help="Stores all MCRObjects with MCRObjectID\'s between {0} and {1} to the directory {2} with the stylesheet {3}-object.xsl. For {3}, the default is xsl/save.", order=100) public static void exportWithStylesheet(String fromID, String toID, String dirname, String style)
      Export any MCRObject's to files named MCRObjectID.xml in a directory named dirname. Exporting starts with fromID and ends with toID. IDs that aren't found will be skipped. The method uses the converter stylesheet style.xsl.
      Parameters:
      fromID - the ID of the MCRObject from be save.
      toID - the ID of the MCRObject to be save.
      dirname - the filename to store the object
      style - the type of the stylesheet
    • exportWithTransformer

      @MCRCommand(syntax="export objects from {0} to {1} to directory {2} with transformer {3}", help="Stores all MCRObjects with MCRObjectID\'s between {0} and {1} to the directory {2} with the transformer {3}.", order=100) public static void exportWithTransformer(String fromID, String toID, String dirname, String transname)
      Export any MCRObject's to files named MCRObjectID.xml in a directory named dirname. Exporting starts with fromID and ends with toID. IDs that aren't found will be skipped. The method use the content transformer transnamexsl.
      Parameters:
      fromID - the ID of the MCRObject from be save.
      toID - the ID of the MCRObject to be save.
      dirname - the filename to store the object
      transname - the name of the transformer
    • exportAllObjectsOfTypeWithStylesheet

      @MCRCommand(syntax="export all objects of type {0} to directory {1} with stylesheet {2}", help="Stores all MCRObjects of type {0} to directory {1} with the stylesheet {2}-object.xsl.For {2}, the default is xsl/save.", order=120) public static List<String> exportAllObjectsOfTypeWithStylesheet(String type, String dirname, String style)
      Export all MCRObject's with data type type to files named MCRObjectID.xml in a directory named dirname. The method uses the converter stylesheet style.xsl.
      Parameters:
      type - the MCRObjectID type
      dirname - the filename to store the object
      style - the type of the stylesheet
    • exportAllObjectsOfBaseWithStylesheet

      @MCRCommand(syntax="export all objects of base {0} to directory {1} with stylesheet {2}", help="Stores all MCRObjects of base {0} to directory {1} with the stylesheet {2}-object.xsl. For {2}, the default is xsl/save.", order=130) public static List<String> exportAllObjectsOfBaseWithStylesheet(String base, String dirname, String style)
      Export all MCRObject's with data base base to files named MCRObjectID.xml in a directory named dirname. The method uses the converter stylesheet style.xsl.
      Parameters:
      base - the MCRObjectID base
      dirname - the filename to store the object
      style - the type of the stylesheet
    • getNextID

      @MCRCommand(syntax="get next ID for base {0}", help="Returns the next free MCRObjectID for the ID base {0}.", order=150) public static void getNextID(String base)
      Get the next free MCRObjectID for the given MCRObjectID base.
      Parameters:
      base - the MCRObjectID base string
    • getLastID

      @MCRCommand(syntax="get last ID for base {0}", help="Returns the last used MCRObjectID for the ID base {0}.", order=140) public static void getLastID(String base)
      Get the last used MCRObjectID for the given MCRObjectID base.
      Parameters:
      base - the MCRObjectID base string
    • listSelected

      @MCRCommand(syntax="list selected", help="Prints the id of selected objects", order=190) public static void listSelected()
      List all selected MCRObjects.
    • listRevisions

      @MCRCommand(syntax="list revisions of {0}", help="List revisions of MCRObject.", order=260) public static void listRevisions(String id)
      List revisions of an MyCoRe Object.
      Parameters:
      id - id of MyCoRe Object
    • restoreToRevision

      @MCRCommand(syntax="restore {0} to revision {1}", help="Restores the selected MCRObject to the selected revision.", order=270) public static void restoreToRevision(String id, String revision)
      This method restores a MyCoRe Object to the selected revision. Please note that children and derivates are not deleted or reverted!
      Parameters:
      id - id of MyCoRe Object
      revision - revision to restore
    • xslt

      @MCRCommand(syntax="xslt {0} with file {1}", help="transforms a mycore object {0} with the given file or URI {1}", order=280) public static void xslt(String objectId, String xslFilePath) throws IOException, JDOMException, SAXException, TransformerException, MCRPersistenceException, MCRAccessException, ParserConfigurationException
      Does a xsl transform with the given mycore object.

      To use this command create a new xsl file and copy following xslt code into it.

       
       <?xml version="1.0" encoding="utf-8"?>
       <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
         <xsl:template match='@*|node()'>
           <!-- default template: just copy -->
           <xsl:copy>
             <xsl:apply-templates select='@*|node()' />
           </xsl:copy>
         </xsl:template>
      
       </xsl:stylesheet>
       
       

      Insert a new template match, for example:

       
       <xsl:template match="metadata/mainTitle/@heritable">
         <xsl:attribute name="heritable"><xsl:value-of select="'true'"/></xsl:attribute>
       </xsl:template>
       
       
      Parameters:
      objectId - object to transform
      xslFilePath - path to xsl file
      Throws:
      MCRPersistenceException - see MCRMetadataManager.update(MCRObject)
      MCRAccessException - see MCRMetadataManager.update(MCRObject)
      IOException
      JDOMException
      SAXException
      TransformerException
      ParserConfigurationException
    • forceXSLT

      @MCRCommand(syntax="force xslt {0} with file {1}", help="transforms a mycore object {0} with the given file or URI {1}. Overwrites anyway if original root name and result root name are different.", order=285) public static void forceXSLT(String objectId, String xslFilePath) throws IOException, JDOMException, SAXException, TransformerException, MCRPersistenceException, MCRAccessException, ParserConfigurationException
      Parameters:
      objectId - object to transform
      xslFilePath - path to xsl file
      Throws:
      MCRPersistenceException - see MCRMetadataManager.update(MCRObject)
      MCRAccessException - see MCRMetadataManager.update(MCRObject)
      IOException
      JDOMException
      SAXException
      TransformerException
      ParserConfigurationException
      See Also:
    • transformObject

      @MCRCommand(syntax="transform object {0} with transformer {1}", help="Transforms the object with the id {0} using the transformer with the id {1} and updates the object with the result") public static void transformObject(String objectIDStr, String transformer) throws IOException, JDOMException, SAXException, MCRAccessException
      Throws:
      IOException
      JDOMException
      SAXException
      MCRAccessException
    • replaceParent

      @MCRCommand(syntax="set parent of {0} to {1}", help="replaces a parent of an object (first parameter) to the given new one (second parameter)", order=300) public static void replaceParent(String sourceId, String newParentId) throws MCRPersistenceException, MCRAccessException
      Moves object to new parent.
      Parameters:
      sourceId - object that should be attached to new parent
      newParentId - the ID of the new parent
      Throws:
      MCRAccessException - see MCRMetadataManager.update(MCRObject)
      MCRPersistenceException
    • checkDerivatesInObjects

      @MCRCommand(syntax="check derivate entries in objects for base {0}", help="check in all objects with MCR base ID {0} for existing linked derivates", order=400) public static void checkDerivatesInObjects(String baseId)
      Check the derivate links in objects of MCR base ID for existing. It looks to the XML store on the disk to get all object IDs.
      Parameters:
      baseId - the base part of a MCRObjectID e.g. DocPortal_document
    • validateObjectsOfBase

      @MCRCommand(syntax="validate object schema for base {0}", help="Validates all objects of base {0} against their specified schema.", order=401) public static List<String> validateObjectsOfBase(String baseID)
      Checks objects of the specified base ID for validity against their specified schemas.
      Parameters:
      baseID - the base part of a MCRObjectID e.g. DocPortal_document
    • validateObjectsOfType

      @MCRCommand(syntax="validate object schema for type {0}", help="Validates all object of type {0} against their specified schema.", order=402) public static List<String> validateObjectsOfType(String type)
      Checks objects of the specified type for validity against their specified schemas.
      Parameters:
      type - the type of a MCRObjectID e.g. document
    • validateObject

      @MCRCommand(syntax="validate object schema for ID {0}", help="Checks if object {0} validates against its specified schema.", order=404) public static void validateObject(String objectID)
      Check if an object validates against its specified schema.
      Parameters:
      objectID - the ID of an object to check
    • validateObjectWithTransformer

      @MCRCommand(syntax="validate object schema for ID {0} after transformer {1}", help="Checks if object {0} validates against its specified schema, after being transformed through {1}.xsl.", order=403) public static void validateObjectWithTransformer(String objectID, String transformerType)
      Check if an object validates against its specified schema.
      Parameters:
      objectID - the ID of an object to check
      transformerType - the name of a stylesheet that the object should be transformed with before validation
    • executeForSelected

      @MCRCommand(syntax="execute for selected {0}", help="Calls the given command multiple times for all selected objects. The replacement is defined by an {x}.E.g. \'execute for selected set parent of {x} to myapp_container_00000001\'", order=450) public static List<String> executeForSelected(String command)
    • repairMetadataSearch

      @MCRCommand(syntax="repair metadata search of type {0}", help="Scans the metadata store for MCRObjects of type {0} and restores them in the search store.", order=170) public static List<String> repairMetadataSearch(String type)
      The method start the repair of the metadata search for a given MCRObjectID type.
      Parameters:
      type - the MCRObjectID type
    • repairMetadataSearchForBase

      @MCRCommand(syntax="repair metadata search of base {0}", help="Scans the metadata store for MCRObjects of base {0} and restores them in the search store.", order=171) public static List<String> repairMetadataSearchForBase(String baseID)
      The method start the repair of the metadata search for a given MCRObjectID base.
      Parameters:
      baseID - the base part of a MCRObjectID e.g. DocPortal_document
    • repairMetadataSearchForID

      @MCRCommand(syntax="repair metadata search of ID {0}", help="Retrieves the MCRObject with the MCRObjectID {0} and restores it in the search store.", order=180) public static void repairMetadataSearchForID(String id)
      The method start the repair of the metadata search for a given MCRObjectID as String.
      Parameters:
      id - the MCRObjectID as String
    • repairMCRLinkHrefTable

      @MCRCommand(syntax="repair mcrlinkhref table", help="Runs through the whole table and checks for already deleted mcr objects and deletes them.", order=185) public static void repairMCRLinkHrefTable()
    • rebuildMCRLinkHrefTableForObject

      @MCRCommand(syntax="rebuild mcrlinkhref table for object {0}", help="Rebuilds (remove/create) all entries of the link href table for the given object id.", order=188) public static void rebuildMCRLinkHrefTableForObject(String objectId)