Package org.nuxeo.ecm.csv.core
Class CSVImporterWork
java.lang.Object
org.nuxeo.ecm.core.work.AbstractWork
org.nuxeo.ecm.core.transientstore.work.TransientStoreWork
org.nuxeo.ecm.csv.core.CSVImporterWork
- All Implemented Interfaces:
Serializable
,Work
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.work.api.Work
Work.Progress, Work.State
-
Field Summary
Modifier and TypeFieldDescriptionCSV headers that won't be checked if the field exists on the document type.static final String
protected boolean
static final String
protected long
protected long
protected static final Serializable
protected boolean
protected ArrayList<CSVImportLog>
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected CSVImporterOptions
protected String
protected Date
static final String
protected long
protected String
Fields inherited from class org.nuxeo.ecm.core.transientstore.work.TransientStoreWork
entryKey, KEY_SUFFIX, STORE_NAME
Fields inherited from class org.nuxeo.ecm.core.work.AbstractWork
callerThread, completionTime, docId, docIds, FAILURE_EXCEPTION, FAILURE_MSG, GLOBAL_DLQ_COUNT_REGISTRY_NAME, id, isTree, loginContext, originatingUsername, progress, RANDOM, repositoryName, schedulePath, schedulingTime, session, startTime, state, status, suspended, suspending, traceContext, WORK_FAILED_EVENT, WORK_INSTANCE
-
Constructor Summary
ConstructorDescriptionCSVImporterWork
(String repositoryName, String parentPath, String username, Blob csvBlob, CSVImporterOptions options) -
Method Summary
Modifier and TypeMethodDescriptionprotected StringList
buildRecipientsList
(String userEmail) void
This method is called afterAbstractWork.work()
is done in a finally block, whether work completed normally or was in error or was interrupted.protected Map<String,
Serializable> computePropertiesMap
(org.apache.commons.csv.CSVRecord record, CompositeType compositeType, Map<String, Integer> header) protected Serializable
convertValue
(CompositeType compositeType, String fieldName, String headerValue, String stringValue, long lineNumber) protected Blob
createBlobFromFilePath
(String fileRelativePath) Creates aBlob
from a relative file path.protected Blob
createBlobFromStringBlob
(Blob stringBlob) Creates aBlob
from aStringBlob
.protected boolean
createDocument
(long lineNumber, String newParentPath, String name, String type, Map<String, Serializable> properties) protected void
doImport
(org.apache.commons.csv.CSVParser parser) protected Blob
getBlob()
Gets the category for this work.protected String
protected static List<CSVImportLog>
protected long
getLineNumber
(org.apache.commons.csv.CSVParser parser) protected long
getLineNumber
(org.apache.commons.csv.CSVRecord record) protected static CSVImportStatus
getTitle()
Gets a human-readable name for this work instance.protected String
protected boolean
importRecord
(org.apache.commons.csv.CSVRecord record, Map<String, Integer> header) Import a line from the CSV file.protected String
launch()
protected static String
loadTemplate
(String key) protected void
protected BufferedReader
protected void
replaceBlobs
(List<Object> list) Recursively replaces allBlob
s withBlob
s created from Files stored in the folder registered by thenuxeo.csv.blobs.folder
property.protected void
replaceBlobs
(Map<String, Object> map) Recursively replaces allBlob
s withBlob
s created from Files stored in the folder registered by thenuxeo.csv.blobs.folder
property.protected void
sendMail()
static Throwable
protected boolean
updateDocument
(long lineNumber, DocumentRef docRef, Map<String, Serializable> properties) void
work()
This method should implement the actual work done by theWork
instance.Methods inherited from class org.nuxeo.ecm.core.transientstore.work.TransientStoreWork
computeEntryKey, computeEntryKey, containsBlobHolder, getBlobHolder, getEntryKey, getStore, isIdempotent, putBlobHolder, putBlobHolder, removeBlobHolder
Methods inherited from class org.nuxeo.ecm.core.work.AbstractWork
appendWorkToDeadLetterQueue, buildWorkFailureEventProps, closeSession, commitOrRollbackTransaction, equals, getCompletionTime, getDocument, getDocuments, getId, getOriginatingUsername, getPartitionKey, getProgress, getRetryCount, getSchedulePath, getSchedulingTime, getSpanFromContext, getStartTime, getStatus, getWorkInstanceState, hashCode, isDocumentTree, isSuspending, isWorkInstanceSuspended, newDocumentLocation, openSystemSession, openUserSession, run, runWorkWithTransaction, setCompletionTime, setDocument, setDocument, setDocuments, setOriginatingUsername, setProgress, setSchedulePath, setStartTime, setStatus, setWorkInstanceState, setWorkInstanceSuspending, startTransaction, suspended, toString, workFailed
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.nuxeo.ecm.core.work.api.Work
isCoalescing, isGroupJoin, onGroupJoinCompletion
-
Field Details
-
NUXEO_CSV_MAIL_TO
- See Also:
-
LABEL_CSV_IMPORTER_NOT_EXISTING_FIELD
- See Also:
-
LABEL_CSV_IMPORTER_CANNOT_CONVERT_FIELD_VALUE
- See Also:
-
LABEL_CSV_IMPORTER_NOT_EXISTING_FILE
- See Also:
-
NUXEO_CSV_BLOBS_FOLDER
- See Also:
-
LABEL_CSV_IMPORTER_DOCUMENT_ALREADY_EXISTS
- See Also:
-
LABEL_CSV_IMPORTER_UNABLE_TO_UPDATE
- See Also:
-
LABEL_CSV_IMPORTER_DOCUMENT_UPDATED
- See Also:
-
LABEL_CSV_IMPORTER_UNABLE_TO_CREATE
- See Also:
-
LABEL_CSV_IMPORTER_PARENT_DOES_NOT_EXIST
- See Also:
-
LABEL_CSV_IMPORTER_DOCUMENT_CREATED
- See Also:
-
LABEL_CSV_IMPORTER_NOT_ALLOWED_SUB_TYPE
- See Also:
-
LABEL_CSV_IMPORTER_UNABLE_TO_SAVE
- See Also:
-
LABEL_CSV_IMPORTER_ERROR_IMPORTING_LINE
- See Also:
-
LABEL_CSV_IMPORTER_NOT_EXISTING_TYPE
- See Also:
-
LABEL_CSV_IMPORTER_MISSING_TYPE_VALUE
- See Also:
-
LABEL_CSV_IMPORTER_MISSING_NAME_VALUE
- See Also:
-
LABEL_CSV_IMPORTER_MISSING_NAME_COLUMN
- See Also:
-
LABEL_CSV_IMPORTER_EMPTY_FILE
- See Also:
-
LABEL_CSV_IMPORTER_ERROR_DURING_IMPORT
- See Also:
-
LABEL_CSV_IMPORTER_EMPTY_LINE
- See Also:
-
TEMPLATE_IMPORT_RESULT
- See Also:
-
CATEGORY_CSV_IMPORTER
- See Also:
-
CONTENT_FILED_TYPE_NAME
- See Also:
-
AUTHORIZED_HEADERS
CSV headers that won't be checked if the field exists on the document type.- Since:
- 7.3
-
parentPath
-
username
-
options
-
hasTypeColumn
protected boolean hasTypeColumn -
startDate
-
importLogs
-
computeTotal
protected boolean computeTotal -
total
protected long total -
docsProcessedCount
protected long docsProcessedCount- Since:
- 11.1
-
docsCreatedCount
protected long docsCreatedCount -
EMPTY_LOGS
-
-
Constructor Details
-
CSVImporterWork
-
CSVImporterWork
public CSVImporterWork(String repositoryName, String parentPath, String username, Blob csvBlob, CSVImporterOptions options)
-
-
Method Details
-
getCategory
Description copied from interface:Work
Gets the category for this work.Used to choose an execution queue.
- Specified by:
getCategory
in interfaceWork
- Overrides:
getCategory
in classAbstractWork
- Returns:
- the category, or
null
for the default
-
getTitle
Description copied from interface:Work
Gets a human-readable name for this work instance.- Returns:
- a human-readable name
-
getImportLogs
-
work
public void work()Description copied from interface:Work
This method should implement the actual work done by theWork
instance.It should periodically update its progress through
Work.setProgress(org.nuxeo.ecm.core.work.api.Work.Progress)
.To allow for suspension by the
WorkManager
, it should periodically callWork.isSuspending()
, and iftrue
callWork.suspended()
return early with saved state data.Clean up can by implemented by
Work.cleanUp(boolean, Exception)
.- Specified by:
work
in interfaceWork
- Specified by:
work
in classAbstractWork
- See Also:
-
cleanUp
Description copied from class:AbstractWork
This method is called afterAbstractWork.work()
is done in a finally block, whether work completed normally or was in error or was interrupted.- Specified by:
cleanUp
in interfaceWork
- Overrides:
cleanUp
in classAbstractWork
- Parameters:
ok
-true
if the work completed normallye
- the exception, if available
-
launch
-
getStatus
-
getLastImportLogs
-
newReader
- Throws:
IOException
- Since:
- 7.3
-
doImport
protected void doImport(org.apache.commons.csv.CSVParser parser) -
importRecord
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) -
computePropertiesMap
protected Map<String,Serializable> computePropertiesMap(org.apache.commons.csv.CSVRecord record, CompositeType compositeType, Map<String, Integer> header) - Since:
- 6.0
-
convertValue
protected Serializable convertValue(CompositeType compositeType, String fieldName, String headerValue, String stringValue, long lineNumber) -
createBlobFromFilePath
Creates aBlob
from a relative file path. The File will be looked up in the folder registered by thenuxeo.csv.blobs.folder
property.- Throws:
IOException
- Since:
- 9.3
-
createBlobFromStringBlob
Creates aBlob
from aStringBlob
. Assume that theStringBlob
content is the relative file path. The File will be looked up in the folder registered by thenuxeo.csv.blobs.folder
property.- Throws:
IOException
- Since:
- 9.3
-
replaceBlobs
Recursively replaces allBlob
s withBlob
s created from Files stored in the folder registered by thenuxeo.csv.blobs.folder
property.- Throws:
IOException
- Since:
- 9.3
-
replaceBlobs
Recursively replaces allBlob
s withBlob
s created from Files stored in the folder registered by thenuxeo.csv.blobs.folder
property.- Throws:
IOException
- Since:
- 9.3
-
createDocument
-
updateDocument
protected boolean updateDocument(long lineNumber, DocumentRef docRef, Map<String, Serializable> properties) -
logError
-
sendMail
protected void sendMail() -
getBlob
- Since:
- 9.1
-
getDocumentUrl
-
getUserUrl
-
buildRecipientsList
-
loadTemplate
-
unwrapException
-