public abstract class AbstractPlugin extends Object implements Plugin
Plugin.MainType
Modifier and Type | Field and Description |
---|---|
protected static PluginParameter<String> |
annotationSection
Section definition for grouping annotation options.
|
protected ParameterValues |
configuration |
protected static String |
COPY_ANNOTATIONS
The name of the parameter that asks if annotations should be copied or not.
|
protected ParameterValues |
job |
private DbControl |
logDc |
private File |
logfile |
private PrintWriter |
logger |
protected static String |
OVERWRITE_ANNOTATIONS
The name of the parameter that asks if annotations should be overwritten or not.
|
protected SessionControl |
sc |
Modifier | Constructor and Description |
---|---|
protected |
AbstractPlugin()
Create a new
AbstractPlugin . |
Modifier and Type | Method and Description |
---|---|
protected <T> PluginParameter<T> |
cloneParameterWithDefaultValue(PluginParameter<T> pp)
Clone a plug-in parameter and set the default value to the value that is
already stored in the job or configuration parameters.
|
protected void |
closeLogFile()
Close the log file created by
createLogFile(String) . |
protected void |
createLogFile(String path)
Create a log file in the BASE file system for logging
detailed information from a plug-in.
|
void |
done()
Clears the variables set by the
init method. |
protected PluginParameter<Boolean> |
getCopyAnnotationsParmeter(String label,
String description,
Boolean defaultValue)
Parameter definition that asks if annotations should be copied from the
plug-in definition/configuration to other items.
|
protected PluginConfiguration |
getCurrentConfiguration(DbControl dc)
Get the plug-in configuration that this is currently in use or null.
|
protected Job |
getCurrentJob(DbControl dc)
Get the job that is executing this plugin or null.
|
protected Object |
getJobOrConfigurationValue(String name)
Get the value for a job or configuration parameter.
|
protected PluginParameter<Boolean> |
getOverwriteAnnotationsParameters(String label,
String description,
Boolean defaultValue)
Parameter definition that asks if copied annotations should overwrite existing
annotations or not.
|
Collection<Permissions> |
getPermissions()
Return null, which gives the plugin the same permissions as the logged in user.
|
void |
init(SessionControl sc,
ParameterValues configuration,
ParameterValues job)
Store copies of the session control, plugin and job configuration.
|
protected void |
log(String message)
Log a message to the log file created by
createLogFile(String) . |
protected void |
log(String message,
Throwable t)
Log a message and stack trace to the log file created by
createLogFile(String) . |
boolean |
requiresConfiguration()
Returns FALSE, since that is how the plugins used to work before this method
was introduced.
|
protected <T> void |
storeValue(ParameterValues values,
PluginParameter<T> parameter,
T value)
Store a value in a
ParameterValues object. |
protected <T> void |
storeValue(ParameterValues values,
Request request,
PluginParameter<T> parameter)
Copy a parameter value from a
Request to a ParameterValues
object. |
protected <T> void |
storeValues(ParameterValues values,
Request request,
PluginParameter<T> parameter)
Copy a list of parameter values from a
Request to a ParameterValues
object. |
boolean |
supportsConfigurations()
Returns TRUE, since that is how the plugins used to work before this method
was introduced.
|
protected List<Throwable> |
validateRequestParameters(List<PluginParameter<?>> parameters,
Request request)
Validate the parameter values in a request against a list of plugin parameter definitions.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getMainType, run
protected SessionControl sc
protected ParameterValues configuration
protected ParameterValues job
private DbControl logDc
private File logfile
private PrintWriter logger
protected static final PluginParameter<String> annotationSection
protected static final String COPY_ANNOTATIONS
getCopyAnnotationsParmeter(String, String, Boolean)
,
Constant Field Valuesprotected static final String OVERWRITE_ANNOTATIONS
getOverwriteAnnotationsParameters(String, String, Boolean)
,
Constant Field Valuespublic void init(SessionControl sc, ParameterValues configuration, ParameterValues job) throws BaseException
sc
, configuration
and job
variables. If a subclass overrides this method it is
recommended that it also calls super.init(sc, configuration, job)
.init
in interface Plugin
sc
- A SessionControl
object that the plugin
can use to communicate with the core.configuration
- The configuration parameters for the pluginjob
- The job parameters for the pluginBaseException
- if there is an error.public void done()
init
method. If a subclass
overrides this method it is recommended that it also calls super.done()
.public boolean supportsConfigurations()
supportsConfigurations
in interface Plugin
public boolean requiresConfiguration()
requiresConfiguration
in interface Plugin
public Collection<Permissions> getPermissions()
getPermissions
in interface Plugin
protected List<Throwable> validateRequestParameters(List<PluginParameter<?>> parameters, Request request)
ParameterType.validate(String, List)
for each parameter in the list of parameter definitions. If all parameters are valid
this method returns null, otherwise a list of exceptions that ocurred during the validation.
This list can be directly propagated to the Response.setError(String, List)
method. For example:
// In Plugin.invoke() method: List<PluginParameter<?>> parameters = getParametersForCommand(request.getCommand()); List<Throwable> errors = validateRequestParameters(parameters, request); if (errors != null) { response.setError(errors.size()+ " invalid parameter(s) were found in the request", errors); return; }
parameters
- A list containing the parameter definitionsrequest
- The requestprotected <T> void storeValue(ParameterValues values, Request request, PluginParameter<T> parameter) throws BaseException
Request
to a ParameterValues
object. This method makes it easy for a subclass to directly store a request
parameter into either the plugin or job configuration. Use this method when
the parameter valus is a single value.values
- The ParameterValues
object where the value should
be stored, use either configuration
or job
request
- The Request
objectparameter
- The PluginParameter
object for the parameterBaseException
- If the parameter value is invalidprotected <T> void storeValue(ParameterValues values, PluginParameter<T> parameter, T value)
ParameterValues
object. This method is useful when
a plugin needs to store a value that is not part of the request.T
- The type of the parametervalues
- The ParameterValues
object where the value should
be stored, use either configuration
or job
parameter
- The PluginParameter
object for the parametervalue
- The value to saveBaseException
- If the parameter value is invalidprotected <T> void storeValues(ParameterValues values, Request request, PluginParameter<T> parameter) throws BaseException
Request
to a ParameterValues
object. This method makes it easy for a subclass to directly store a request
parameter into either the plugin or job configuration. Use this method when the
parameter value is a list of values.values
- The ParameterValues
object where the value should
be stored, use either configuration
or job
request
- The Request
objectparameter
- The ParameterType
object for the parameterBaseException
- If the parameter value is invalidprotected Job getCurrentJob(DbControl dc)
dc
- The DbControl to use for database accessprotected PluginConfiguration getCurrentConfiguration(DbControl dc)
dc
- The DbControl to use for database accessprotected PluginParameter<Boolean> getCopyAnnotationsParmeter(String label, String description, Boolean defaultValue)
label
- The label to use for the parameter or null to use the default label
(Copy annotations)description
- The description to use for the parameter or null to use the
default descriptiondefaultValue
- The default valueprotected PluginParameter<Boolean> getOverwriteAnnotationsParameters(String label, String description, Boolean defaultValue)
label
- The label to use for the parameter or null to use the default label
(Overwrite existing)description
- The description to use for the parameter or null to use the
default descriptiondefaultValue
- The default valueprotected Object getJobOrConfigurationValue(String name)
name
- The name of the parameterprotected <T> PluginParameter<T> cloneParameterWithDefaultValue(PluginParameter<T> pp)
pp
- The parameter to cloneprotected void createLogFile(String path)
closeLogFile()
to
close the log file and commit changes to the database.
If this method is called when a log file is open, it
does nothing.path
- The path to log to, if null this method does nothingprotected void closeLogFile()
createLogFile(String)
.protected void log(String message)
createLogFile(String)
.
If no log file has been created, this method does nothing.message
- The message to logprotected void log(String message, Throwable t)
createLogFile(String)
. If not log file exists,
this method does nothing.message
- The message to logt
- A stack trace