Package org.dspace.curate
Class Curator
- java.lang.Object
-
- org.dspace.curate.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCurator.Invokedprotected classCurator.TaskRunnerstatic classCurator.TxScope
-
Field Summary
Fields Modifier and Type Field Description protected CommunityServicecommunityServicestatic intCURATE_ERRORtask encountered an error in processingstatic intCURATE_FAILtask failedstatic intCURATE_NOTASKCurator unable to find requested taskstatic intCURATE_SKIPtask was not applicable to passed objectstatic intCURATE_SUCCESStask completed successfullystatic intCURATE_UNSETno assigned status code - typically because task not yet performedprotected static ThreadLocal<Context>curationCtxprotected HandleServicehandleServiceprotected Curator.InvokediModeprotected ItemServiceitemServiceprotected List<String>perfListprotected Appendablereporterprotected TaskResolverresolverprotected Map<String,String>runParametersprotected TaskQueuetaskQprotected Map<String,Curator.TaskRunner>trMapprotected Curator.TxScopetxScope
-
Constructor Summary
Constructors Constructor Description Curator()No-arg constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddParameter(String name, String value)Set a parameter visible to all tasks in this Curator instance.voidaddParameters(Map<String,String> parameters)Set many parameters visible to all tasks in this Curator instance.CuratoraddTask(String taskName)Add a task to the set to be performed.voidclear()Removes all configured tasks from the Curator.voidcurate(DSpaceObject dso)Performs all configured tasks upon DSpace object (Community, Collection or Item).voidcurate(Context c, String id)Performs all configured tasks upon object identified by id.voidcurate(Context c, DSpaceObject dso)Performs all configured tasks upon DSpace object (Community, Collection or Item).static ContextcurationContext()Returns the context object used in the current curation thread.protected booleandoCollection(Curator.TaskRunner tr, Collection coll)Run task for Collection along with all Items in that collection.protected booleandoCommunity(Curator.TaskRunner tr, Community comm)Run task for Community along with all sub-communities and collections.protected booleandoSite(Curator.TaskRunner tr, Site site)Run task for entire Site (including all Communities, Collections and Items)StringgetResult(String taskName)Returns the result string for the latest performance of the named task.StringgetRunParameter(String name)Look up a run parameter.intgetStatus(String taskName)Returns the status code for the latest performance of the named task.booleanhasTask(String taskName)Returns whether this curator has the specified taskstatic booleanisContainer(DSpaceObject dso)Returns whether a given DSO is a 'container' - collection or communityvoidqueue(Context c, String id, String queueId)Places a curation request for the object identified by id on a managed queue named by the queueId.CuratorremoveTask(String taskName)Removes a task from the set to be performed.voidreport(String message)Adds a message to the configured reporting stream.CuratorsetInvoked(Curator.Invoked mode)Assigns invocation mode.CuratorsetReporter(Appendable reporter)Sets the reporting stream for this curator.voidsetResult(String taskName, String result)Assigns a result to the performance of the named task.CuratorsetTransactionScope(Curator.TxScope scope)Defines the transactional scope of curator executions.protected voidvisit(DSpaceObject dso)Record a 'visit' to a DSpace object and enforce any policies set on this curator.
-
-
-
Field Detail
-
CURATE_NOTASK
public static final int CURATE_NOTASK
Curator unable to find requested task- See Also:
- Constant Field Values
-
CURATE_UNSET
public static final int CURATE_UNSET
no assigned status code - typically because task not yet performed- See Also:
- Constant Field Values
-
CURATE_ERROR
public static final int CURATE_ERROR
task encountered an error in processing- See Also:
- Constant Field Values
-
CURATE_SUCCESS
public static final int CURATE_SUCCESS
task completed successfully- See Also:
- Constant Field Values
-
CURATE_FAIL
public static final int CURATE_FAIL
task failed- See Also:
- Constant Field Values
-
CURATE_SKIP
public static final int CURATE_SKIP
task was not applicable to passed object- See Also:
- Constant Field Values
-
curationCtx
protected static final ThreadLocal<Context> curationCtx
-
trMap
protected Map<String,Curator.TaskRunner> trMap
-
taskQ
protected TaskQueue taskQ
-
reporter
protected Appendable reporter
-
iMode
protected Curator.Invoked iMode
-
resolver
protected TaskResolver resolver
-
txScope
protected Curator.TxScope txScope
-
communityService
protected CommunityService communityService
-
itemService
protected ItemService itemService
-
handleService
protected HandleService handleService
-
-
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 contextid- 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).Note: Site-wide tasks will default to running as an Anonymous User unless you call the Site-wide task via the
curate(org.dspace.core.Context,java.lang.String)orcurate(Context, DSpaceObject)method with an authenticated Context object.- 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 contextid- an object IdqueueId- 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
nullif 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 nameresult- 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- TaskRunnersite- 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- TaskRunnercomm- 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- TaskRunnercoll- 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.
-
-