Package org.dspace.scripts
Class DSpaceRunnable
- java.lang.Object
-
- org.dspace.scripts.DSpaceRunnable
-
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
IndexClient
public abstract class DSpaceRunnable extends Object implements Runnable
This abstract class is the class that should be extended by each script. it provides the basic variables to be hold by the script as well as the means to initialize, parse and run the script Every DSpaceRunnable that is implemented in this way should be defined in the scripts.xml config file as a bean
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.cli.CommandLinecommandLineThe CommandLine object for the script that'll hold the informationprotected DSpaceRunnableHandlerhandlerThe handler that deals with this script.protected org.apache.commons.cli.OptionsoptionsThe possible options for this script
-
Constructor Summary
Constructors Constructor Description DSpaceRunnable()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringgetDescription()StringgetName()org.apache.commons.cli.OptionsgetOptions()voidinitialize(String[] args, DSpaceRunnableHandler dSpaceRunnableHandler)This method sets the appropriate DSpaceRunnableHandler depending on where it was ran from and it parses the arguments given to the scriptabstract voidinternalRun()This method has to be included in every script and this will be the main execution block for the script that'll contain all the logic neededbooleanisAllowedToExecute(Context context)This method will return if the script is allowed to execute in the given context.voidprintHelp()This method will call upon theDSpaceRunnableHandler.printHelp(Options, String)method with the script's options and namevoidrun()This is the run() method from the Runnable interface that we implement.voidsetDescription(String description)voidsetName(String name)abstract voidsetup()This method has to be included in every script and handles the setup of the script by parsing the CommandLine and setting the variables
-
-
-
Field Detail
-
commandLine
protected org.apache.commons.cli.CommandLine commandLine
The CommandLine object for the script that'll hold the information
-
options
protected org.apache.commons.cli.Options options
The possible options for this script
-
handler
protected DSpaceRunnableHandler handler
The handler that deals with this script. This handler can currently either be a RestDSpaceRunnableHandler or a CommandlineDSpaceRunnableHandler depending from where the script is called
-
-
Method Detail
-
getName
public String getName()
-
setName
public void setName(String name)
-
getDescription
public String getDescription()
-
setDescription
public void setDescription(String description)
-
getOptions
public org.apache.commons.cli.Options getOptions()
-
printHelp
public void printHelp()
This method will call upon theDSpaceRunnableHandler.printHelp(Options, String)method with the script's options and name
-
run
public void run()
This is the run() method from the Runnable interface that we implement. This method will handle the running of the script and all the database modifications needed for the Process object that resulted from this script
-
initialize
public void initialize(String[] args, DSpaceRunnableHandler dSpaceRunnableHandler) throws org.apache.commons.cli.ParseException
This method sets the appropriate DSpaceRunnableHandler depending on where it was ran from and it parses the arguments given to the script- Parameters:
args- The arguments given to the scriptdSpaceRunnableHandler- The DSpaceRunnableHandler object that defines from where the script was ran- Throws:
org.apache.commons.cli.ParseException- If something goes wrong
-
internalRun
public abstract void internalRun() throws ExceptionThis method has to be included in every script and this will be the main execution block for the script that'll contain all the logic needed- Throws:
Exception- If something goes wrong
-
setup
public abstract void setup() throws org.apache.commons.cli.ParseExceptionThis method has to be included in every script and handles the setup of the script by parsing the CommandLine and setting the variables- Throws:
org.apache.commons.cli.ParseException- If something goes wrong
-
isAllowedToExecute
public boolean isAllowedToExecute(Context context)
This method will return if the script is allowed to execute in the given context. This is by default set to the currentUser in the context being an admin, however this can be overwritten by each script individually if different rules apply- Parameters:
context- The relevant DSpace context- Returns:
- A boolean indicating whether the script is allowed to execute or not
-
-