Class AnnotationFlatFileImporter

  • All Implemented Interfaces:
    AutoDetectingImporter, InteractivePlugin, Plugin, SignalTarget, ConfigureByExample

    public class AnnotationFlatFileImporter
    extends AbstractFlatFileImporter
    implements InteractivePlugin, ConfigureByExample
    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:
    1. Setup regular expressions and other options for the flat file parser. If a configuration is used all values should already be filled in. In this step a file to import from must also be selected.
    2. Map file columns to annotation types. Annotation types that support multiple values may be mapped to more than one column.
    3. Setup error handling options and other settings for the plug-in (for example if existing annotations should be replaced or not).
    Version:
    2.4
    Author:
    nicklas
    Last modified
    $Date: 2020-10-20 08:29:43 +0200 (Tue, 20 Oct 2020) $
    • Constructor Detail

      • AnnotationFlatFileImporter

        public AnnotationFlatFileImporter()
    • Method Detail

      • isInContext

        public String isInContext​(GuiContext context,
                                  Object item)
        Description copied from interface: InteractivePlugin
        Check if the plugin can be used on the specified object. The item is either a 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.

        Specified by:
        isInContext in interface InteractivePlugin
        Parameters:
        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
        Returns:
        Null if the plugin can use that item, or a warning-level message explaining why the plugin can't be used
      • handleData

        protected void handleData​(FlatFileParser.Data data)
                           throws BaseException
        Read annotations from a single data line. Errors are handled internally. Errors thrown from this method should be reported back to client (ie. error handling in AbstractFlatFileParser) must be disabled. This method will load items and annotation values and put them in an internal cache. No items are annotated until the entire file has been parsed.
        Specified by:
        handleData in class AbstractFlatFileImporter
        Throws:
        BaseException
      • getSuccessMessage

        protected String getSuccessMessage​(int skippedLines)
        Description copied from class: AbstractFlatFileImporter
        Called if the parsing was successful to let the subclass generate a simple message that is sent back to the core and user interface. An example message might by: 178 reporters imported successfully. The default implementation always return null. Note that this method is called once for every file returned by AbstractFlatFileImporter.getFileIterator().
        Overrides:
        getSuccessMessage in class AbstractFlatFileImporter
        Parameters:
        skippedLines - The number of data lines that were skipped due to errors
      • getProgress

        protected int getProgress​(FlatFileParser ffp)
        Overriding default implementation since we want file parsing to only use 'progressParser'% and the remaining 'progressDatabase'% for storing to the database.
        Overrides:
        getProgress in class AbstractFlatFileImporter
        Parameters:
        ffp - The file parser that is used to parsed the file
        Returns:
        A value between 0 and 100
      • getItemListFromContext

        private ItemList getItemListFromContext​(DbControl dc,
                                                GuiContext context)
        If the current context is the "Members" tab for an item list we load the item list and will later require that all items to be annotated are members of that list.
      • getConfigureMappingParameters

        private RequestInformation getConfigureMappingParameters​(GuiContext context)
        Step 2 of 3. Parameters for configuring mapping between columns and annotation types
      • getConfigureImportParameters

        private RequestInformation getConfigureImportParameters​(GuiContext context)
        Step 3 of 3. Other options and error handling parameters
      • hasExternalId

        private boolean hasExternalId​(Item item)
        Check if the current item has an 'externalId' property. We use reflection to look for the 'getExternalId' method in the item's data class.
      • createQuery

        private ItemQuery<?> createQuery​(Item itemType,
                                         ItemList list)
        Create a query that return items of the specified type. We use reflection to call the static method 'getQuery' on the item's item class, for example Sample.getQuery().
        Parameters:
        itemType - The type of items to search
        Returns:
        A query that searches items of the specified type.