Class DefaultImportProcessor
- All Implemented Interfaces:
ImportProcessor
- Author:
- Phillip Verheyden (phillipuniverse)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultImportProcessor(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 TypeMethodDescriptionbooleancanProcess(Import importMetadata) Whether or not this processor can handle the given import.protected com.broadleafcommerce.common.dataimport.messaging.BatchRecordcreateBatchRecord(ImportProcessingContext<? extends FileReaderContext> context, Map<String, String> rowMap, long lineNumber) Parses the givenrecordinto aBatchRecord.getNextRowMap(ImportProcessingContext<? extends FileReaderContext> context) protected ImportmarkCompleted(String importId) protected voidnormalizeRowData(Map<String, String> row, ImportSpecification spec) voidprocess(ImportProcessingContext<? extends FileReaderContext> context) Performs the operations required to transform the givenfileinto persisting into a backing data store.protected booleanreplaceCorrelationIdsAndCollectErrors(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 therowsof the givenBatchRecordand its dependents with the corresponding resource IDs.protected voidprotected StringResolves the correlation ID value from the givenrow.protected StringresolveAndRemoveId(Map<String, String> row) Resolves the ID value from the givenrow.protected com.broadleafcommerce.common.dataimport.messaging.OperationTypeResolves 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:ImportProcessorWhether or not this processor can handle the given import.- Specified by:
canProcessin interfaceImportProcessor- Parameters:
importMetadata- details about a particular import that needs to be processed- Returns:
trueif this processor should handle the import,falseotherwise
-
process
Description copied from interface:ImportProcessorPerforms the operations required to transform the givenfileinto 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
BatchItemCompletionis created in the data store for each. TheImport.errorCountis updated accordingly.If at the end of this processing, the processor detects that the
Import.successCountandImport.errorCountsum toImport.totalItems, it will mark the import as complete.- Specified by:
processin 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 therowsof the givenBatchRecordand 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).
BatchItemCompletionswill 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- aBatchRecordwhose 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 aBatchItemCompletiongenerated and added to this listtopLevelParentCorrelationId- the correlation ID of the top-level (main-record) parent therecordbelongs to. This is used to setBatchItemCompletion.setTopLevelParentCorrelationId(String). If the givenrecordis the top-level parent itself, this should be its correlation ID.- Returns:
- whether or not the
recorditself had its correlation ID references successfully resolved and replaced. A return value oftruedoes 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 caseerrorswill 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 givenrecordinto 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
BatchRecordrepresenting 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,
nullotherwise
-
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,
nullotherwise
-
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,
nullotherwise
-