@Service(value="blCSVFileImportProcessor") public class CSVFileImportProcessor extends Object implements FileImportProcessor
Modifier and Type | Field and Description |
---|---|
protected List<BroadleafCellProcessor> |
cellProcessors |
static String |
CONTEXT_HEADERS |
protected BroadleafCellProcessor |
defaultProcessor |
protected org.broadleafcommerce.common.persistence.EntityConfiguration |
entityConfiguration |
protected DynamicEntityDaoProvider |
entityDaoProvider |
protected ExternalIdUtil |
externalIdUtil |
protected List<HeaderNameFilter> |
headerNameFilters |
protected List<HeaderNameMapper> |
headerNameMappers |
protected Map<String,String[]> |
headerSpecification
If the import file does not have a header attached to it, this is a map from ceilingClass -> headers that can serve
as the specification in lieu of a first-line header.
|
protected ImportPersister |
importPersister |
protected org.springframework.context.MessageSource |
messageSource |
protected ImportPersister |
orderImportPersister |
protected com.broadleafcommerce.process.manager.ProcessStateManager |
processStateManager |
Constructor and Description |
---|
CSVFileImportProcessor() |
Modifier and Type | Method and Description |
---|---|
protected void |
addValidationDetails(Long processId,
org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse response,
long recordNumber) |
int |
calculateTotalRecords(File uploadedFile)
Given an InputStream, the implementation should calculate the total number of records to be processed.
|
boolean |
canHandle(File uploadedFile,
ImportSpecification importSpecification,
ImportType importType)
Whether or not this can handle the given input according to the
ImportSpecification |
protected BroadleafCsvReader |
createReader(File file,
List<String> ignoredHeaders) |
int |
getBatchSize() |
List<BroadleafCellProcessor> |
getCellProcessors() |
protected String[] |
getHeaders(BroadleafCsvReader reader,
ImportType importType) |
Map<String,String[]> |
getHeaderSpecification() |
protected List<String> |
getIgnoreHeaderList(ImportContext context) |
protected Class<?> |
getImplForRequest(Class<?> importingClass,
Map<String,ColumnParseResult> row) |
protected List<BroadleafCellProcessor> |
getProcessorsForHeader(String header,
ImportContext context)
Returns the first processor representing the header
|
protected Map<String,List<BroadleafCellProcessor>> |
getProcessorsForHeaders(String[] headers,
ImportContext context) |
boolean |
isPrimaryKeyPopulated(Map<String,ColumnParseResult> row,
ImportType importType) |
RecordParseResult |
parseRow(Map<String,ColumnParseResult> row,
ImportContext context)
Takes an individual row and parses it into a record suitable for writing to the db via the
ImportPersister |
void |
populatePrimaryKeys(List<RowParseResult> rows,
ImportType importType)
For a given row, this will populate the primary key in the map of processed results.
|
void |
processFile(File uploadedFile,
Long processId,
ImportContext context)
This is designed to process and parse out a given uploadedFile and persist the records to the database.
|
protected List<RecordParseResult> |
readBatch(BroadleafCsvReader reader,
int batchSize,
Map<String,List<BroadleafCellProcessor>> processors,
ImportContext context)
Reads in and processes a batch of records.
|
void |
setCellProcessors(List<BroadleafCellProcessor> cellProcessors) |
void |
setHeaderSpecification(Map<String,String[]> headerSpecification) |
protected List<BroadleafCellProcessor> cellProcessors
protected BroadleafCellProcessor defaultProcessor
protected List<HeaderNameMapper> headerNameMappers
@Autowired(required=false) protected List<HeaderNameFilter> headerNameFilters
protected ImportPersister importPersister
protected ImportPersister orderImportPersister
protected com.broadleafcommerce.process.manager.ProcessStateManager processStateManager
protected org.broadleafcommerce.common.persistence.EntityConfiguration entityConfiguration
protected ExternalIdUtil externalIdUtil
protected DynamicEntityDaoProvider entityDaoProvider
protected org.springframework.context.MessageSource messageSource
protected Map<String,String[]> headerSpecification
public static final String CONTEXT_HEADERS
public boolean canHandle(File uploadedFile, ImportSpecification importSpecification, ImportType importType)
FileImportProcessor
ImportSpecification
canHandle
in interface FileImportProcessor
uploadedFile
- the file that was uploaded by the userimportSpecification
- the metadata about uploadedFile in order to determine if it should be processedpublic int calculateTotalRecords(File uploadedFile) throws ImportException
FileImportProcessor
calculateTotalRecords
in interface FileImportProcessor
ImportException
- if there was a problem in processing the uploadedFilepublic void processFile(File uploadedFile, Long processId, ImportContext context) throws ImportException
FileImportProcessor
processFile
in interface FileImportProcessor
uploadedFile
- the original file that was uploaded by the userImportException
- if there was a problem in processing the inputStreamprotected void addValidationDetails(Long processId, org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse response, long recordNumber) throws ClassNotFoundException
ClassNotFoundException
protected List<RecordParseResult> readBatch(BroadleafCsvReader reader, int batchSize, Map<String,List<BroadleafCellProcessor>> processors, ImportContext context) throws IOException
IOException
protected String[] getHeaders(BroadleafCsvReader reader, ImportType importType) throws IOException
IOException
public RecordParseResult parseRow(Map<String,ColumnParseResult> row, ImportContext context)
ImportPersister
public boolean isPrimaryKeyPopulated(Map<String,ColumnParseResult> row, ImportType importType)
public void populatePrimaryKeys(List<RowParseResult> rows, ImportType importType)
For a given row, this will populate the primary key in the map of processed results. If the given map was changed OR if the map already contained the primary key. This will denote whether or not the persist request for this row is an ADD or an UPDATE.
This should be done prior to converting rows into a PersistencePackageRequest
.
rows
- importType
- protected Class<?> getImplForRequest(Class<?> importingClass, Map<String,ColumnParseResult> row)
protected Map<String,List<BroadleafCellProcessor>> getProcessorsForHeaders(String[] headers, ImportContext context)
protected BroadleafCsvReader createReader(File file, List<String> ignoredHeaders) throws FileNotFoundException
FileNotFoundException
protected List<BroadleafCellProcessor> getProcessorsForHeader(String header, ImportContext context)
header
- context
- protected List<String> getIgnoreHeaderList(ImportContext context)
public int getBatchSize()
public List<BroadleafCellProcessor> getCellProcessors()
public void setCellProcessors(List<BroadleafCellProcessor> cellProcessors)
Copyright © 2020. All rights reserved.