Class CSVErrorsReportService
java.lang.Object
com.broadleafcommerce.dataimport.service.CSVErrorsReportService
- All Implemented Interfaces:
ErrorsReportService
Retrieves or generates the new import error report in "csv" format.
- Author:
- Dima Myroniuk (dmyroniuk), Phillip Verheyden
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classWrapper ofCsvWriterthat implementsAutoCloseablefor use in try-with-resources statements. -
Constructor Summary
ConstructorsConstructorDescriptionCSVErrorsReportService(ImportService<Import> importService, StorageService storage, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService, ImportManager importManager) -
Method Summary
Modifier and TypeMethodDescriptionbuildCsvWriter(File file) protected com.univocity.parsers.csv.CsvWriterSettingsOptional<org.springframework.core.io.Resource>getErrorsReport(String importId) Note that the use ofTransactionalis intentional - a transaction is required to keep the connection open for the entire read of theBatchItemCompletionService.readAllByImportIdAndStatus(String, String)stream.protected String[]getHeadersFromOriginalFile(InputStream originalFile) protected LinkedHashSet<String>getHeadersToWrite(InputStream originalFile, Map<String, String> propertyNameToHeaderName) protected ImportSpecificationServicegetRowWithAdditionalDataAdded(BatchItemCompletion batchItemCompletion, Map<String, String> propertyNameToHeaderName, ImportSpecification specification) Takes the original row frombatchItemCompletionand returns a new row with mutations and additional entries as necessary.Deprecated, for removal: This API element is subject to removal in a future version.booleanisEligibleForErrorsDownload(Import metadata) A simple method that examines the givenmetadataobject to determine whether an errors report can be created for it.voidsetErrorMessageHeader(String errorMessageHeader) Header in the error download that maps to the error that occurred with the recordvoidsetImportSpecificationService(ImportSpecificationService importSpecificationService) voidsetLineNumberHeader(String lineNumberHeader) Header in the error download that maps back to the line number in the original file
-
Constructor Details
-
CSVErrorsReportService
public CSVErrorsReportService(ImportService<Import> importService, StorageService storage, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService, ImportManager importManager)
-
-
Method Details
-
getErrorsReport
@Transactional("importTransactionManager") public Optional<org.springframework.core.io.Resource> getErrorsReport(String importId) Note that the use ofTransactionalis intentional - a transaction is required to keep the connection open for the entire read of theBatchItemCompletionService.readAllByImportIdAndStatus(String, String)stream.- Specified by:
getErrorsReportin interfaceErrorsReportService- Parameters:
importId- the id of the import- Returns:
- the resource, or an empty optional if an errors report cannot be generated for the
given import (either because the result of
isEligibleForErrorsDownload(Import)is false, or if there are no errors to build the report from) - See Also:
-
isEligibleForErrorsDownload
Description copied from interface:ErrorsReportServiceA simple method that examines the givenmetadataobject to determine whether an errors report can be created for it.The default implementation is simply to check that the import has a non-zero errors count and has a finished
Import.status.- Specified by:
isEligibleForErrorsDownloadin interfaceErrorsReportService- Parameters:
metadata- the import which should be checked for errors report eligibility- Returns:
- true if an errors report can be generated for the given import, false otherwise
- See Also:
-
getHeadersToWrite
protected LinkedHashSet<String> getHeadersToWrite(InputStream originalFile, Map<String, String> propertyNameToHeaderName) -
getHeadersFromOriginalFile
- Throws:
IOException
-
getRowWithAdditionalDataAdded
protected Map<String,String> getRowWithAdditionalDataAdded(BatchItemCompletion batchItemCompletion, Map<String, String> propertyNameToHeaderName, ImportSpecification specification) Takes the original row frombatchItemCompletionand returns a new row with mutations and additional entries as necessary. For example, this will map back from field names to header names, as well as add additional entries for columns likeDefaultImportProcessor.OPERATION_COLUMNfor use in subsequent imports of the errors file.- Parameters:
batchItemCompletion- the batch item completion whose row should be processedpropertyNameToHeaderName- a pre-processed map containing mappings from property names to header namesspecification- the specification, useful for obtaining additional data as needed- Returns:
- a new, mutated copy of the original row
-
getSpecificationNameMap
@Deprecated(since="1.8.1", forRemoval=true) protected Map<String,String> getSpecificationNameMap(ImportSpecification spec) Deprecated, for removal: This API element is subject to removal in a future version.This method has been deprecated, and will be removed whenImportSpecification.getFieldConfigMap()is removed. Specifications should move to usingImportSpecification.getHeaderFieldConfigsByRowType().- Parameters:
spec- the import specification- Returns:
- a map of property names to header names from
ImportSpecification.getFieldConfigMap()
-
buildCsvWriter
-
buildCsvWriterSettings
protected com.univocity.parsers.csv.CsvWriterSettings buildCsvWriterSettings() -
setLineNumberHeader
Header in the error download that maps back to the line number in the original file -
setErrorMessageHeader
Header in the error download that maps to the error that occurred with the record -
setImportSpecificationService
@Autowired public void setImportSpecificationService(ImportSpecificationService importSpecificationService) -
getImportSpecificationService
-