|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.plugin.AbstractPlugin net.sf.basedb.plugins.AbstractFlatFileImporter net.sf.basedb.plugins.AnnotationFlatFileImporter
public class AnnotationFlatFileImporter
Plug-in for importing annotations from simple text files. The plug-in supports
all files that can be parsed with the FlatFileParser
class. This plug-in
works without a configuration but can use a configuration to store regular
expressions and other settings for the flat file parser. In both cases,
the job configuration is a three-step process:
Nested Class Summary | |
---|---|
private static class |
AnnotationFlatFileImporter.AnnotationValue
|
private static class |
AnnotationFlatFileImporter.NewAnnotations
Internal cache for storing annotation values from the file for a single item. |
Nested classes/interfaces inherited from interface net.sf.basedb.core.plugin.Plugin |
---|
Plugin.MainType |
Fields inherited from class net.sf.basedb.core.plugin.AbstractPlugin |
---|
annotationSection, configuration, COPY_ANNOTATIONS, job, OVERWRITE_ANNOTATIONS, sc |
Constructor Summary | |
---|---|
AnnotationFlatFileImporter()
|
Method Summary | |
---|---|
protected void |
begin(FlatFileParser ffp)
Setup error handling and pre-load some of the configuration options. |
protected void |
beginData()
Setup column mapping. |
void |
configure(GuiContext context,
Request request,
Response response)
Configure the plugin. |
private ItemQuery<?> |
createQuery(Item itemType,
String searchProperty,
Set<Include> includes)
Create a query that return items of the specified type. |
protected void |
end(boolean success)
Now it's time to update the items in the cache with the new annotation values. |
About |
getAbout()
Get information about the plugin, such as name, version, authors, etc. |
private RequestInformation |
getConfigureImportParameters(GuiContext context)
Step 3 of 3. |
private RequestInformation |
getConfigureMappingParameters(GuiContext context)
Step 2 of 3. |
private RequestInformation |
getConfigureParserParameters(GuiContext context,
boolean forJob)
|
Set<GuiContext> |
getGuiContexts()
This plug-in works in list context of all Annotatable items,
except bioassay sets, bioassays and wells because they are not standalone
items. |
protected FlatFileParser |
getInitializedFlatFileParser()
Create and initialise a flat file parser by setting all regular expressions and other options. |
protected FlatFileParser |
getInitializedFlatFileParser(ParameterValues parameters)
|
private Pattern |
getPattern(ParameterValues parameters,
String name)
|
Collection<Permissions> |
getPermissions()
Request read access to File:s, read access to annotation types and write access to all annotatable items. |
RequestInformation |
getRequestInformation(GuiContext context,
String command)
This method will return the RequestInformation for a given command, i.e. |
protected String |
getSuccessMessage(int skippedLines)
Called if the parsing was successful to let the subclass generate a simple message that is sent back to the core and user interface. |
protected void |
handleData(FlatFileParser.Data data)
Read annotations from a single data line. |
private boolean |
hasExternalId(Item item)
Check if the current item has an 'externalId' property. |
String |
isInContext(GuiContext context,
Object item)
Check if the plugin can be used on the specified object. |
boolean |
requiresConfiguration()
Return TRUE, since the implementation requires it for finding the regular expressions used by the FlatFileParser . |
protected void |
setUpErrorHandling()
Don't use AbstractFlatFileImporter to handle errors. |
boolean |
supportsConfigurations()
Returns TRUE, since that is how the plugins used to work before this method was introduced. |
Methods inherited from class net.sf.basedb.plugins.AbstractFlatFileImporter |
---|
addErrorHandler, checkColumnMapping, checkColumnMapping, continueWithNextFileAfterError, doImport, finish, getCharset, getCharset, getCharsetParameter, getDecimalSeparator, getDecimalSeparatorParameter, getErrorHandler, getErrorOption, getFileIterator, getMainType, getMapper, getNumberFormat, getNumBytes, getPrimaryLocationFilter, getProgress, getSignalHandler, getTotalFileSize, handleHeader, handleSection, isImportable, isImportable, log, log, log, log, run, start, wrapInputStream |
Methods inherited from class net.sf.basedb.core.plugin.AbstractPlugin |
---|
checkInterrupted, cloneParameterWithDefaultValue, closeLogFile, createLogFile, done, getCopyAnnotationsParmeter, getCurrentConfiguration, getCurrentJob, getJobOrConfigurationValue, getOverwriteAnnotationsParameters, init, log, log, storeValue, storeValue, storeValues, validateRequestParameters |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface net.sf.basedb.core.plugin.Plugin |
---|
done, getMainType, init, run |
Field Detail |
---|
private static final About about
private static volatile Set<GuiContext> guiContexts
private static final Set<Permissions> permissions
private static final String CONFIGURE_MAPPING
private static final String CONFIGURE_IMPORT
private static final StringParameterType optionalColumnMapping
private static final BooleanParameterType optionalBooleanType
private static final PluginParameter<String> nameColumnMapping
private static final PluginParameter<String> externalIdColumnMapping
private static final PluginParameter<String> internalIdColumnMapping
private static final PluginParameter<String> annotationTypeSection
private static final PluginParameter<String> findItemsSection
private static final PluginParameter<String> addReplaceSection
private static final PluginParameter<Boolean> addToUnlimitedParameter
private static final PluginParameter<Boolean> replaceExistingParameter
private static final PluginParameter<Boolean> removeExistingParameter
private static final PluginParameter<String> defaultErrorParameter
private static final PluginParameter<String> itemNotFoundErrorParameter
private static final PluginParameter<String> multipleItemsFoundErrorParameter
private static final PluginParameter<String> stringTooLongErrorParameter
protected static final PluginParameter<String> numberOutOfRangeErrorParameter
protected static final PluginParameter<String> numberFormatErrorParameter
protected static final PluginParameter<String> dateFormatErrorParameter
protected static final PluginParameter<String> invalidEnumErrorParameter
protected static final PluginParameter<String> tooManyValuesErrorParameter
private List<String> columnHeaders
private DbControl dc
private UnitCache unitCache
private FlatFileParser ffp
private NumberFormat numberFormat
private DateFormatter dateFormatter
private DateFormatter timestampFormatter
private Item itemType
private String searchProperty
private String searchMapping
private Type searchParameterType
private Mapper itemMapper
private Map<Mapper,AnnotationType> mappers
private Map<String,Set<AnnotationFlatFileImporter.NewAnnotations>> itemCache
private ItemQuery<?> itemQuery
private boolean addToUnlimited
private boolean replaceExisting
private boolean removeExisting
private ClassMapErrorHandler errorHandler
private boolean cropStrings
private boolean ignoreNotFoundItems
private boolean failIfMultipleFoundItems
private boolean failIfTooManyValues
private boolean cropTooManyValues
private int numItems
private int numItemNotFound
private int numAnnotations
private int numReplaced
private int numError
private int numRemoved
private RequestInformation configureParser
private RequestInformation configureMapping
private RequestInformation configureImport
Constructor Detail |
---|
public AnnotationFlatFileImporter()
Method Detail |
---|
public About getAbout()
Plugin
getAbout
in interface Plugin
About
objectpublic boolean requiresConfiguration()
AbstractFlatFileImporter
FlatFileParser
. If this
method is overridden and returns FALSE, the subclass must also override
the AbstractFlatFileImporter.getInitializedFlatFileParser()
method and provide a
parser with all regular expressions and other options set.
requiresConfiguration
in interface Plugin
requiresConfiguration
in class AbstractFlatFileImporter
public boolean supportsConfigurations()
AbstractPlugin
supportsConfigurations
in interface Plugin
supportsConfigurations
in class AbstractPlugin
public Collection<Permissions> getPermissions()
getPermissions
in interface Plugin
getPermissions
in class AbstractPlugin
public Set<GuiContext> getGuiContexts()
Annotatable
items,
except bioassay sets, bioassays and wells because they are not standalone
items. We use Metadata.getAnnotatableItems()
to create the contexts.
getGuiContexts
in interface InteractivePlugin
Set
containing Item
:s, or null
if the plugin is not concerned about itemspublic String isInContext(GuiContext context, Object item)
InteractivePlugin
BasicItem
or BasicData
object, or null if called from
a list context. A client application should only call this method for
contexts matching one of
the contexts in the set returned by the InteractivePlugin.getGuiContexts()
method. For GuiContext.Type.ITEM
contexts an item
of the correct type should be passed as a parameter.
The plug-in can response with a null value indicating success, a warning-level message or throw an exception to indicate an error-level message. Client application should normally only show error-level messages to users, unless the user has requested to see warning messages.
NOTE! Before BASE 2.4 all messages were treated as error-level messages.
isInContext
in interface InteractivePlugin
context
- The current context of the client application,
it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
item
- The currently active item, it's type should match the
GuiContext.getItem()
type, or null if the context is a list
context
Null
if the plugin can use that item, or
a warning-level message explaining why the plugin can't be usedpublic RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException
InteractivePlugin
RequestInformation
for a given command, i.e.
the list of parameters and some nice help text.
getRequestInformation
in interface InteractivePlugin
context
- The current context of the client application,
it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
command
- The command
RequestInformation
for the command
BaseException
- if there is an errorpublic void configure(GuiContext context, Request request, Response response)
InteractivePlugin
InteractivePlugin.getRequestInformation(GuiContext, String)
.
configure
in interface InteractivePlugin
context
- The current context of the client application,
it is one of the values found in set returned by InteractivePlugin.getGuiContexts()
request
- Request object with the command and parametersresponse
- Response object in for the plugin to response
throughprotected FlatFileParser getInitializedFlatFileParser() throws BaseException
AbstractFlatFileImporter
AbstractPlugin.job
or AbstractPlugin.configuration
settings. If a subclass doesn't store the
parameters there it must override this method and initialise the parser. Note that
this method is called once for each file returned by the
AbstractFlatFileImporter.getFileIterator()
and that a new parser is needed for each file.
getInitializedFlatFileParser
in class AbstractFlatFileImporter
BaseException
protected void setUpErrorHandling()
setUpErrorHandling
in class AbstractFlatFileImporter
protected void begin(FlatFileParser ffp)
begin
in class AbstractFlatFileImporter
AbstractFlatFileImporter.end(boolean)
protected void beginData()
beginData
in class AbstractFlatFileImporter
protected void handleData(FlatFileParser.Data data) throws BaseException
handleData
in class AbstractFlatFileImporter
BaseException
protected void end(boolean success)
end
in class AbstractFlatFileImporter
success
- TRUE if the file was parsed successfully, FALSE otherwiseAbstractFlatFileImporter.begin(FlatFileParser)
protected String getSuccessMessage(int skippedLines)
AbstractFlatFileImporter
178 reporters imported successfully
.
The default implementation always return null. Note that this method is called
once for every file returned by AbstractFlatFileImporter.getFileIterator()
.
getSuccessMessage
in class AbstractFlatFileImporter
skippedLines
- The number of data lines that were skipped due to errorsprivate Pattern getPattern(ParameterValues parameters, String name) throws BaseException
BaseException
protected FlatFileParser getInitializedFlatFileParser(ParameterValues parameters) throws BaseException
BaseException
private RequestInformation getConfigureParserParameters(GuiContext context, boolean forJob)
private RequestInformation getConfigureMappingParameters(GuiContext context)
private RequestInformation getConfigureImportParameters(GuiContext context)
private boolean hasExternalId(Item item)
private ItemQuery<?> createQuery(Item itemType, String searchProperty, Set<Include> includes)
Sample.getQuery()
. We add a restriction
to either the 'name' or the 'externalId' property but the parameter is
always called 'name' to make it easier to implement the code that is
using the query.
itemType
- The type of items to searchsearchProperty
- If we should search by name, external ID or internal IDincludes
- Include options passed to AbstractEntityQuery.include(java.util.Collection)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |