Class DefaultImportProcessor
- All Implemented Interfaces:
ImportProcessor
- Author:
- Phillip Verheyden (phillipuniverse)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultImportProcessor
(int batchSize, BatchManager batchManager, ImportService<Import> importService, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService) DefaultImportProcessor
(int batchSize, BatchManager batchManager, ImportService<Import> importService, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver, com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver, CorrelationIdMappingCache correlationIdCache) DefaultImportProcessor
(BatchManager batchManager, ImportService<Import> importService, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService) Initializes the processor with a batch size of 100 -
Method Summary
Modifier and TypeMethodDescriptionboolean
canProcess
(Import importMetadata) Whether or not this processor can handle the given import.protected com.broadleafcommerce.common.dataimport.messaging.BatchRecord
createBatchRecord
(ImportProcessingContext<? extends FileReaderContext> context, Map<String, String> rowMap, long lineNumber) Parses the givenrecord
into aBatchRecord
.getNextRowMap
(ImportProcessingContext<? extends FileReaderContext> context) protected Import
markCompleted
(String importId) protected void
normalizeRowData
(Map<String, String> row, ImportSpecification spec) void
process
(ImportProcessingContext<? extends FileReaderContext> context) Performs the operations required to transform the givenfile
into persisting into a backing data store.protected boolean
replaceCorrelationIdsAndCollectErrors
(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, ImportProcessingContext<? extends FileReaderContext> context, List<BatchItemCompletion> errors, String topLevelParentCorrelationId) Resolves and replaces any correlation id references found in therows
of the givenBatchRecord
and its dependents with the corresponding resource IDs.protected void
protected String
Resolves the correlation ID value from the givenrow
.protected String
resolveAndRemoveId
(Map<String, String> row) Resolves the ID value from the givenrow
.protected com.broadleafcommerce.common.dataimport.messaging.OperationType
Resolves the operation type value from the givenrow
.
-
Field Details
-
CORRELATION_ID_COLUMN
- See Also:
-
OPERATION_COLUMN
- See Also:
-
ID_COLUMN
- See Also:
-
CORRELATION_ID_ERROR
- See Also:
-
PARENT_RECORD_ERROR
- See Also:
-
-
Constructor Details
-
DefaultImportProcessor
public DefaultImportProcessor(BatchManager batchManager, ImportService<Import> importService, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService) Initializes the processor with a batch size of 100 -
DefaultImportProcessor
public DefaultImportProcessor(int batchSize, BatchManager batchManager, ImportService<Import> importService, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService) -
DefaultImportProcessor
public DefaultImportProcessor(int batchSize, BatchManager batchManager, ImportService<Import> importService, BatchItemCompletionService<BatchItemCompletion> batchItemCompletionService, com.broadleafcommerce.common.dataimport.util.IdResolver idResolver, com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver, CorrelationIdMappingCache correlationIdCache)
-
-
Method Details
-
canProcess
Description copied from interface:ImportProcessor
Whether or not this processor can handle the given import.- Specified by:
canProcess
in interfaceImportProcessor
- Parameters:
importMetadata
- details about a particular import that needs to be processed- Returns:
true
if this processor should handle the import,false
otherwise
-
process
Description copied from interface:ImportProcessor
Performs the operations required to transform the givenfile
into persisting into a backing data store. The actual persistence will usually be remote and so this processor's main job is to convert the file to a JSON representation and publish batch messages for resource tiers to persist to their data store.Any records which are detected to have errors (ex: invalid row types) are pruned from the published batches, and a new
BatchItemCompletion
is created in the data store for each. TheImport.errorCount
is updated accordingly.If at the end of this processing, the processor detects that the
Import.successCount
andImport.errorCount
sum toImport.totalItems
, it will mark the import as complete.- Specified by:
process
in interfaceImportProcessor
- Parameters:
context
- the current import being executed
-
markCompleted
-
replaceCorrelationIdsAndCollectErrors
protected boolean replaceCorrelationIdsAndCollectErrors(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, ImportProcessingContext<? extends FileReaderContext> context, List<BatchItemCompletion> errors, String topLevelParentCorrelationId) Resolves and replaces any correlation id references found in therows
of the givenBatchRecord
and its dependents with the corresponding resource IDs.If a record's correlation ID references are successfully resolved, its own correlation ID/resource ID pair will be placed in the cache.
At any point, if a record is found to have unresolvable correlation ID references, it and all of its dependents will be considered failed (no attempt will be made to resolve the correlation IDs of the dependents).
BatchItemCompletions
will be generated for all of them and added toerrors
. Any dependents which failed resolution will be removed from their parent record'sBatchRecord.getDependents()
list, leaving only those which were successful.- Parameters:
record
- aBatchRecord
whose correlation ID references should be resolved and replaced. Should already have all of itsBatchRecord.getDependents()
set and correctly organized into a hierarchy.context
- context about the import that is currently being processederrors
- any records deemed to be errored should have aBatchItemCompletion
generated and added to this listtopLevelParentCorrelationId
- the correlation ID of the top-level (main-record) parent therecord
belongs to. This is used to setBatchItemCompletion.setTopLevelParentCorrelationId(String)
. If the givenrecord
is the top-level parent itself, this should be its correlation ID.- Returns:
- whether or not the
record
itself had its correlation ID references successfully resolved and replaced. A return value oftrue
does not necessarily mean all of the record's dependents had their correlation IDs successfully resolved. It is possible they (and/or their children) failed, in which caseerrors
will have been updated to have their completions, and those dependents will have been removed from their parent record'sBatchRecord.getDependents()
list. - See Also:
-
createBatchRecord
protected com.broadleafcommerce.common.dataimport.messaging.BatchRecord createBatchRecord(ImportProcessingContext<? extends FileReaderContext> context, Map<String, String> rowMap, long lineNumber) Parses the givenrecord
into aBatchRecord
.- Parameters:
context
- information about the current import being processedrowMap
- the record read from the filelineNumber
- the line number to assign to theBatchRecord.lineNumber
- Returns:
- a newly created
BatchRecord
representing the givenrecord
-
resolveAndRemoveOperationType
@Nullable protected com.broadleafcommerce.common.dataimport.messaging.OperationType resolveAndRemoveOperationType(Map<String, String> row) Resolves the operation type value from the givenrow
.- Parameters:
row
- the row from which to resolve the operation type value- Returns:
- the operation type value from the given row if found,
null
otherwise
-
resolveAndRemoveId
Resolves the ID value from the givenrow
.This method signature is a misnomer, and it (and overrides) are not expected to remove the ID entry from the
row
. The name is only kept for backwards compatibility.- Parameters:
row
- the row from which to resolve the ID value- Returns:
- the ID value from the given row if found,
null
otherwise
-
getNextRowMap
protected Map<String,String> getNextRowMap(ImportProcessingContext<? extends FileReaderContext> context) -
replaceNullRowValuesWithSpecDefaults
protected void replaceNullRowValuesWithSpecDefaults(Map<String, String> row, ImportSpecification spec) -
normalizeRowData
-
replaceHeaderNameWithPropertyName
-
resolveAndRemoveCorrelationId
Resolves the correlation ID value from the givenrow
.- Parameters:
row
- the row from which to resolve the correlation ID value.- Returns:
- the correlation ID value from the given row if found,
null
otherwise
-