public class CSVImporterWork extends TransientStoreWork
Work.Progress, Work.State
entryKey, KEY_SUFFIX, STORE_NAME
callerThread, completionTime, docId, docIds, id, isTree, loginContext, originatingUsername, progress, RANDOM, repositoryName, schedulePath, schedulingTime, session, startTime, state, status, suspended, suspending
Constructor and Description |
---|
CSVImporterWork(String id) |
CSVImporterWork(String repositoryName,
String parentPath,
String username,
Blob csvBlob,
CSVImporterOptions options) |
Modifier and Type | Method and Description |
---|---|
protected StringList |
buildRecipientsList(String userEmail) |
void |
cleanUp(boolean ok,
Exception e)
This method is called after
AbstractWork.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 a
Blob from a relative file path. |
protected Blob |
createBlobFromStringBlob(Blob stringBlob)
Creates a
Blob from a StringBlob . |
protected boolean |
createDocument(long lineNumber,
String newParentPath,
String name,
String type,
Map<String,Serializable> properties) |
protected void |
doImport(org.apache.commons.csv.CSVParser parser) |
String |
getCategory()
Gets the category for this work.
|
protected DateFormat |
getDateFormat() |
protected String |
getDocumentUrl(DocumentModel doc) |
List<CSVImportLog> |
getImportLogs() |
protected long |
getLineNumber(org.apache.commons.csv.CSVParser parser) |
protected long |
getLineNumber(org.apache.commons.csv.CSVRecord record) |
String |
getTitle()
Gets a human-readable name for this work instance.
|
protected String |
getUserUrl() |
protected boolean |
importRecord(org.apache.commons.csv.CSVRecord record,
Map<String,Integer> header)
Import a line from the CSV file.
|
protected void |
logError(long lineNumber,
String message,
String localizedMessage,
String... params) |
protected BufferedReader |
newReader(Blob blob) |
protected void |
replaceBlobs(List<Object> list)
Recursively replaces all
Blob s with Blob s created from Files stored in the folder registered by
the nuxeo.csv.blobs.folder property. |
protected void |
replaceBlobs(Map<String,Object> map)
Recursively replaces all
Blob s with Blob s created from Files stored in the folder registered by
the nuxeo.csv.blobs.folder property. |
protected void |
sendMail() |
static Throwable |
unwrapException(Throwable t) |
protected boolean |
updateDocument(long lineNumber,
DocumentRef docRef,
Map<String,Serializable> properties) |
void |
work()
This method should implement the actual work done by the
Work instance. |
computeEntryKey, computeEntryKey, containsBlobHolder, getBlobHolder, getEntryKey, getStore, putBlobHolder, putBlobHolder, removeBlobHolder
closeSession, commitOrRollbackTransaction, equals, getCompletionTime, getDocument, getDocuments, getId, getOriginatingUsername, getPartitionKey, getProgress, getRetryCount, getSchedulePath, getSchedulingTime, getStartTime, getStatus, getWorkInstanceState, hashCode, initSession, initSession, isDocumentTree, isSuspending, isWorkInstanceSuspended, newDocumentLocation, openSystemSession, openUserSession, run, runWorkWithTransaction, setCompletionTime, setDocument, setDocument, setDocuments, setOriginatingUsername, setProgress, setSchedulePath, setStartTime, setStatus, setWorkInstanceState, setWorkInstanceSuspending, startTransaction, suspended, toString
public static final String NUXEO_CSV_MAIL_TO
public static final String LABEL_CSV_IMPORTER_NOT_EXISTING_FIELD
public static final String LABEL_CSV_IMPORTER_CANNOT_CONVERT_FIELD_VALUE
public static final String LABEL_CSV_IMPORTER_NOT_EXISTING_FILE
public static final String NUXEO_CSV_BLOBS_FOLDER
public static final String LABEL_CSV_IMPORTER_DOCUMENT_ALREADY_EXISTS
public static final String LABEL_CSV_IMPORTER_UNABLE_TO_UPDATE
public static final String LABEL_CSV_IMPORTER_DOCUMENT_UPDATED
public static final String LABEL_CSV_IMPORTER_UNABLE_TO_CREATE
public static final String LABEL_CSV_IMPORTER_PARENT_DOES_NOT_EXIST
public static final String LABEL_CSV_IMPORTER_DOCUMENT_CREATED
public static final String LABEL_CSV_IMPORTER_NOT_ALLOWED_SUB_TYPE
public static final String LABEL_CSV_IMPORTER_UNABLE_TO_SAVE
public static final String LABEL_CSV_IMPORTER_ERROR_IMPORTING_LINE
public static final String LABEL_CSV_IMPORTER_NOT_EXISTING_TYPE
public static final String LABEL_CSV_IMPORTER_MISSING_TYPE_VALUE
public static final String LABEL_CSV_IMPORTER_MISSING_NAME_VALUE
public static final String LABEL_CSV_IMPORTER_MISSING_NAME_COLUMN
public static final String LABEL_CSV_IMPORTER_EMPTY_FILE
public static final String LABEL_CSV_IMPORTER_ERROR_DURING_IMPORT
public static final String LABEL_CSV_IMPORTER_EMPTY_LINE
public static final String CATEGORY_CSV_IMPORTER
public static final String CONTENT_FILED_TYPE_NAME
public static List<String> AUTHORIZED_HEADERS
protected String parentPath
protected CSVImporterOptions options
protected transient DateFormat dateformat
protected boolean hasTypeColumn
protected ArrayList<CSVImportLog> importLogs
protected boolean computeTotal
protected long total
protected long docsCreatedCount
public CSVImporterWork(String id)
public CSVImporterWork(String repositoryName, String parentPath, String username, Blob csvBlob, CSVImporterOptions options)
public String getCategory()
Work
Used to choose an execution queue.
getCategory
in interface Work
getCategory
in class AbstractWork
null
for the defaultpublic String getTitle()
Work
public List<CSVImportLog> getImportLogs()
public void work()
Work
Work
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 call Work.isSuspending()
, and if
true
call Work.suspended()
return early with saved state data.
Clean up can by implemented by #cleanUp()
.
work
in interface Work
work
in class AbstractWork
Work.isSuspending()
,
Work.suspended()
,
Work.cleanUp(boolean, java.lang.Exception)
public void cleanUp(boolean ok, Exception e)
AbstractWork
AbstractWork.work()
is done in a finally block, whether work completed normally or was in
error or was interrupted.cleanUp
in interface Work
cleanUp
in class AbstractWork
ok
- true
if the work completed normallye
- the exception, if availableprotected BufferedReader newReader(Blob blob) throws IOException
IOException
protected void doImport(org.apache.commons.csv.CSVParser parser)
protected boolean importRecord(org.apache.commons.csv.CSVRecord record, Map<String,Integer> header)
true
if a document has been created or updated, false
otherwise.protected long getLineNumber(org.apache.commons.csv.CSVRecord record)
protected long getLineNumber(org.apache.commons.csv.CSVParser parser)
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) throws IOException
Blob
from a relative file path. The File will be looked up in the folder registered by the
nuxeo.csv.blobs.folder
property.IOException
protected Blob createBlobFromStringBlob(Blob stringBlob) throws IOException
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.IOException
protected void replaceBlobs(Map<String,Object> map) throws IOException
Blob
s with Blob
s created from Files stored in the folder registered by
the nuxeo.csv.blobs.folder
property.IOException
protected void replaceBlobs(List<Object> list) throws IOException
Blob
s with Blob
s created from Files stored in the folder registered by
the nuxeo.csv.blobs.folder
property.IOException
protected DateFormat getDateFormat()
protected boolean createDocument(long lineNumber, String newParentPath, String name, String type, Map<String,Serializable> properties)
protected boolean updateDocument(long lineNumber, DocumentRef docRef, Map<String,Serializable> properties)
protected void logError(long lineNumber, String message, String localizedMessage, String... params)
protected void sendMail()
protected String getDocumentUrl(DocumentModel doc)
protected String getUserUrl()
protected StringList buildRecipientsList(String userEmail)
public static Throwable unwrapException(Throwable t)
Copyright © 2018 Nuxeo. All rights reserved.