Class CSVImporterWork

  • All Implemented Interfaces:
    Serializable, Work

    public class CSVImporterWork
    extends TransientStoreWork
    Work task to import form a CSV file. Because the file is read from the local filesystem, this must be executed in a local queue. Since NXP-15252 the CSV reader manages "records", not "lines".
    Since:
    5.7
    See Also:
    Serialized Form
    • Method Detail

      • getCategory

        public String getCategory()
        Description copied from interface: Work
        Gets the category for this work.

        Used to choose an execution queue.

        Specified by:
        getCategory in interface Work
        Overrides:
        getCategory in class AbstractWork
        Returns:
        the category, or null for the default
      • getTitle

        public String getTitle()
        Description copied from interface: Work
        Gets a human-readable name for this work instance.
        Returns:
        a human-readable name
      • cleanUp

        public void cleanUp​(boolean ok,
                            Exception e)
        Description copied from class: AbstractWork
        This method is called after AbstractWork.work() is done in a finally block, whether work completed normally or was in error or was interrupted.
        Specified by:
        cleanUp in interface Work
        Overrides:
        cleanUp in class AbstractWork
        Parameters:
        ok - true if the work completed normally
        e - the exception, if available
      • launch

        protected String launch()
      • doImport

        protected void doImport​(org.apache.commons.csv.CSVParser parser)
      • importRecord

        protected boolean importRecord​(org.apache.commons.csv.CSVRecord record,
                                       Map<String,​Integer> header)
        Import a line from the CSV file.
        Returns:
        true if a document has been created or updated, false otherwise.
        Since:
        6.0
      • getLineNumber

        protected long getLineNumber​(org.apache.commons.csv.CSVRecord record)
      • getLineNumber

        protected long getLineNumber​(org.apache.commons.csv.CSVParser parser)
      • createBlobFromFilePath

        protected Blob createBlobFromFilePath​(String fileRelativePath)
                                       throws IOException
        Creates a Blob from a relative file path. The File will be looked up in the folder registered by the nuxeo.csv.blobs.folder property.
        Throws:
        IOException
        Since:
        9.3
      • createBlobFromStringBlob

        protected Blob createBlobFromStringBlob​(Blob stringBlob)
                                         throws IOException
        Creates a Blob from a StringBlob. Assume that the StringBlob content is the relative file path. The File will be looked up in the folder registered by the nuxeo.csv.blobs.folder property.
        Throws:
        IOException
        Since:
        9.3
      • replaceBlobs

        protected void replaceBlobs​(Map<String,​Object> map)
                             throws IOException
        Recursively replaces all Blobs with Blobs created from Files stored in the folder registered by the nuxeo.csv.blobs.folder property.
        Throws:
        IOException
        Since:
        9.3
      • replaceBlobs

        protected void replaceBlobs​(List<Object> list)
                             throws IOException
        Recursively replaces all Blobs with Blobs created from Files stored in the folder registered by the nuxeo.csv.blobs.folder property.
        Throws:
        IOException
        Since:
        9.3
      • logError

        protected void logError​(long lineNumber,
                                String message,
                                String localizedMessage,
                                String... params)
      • sendMail

        protected void sendMail()
      • getBlob

        protected Blob getBlob()
        Since:
        9.1
      • getUserUrl

        protected String getUserUrl()
      • buildRecipientsList

        protected StringList buildRecipientsList​(String userEmail)
      • loadTemplate

        protected static String loadTemplate​(String key)