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
FieldsModifier and TypeFieldDescriptionCSV headers that won't be checked if the field exists on the document type.static final Stringprotected booleanstatic final Stringprotected longprotected longprotected static final Serializableprotected booleanprotected ArrayList<CSVImportLog> static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected CSVImporterOptionsprotected Stringprotected Datestatic final Stringprotected longprotected StringFields inherited from class org.nuxeo.ecm.core.transientstore.work.TransientStoreWork
entryKey, KEY_SUFFIX, STORE_NAMEFields 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
ConstructorsConstructorDescriptionCSVImporterWork(String repositoryName, String parentPath, String username, Blob csvBlob, CSVImporterOptions options) -
Method Summary
Modifier and TypeMethodDescriptionprotected StringListbuildRecipientsList(String userEmail) voidThis 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 SerializableconvertValue(CompositeType compositeType, String fieldName, String headerValue, String stringValue, long lineNumber) protected BlobcreateBlobFromFilePath(String fileRelativePath) Creates aBlobfrom a relative file path.protected BlobcreateBlobFromStringBlob(Blob stringBlob) Creates aBlobfrom aStringBlob.protected booleancreateDocument(long lineNumber, String newParentPath, String name, String type, Map<String, Serializable> properties) protected voiddoImport(org.apache.commons.csv.CSVParser parser) protected BlobgetBlob()Gets the category for this work.protected Stringprotected static List<CSVImportLog> protected longgetLineNumber(org.apache.commons.csv.CSVParser parser) protected longgetLineNumber(org.apache.commons.csv.CSVRecord record) protected static CSVImportStatusgetTitle()Gets a human-readable name for this work instance.protected Stringprotected booleanimportRecord(org.apache.commons.csv.CSVRecord record, Map<String, Integer> header) Import a line from the CSV file.protected Stringlaunch()protected static StringloadTemplate(String key) protected voidprotected BufferedReaderprotected voidreplaceBlobs(List<Object> list) Recursively replaces allBlobs withBlobs created from Files stored in the folder registered by thenuxeo.csv.blobs.folderproperty.protected voidreplaceBlobs(Map<String, Object> map) Recursively replaces allBlobs withBlobs created from Files stored in the folder registered by thenuxeo.csv.blobs.folderproperty.protected voidsendMail()static Throwableprotected booleanupdateDocument(long lineNumber, DocumentRef docRef, Map<String, Serializable> properties) voidwork()This method should implement the actual work done by theWorkinstance.Methods inherited from class org.nuxeo.ecm.core.transientstore.work.TransientStoreWork
computeEntryKey, computeEntryKey, containsBlobHolder, getBlobHolder, getEntryKey, getStore, isIdempotent, putBlobHolder, putBlobHolder, removeBlobHolderMethods 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, workFailedMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:WorkGets the category for this work.Used to choose an execution queue.
- Specified by:
getCategoryin interfaceWork- Overrides:
getCategoryin classAbstractWork- Returns:
- the category, or
nullfor the default
-
getTitle
Description copied from interface:WorkGets a human-readable name for this work instance.- Returns:
- a human-readable name
-
getImportLogs
-
work
public void work()Description copied from interface:WorkThis method should implement the actual work done by theWorkinstance.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 iftruecallWork.suspended()return early with saved state data.Clean up can by implemented by
Work.cleanUp(boolean, Exception).- Specified by:
workin interfaceWork- Specified by:
workin classAbstractWork- See Also:
-
cleanUp
Description copied from class:AbstractWorkThis method is called afterAbstractWork.work()is done in a finally block, whether work completed normally or was in error or was interrupted.- Specified by:
cleanUpin interfaceWork- Overrides:
cleanUpin classAbstractWork- Parameters:
ok-trueif 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:
trueif a document has been created or updated,falseotherwise.- 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 aBlobfrom a relative file path. The File will be looked up in the folder registered by thenuxeo.csv.blobs.folderproperty.- Throws:
IOException- Since:
- 9.3
-
createBlobFromStringBlob
Creates aBlobfrom aStringBlob. Assume that theStringBlobcontent is the relative file path. The File will be looked up in the folder registered by thenuxeo.csv.blobs.folderproperty.- Throws:
IOException- Since:
- 9.3
-
replaceBlobs
Recursively replaces allBlobs withBlobs created from Files stored in the folder registered by thenuxeo.csv.blobs.folderproperty.- Throws:
IOException- Since:
- 9.3
-
replaceBlobs
Recursively replaces allBlobs withBlobs created from Files stored in the folder registered by thenuxeo.csv.blobs.folderproperty.- 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
-