Class FileImporter

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

public class FileImporter
extends AbstractItemImporter<File>
Plug-in for importing file items in a batch. The plug-in can create new items (offline or external) and updated existing items (all).
Since:
3.3
Author:
nicklas
  • Field Details

  • Constructor Details

    • FileImporter

      public FileImporter()
  • Method Details

    • getGuiContexts

      public Set<GuiContext> getGuiContexts()
      Description copied from interface: InteractivePlugin
      Get a set containing all items that the plugin handles. Ie. if the plugin imports reporters, return a set containing Item.REPORTER. This information is used by client applications to put the plugin in the proper place in the user interface.
      Returns:
      A Set containing Item:s, or null if the plugin is not concerned about items
    • getIdMethods

      protected IdMethod[] getIdMethods()
      Overrides:
      getIdMethods in class AbstractItemImporter<File>
    • getIdMethod

      protected IdMethod getIdMethod​(DbControl dc, String method)
      We need to initialize the PathIdMethod when this is called.
      Overrides:
      getIdMethod in class AbstractItemImporter<File>
    • getItemForSubtypes

      protected Item getItemForSubtypes()
      Description copied from class: AbstractItemImporter
      Does the importer want to use item subtypes when importing? If this method returns a non-null, this class will add a parameter in the "Item identification" section that makes it possible to select which subtypes the importer should use to limit the search for existing items. The default implementation returns null.
      Overrides:
      getItemForSubtypes in class AbstractItemImporter<File>
      Returns:
      An Item or null
    • addMoreJobParameters

      protected void addMoreJobParameters​(List<PluginParameter<?>> parameters)
      Description copied from class: AbstractItemImporter
      Add extra job parameters that the subclass needs. This method is called during configuration of the plug-in and the default implementation does nothing.
      Overrides:
      addMoreJobParameters in class AbstractItemImporter<File>
      Parameters:
      parameters - The list of parameters to add the column mapping parameters to
    • addMoreColumnMappingParameters

      protected void addMoreColumnMappingParameters​(List<PluginParameter<?>> parameters)
      Adds column mappings for name, externalId and description.
      Overrides:
      addMoreColumnMappingParameters in class AbstractItemImporter<File>
      Parameters:
      parameters - The list of parameters to add the column mapping parameters to
    • createItemQuery

      protected ItemQuery<File> createItemQuery()
      Specified by:
      createItemQuery in class AbstractItemImporter<File>
      Returns:
      A query
    • createColumnMappers

      protected void createColumnMappers​(FlatFileParser ffp, boolean cropStrings)
      Description copied from class: AbstractItemImporter
      Create mappers that can be used to extract data values from the file that is currently being parsed by the ffp FlatFileParser. This method is called during initialisation of the plug-in when the FlatFileParser.parseHeaders() has successfully found the start of data. Use the AbstractFlatFileImporter.getMapper(FlatFileParser, String, Integer, Mapper) to create column mappers. Example:
      nameMapper = getMapper(ffp, job.getValue("nameColumnMapping"), 
         cropStrings ? Nameable.MAX_NAME_LENGTH : null, null);
      
      Overrides:
      createColumnMappers in class AbstractItemImporter<File>
      Parameters:
      ffp - The parser that is parsing the data file
      cropStrings - If strings that are too long to fit in the database should be cropped or not (=generate an error)
    • createItem

      protected File createItem​(DbControl dc, FlatFileParser.Data data)
      Description copied from class: AbstractItemImporter
      Create a new item and populate it with data from the current line. Do not call DbControl.saveItem(BasicItem). This is done automatically by the core implementation.
      BioSource bs = BioSource.getNew(dc);
      // Set properties. See example on updateItem method
      return bs;
      

      If the current data line doesn't have data for all required properties, this method should throw an InvalidUseOfNullException exception.

      This method is called during import when current item can be found and if the user has selected to create missing item.

      Specified by:
      createItem in class AbstractItemImporter<File>
      Parameters:
      dc - The DbControl to use for database access
      data - The current data line
      Returns:
      A new item
    • updateItem

      protected void updateItem​(DbControl dc, File file, FlatFileParser.Data data)
      Description copied from class: AbstractItemImporter
      Update an item with data from the current line. Example:
      if (nameMapper != null) item.setName(nameMapper.getValue(data));
      if (descriptionMapper != null) item.setDescription(descriptionMapper.getValue(data));
      ...
      
      This method is called during import to update an existing item.
      Specified by:
      updateItem in class AbstractItemImporter<File>
      Parameters:
      dc - The DbControl to use for database access
      file - The item to update
      data - The current data line
    • getRootPath

      private String getRootPath​(DbControl dc)
    • getDirectory

      private Directory getDirectory​(DbControl dc, Path path)
    • resolvePath

      private static String resolvePath​(String path, String rootPath)