Class CSVImportService

java.lang.Object
org.imixs.workflow.importer.ftp.CSVImportService

@Named public class CSVImportService extends Object
The CSVImportService reacts on DocumentImportEvent and imports a CSV file form a FTP data source or the local file system.

The FTP implementation is based on org.apache.commons.net.ftp

The CSV import can be customized by various options

Author:
rsoika
  • Field Details

  • Constructor Details

    • CSVImportService

      public CSVImportService()
  • Method Details

    • onEvent

      public void onEvent(@Observes DocumentImportEvent event)
      This method reacts on a CDI ImportEvent and imports the data of a CSV file form a ftp server.
    • readFileDataFromFTP

      protected org.imixs.workflow.FileData readFileDataFromFTP(String ftpServer, String csvSelector, String encoding, DocumentImportEvent event)
      Helper method to import the data source from a FTP server The method returns a byte array with the file raw data.
    • importData

      public String importData(InputStream inputStream, String encoding, String type, String keyField, DocumentImportEvent event) throws org.imixs.workflow.exceptions.PluginException
      This method imports all entities from a csv file. The file must have one header line.

      All existing entries not listed in the current file will be removed.

      Each imported document will have a unique key in the item 'name' to be used to verify if the entry already exists.

      Optional a workflow task/event can be defined in the source configuration. In this case the entity will be processed. Otherwise it will be saved only.

      The method returns a log . If an error occurs a plugin exception is thrown

      Method: the implementation first reads all existing ItemCollection objects from the database and stores the hash into a local array. Next the method reads all entries from the CSV file and stores also the hash objects in a array. Next both arrays will be compared. If the compare results in not equal, the entry will be updated/imported. If the entry does no longer exist, the entry will be removed from the database. This operation runs in-memory and reduces database access.

      Returns:
      ErrorMessage or empty String
      Throws:
      org.imixs.workflow.exceptions.PluginException