Class Curator


  • public class Curator
    extends Object
    Curator orchestrates and manages the application of a one or more curation tasks to a DSpace object. It provides common services and runtime environment to the tasks.
    Author:
    richardrodgers
    • Constructor Detail

      • Curator

        public Curator()
        No-arg constructor
    • Method Detail

      • addParameter

        public void addParameter​(String name,
                                 String value)
        Set a parameter visible to all tasks in this Curator instance.
        Parameters:
        name - the parameter's name.
        value - the parameter's value.
      • addParameters

        public void addParameters​(Map<String,​String> parameters)
        Set many parameters visible to all tasks in this Curator instance.
        Parameters:
        parameters - parameter name/value pairs.
      • getRunParameter

        public String getRunParameter​(String name)
        Look up a run parameter.
        Parameters:
        name - the name of the desired parameter.
        Returns:
        the value of the named parameter.
      • addTask

        public Curator addTask​(String taskName)
        Add a task to the set to be performed. Caller should make no assumptions on execution ordering.
        Parameters:
        taskName - - logical name of task
        Returns:
        this curator - to support concatenating invocation style
      • hasTask

        public boolean hasTask​(String taskName)
        Returns whether this curator has the specified task
        Parameters:
        taskName - - logical name of the task
        Returns:
        true if task has been configured, else false
      • removeTask

        public Curator removeTask​(String taskName)
        Removes a task from the set to be performed.
        Parameters:
        taskName - - logical name of the task
        Returns:
        this curator - to support concatenating invocation style
      • setInvoked

        public Curator setInvoked​(Curator.Invoked mode)
        Assigns invocation mode.
        Parameters:
        mode - one of INTERACTIVE, BATCH, ANY
        Returns:
        the Curator instance.
      • setReporter

        public Curator setReporter​(Appendable reporter)
        Sets the reporting stream for this curator.
        Parameters:
        reporter - name of reporting stream. The name '-' causes reporting to standard out.
        Returns:
        return self (Curator instance) with reporter set
      • setTransactionScope

        public Curator setTransactionScope​(Curator.TxScope scope)
        Defines the transactional scope of curator executions. The default is 'open' meaning that no commits are performed by the framework during curation. A scope of 'curation' means that a single commit will occur after the entire performance is complete, and a scope of 'object' will commit for each object (e.g. item) encountered in a given execution.
        Parameters:
        scope - transactional scope
        Returns:
        return self (Curator instance) with given scope set
      • curate

        public void curate​(Context c,
                           String id)
                    throws IOException
        Performs all configured tasks upon object identified by id. If the object can be resolved as a handle, the DSO will be the target object.

        Note: this method has the side-effect of setting this instance's Context reference. The setting is retained on return.

        Parameters:
        c - a DSpace context
        id - an object identifier
        Throws:
        IOException - if IO error
      • curate

        public void curate​(DSpaceObject dso)
                    throws IOException
        Performs all configured tasks upon DSpace object (Community, Collection or Item).
        Parameters:
        dso - the DSpace object
        Throws:
        IOException - if IO error
      • curate

        public void curate​(Context c,
                           DSpaceObject dso)
                    throws IOException
        Performs all configured tasks upon DSpace object (Community, Collection or Item).

        Note: this method has the side-effect of setting this instance's Context reference. The setting is retained on return.

        Parameters:
        c - session context in which curation takes place.
        dso - the single object to be curated.
        Throws:
        IOException - passed through.
      • queue

        public void queue​(Context c,
                          String id,
                          String queueId)
                   throws IOException
        Places a curation request for the object identified by id on a managed queue named by the queueId.
        Parameters:
        c - A DSpace context
        id - an object Id
        queueId - name of a queue. If queue does not exist, it will be created automatically.
        Throws:
        IOException - if IO error
      • clear

        public void clear()
        Removes all configured tasks from the Curator.
      • report

        public void report​(String message)
        Adds a message to the configured reporting stream.
        Parameters:
        message - the message to output to the reporting stream.
      • getStatus

        public int getStatus​(String taskName)
        Returns the status code for the latest performance of the named task.
        Parameters:
        taskName - the task name
        Returns:
        the status code - one of CURATE_ values
      • getResult

        public String getResult​(String taskName)
        Returns the result string for the latest performance of the named task.
        Parameters:
        taskName - the task name
        Returns:
        the result string, or null if task has not set it.
      • setResult

        public void setResult​(String taskName,
                              String result)
        Assigns a result to the performance of the named task.
        Parameters:
        taskName - the task name
        result - a string indicating results of performing task.
      • curationContext

        public static Context curationContext()
                                       throws SQLException
        Returns the context object used in the current curation thread. This is primarily a utility method to allow tasks access to the context when necessary.

        If the context is null or not set, then this just returns a brand new Context object representing an Anonymous User.

        Returns:
        curation thread's Context object (or a new, anonymous Context if no curation Context exists)
        Throws:
        SQLException - An exception that provides information on a database access error or other errors.
      • isContainer

        public static boolean isContainer​(DSpaceObject dso)
        Returns whether a given DSO is a 'container' - collection or community
        Parameters:
        dso - a DSpace object
        Returns:
        true if a container, false otherwise
      • doSite

        protected boolean doSite​(Curator.TaskRunner tr,
                                 Site site)
                          throws IOException
        Run task for entire Site (including all Communities, Collections and Items)
        Parameters:
        tr - TaskRunner
        site - DSpace Site object
        Returns:
        true if successful, false otherwise
        Throws:
        IOException - if IO error
      • doCommunity

        protected boolean doCommunity​(Curator.TaskRunner tr,
                                      Community comm)
                               throws IOException
        Run task for Community along with all sub-communities and collections.
        Parameters:
        tr - TaskRunner
        comm - Community
        Returns:
        true if successful, false otherwise
        Throws:
        IOException - if IO error
      • doCollection

        protected boolean doCollection​(Curator.TaskRunner tr,
                                       Collection coll)
                                throws IOException
        Run task for Collection along with all Items in that collection.
        Parameters:
        tr - TaskRunner
        coll - Collection
        Returns:
        true if successful, false otherwise
        Throws:
        IOException - if IO error
      • visit

        protected void visit​(DSpaceObject dso)
                      throws IOException
        Record a 'visit' to a DSpace object and enforce any policies set on this curator.
        Parameters:
        dso - the DSpace object
        Throws:
        IOException - A general class of exceptions produced by failed or interrupted I/O operations.