Class DefaultImportProcessor

java.lang.Object
com.broadleafcommerce.dataimport.processor.csv.DefaultImportProcessor
All Implemented Interfaces:
ImportProcessor

public class DefaultImportProcessor extends Object implements ImportProcessor
Author:
Phillip Verheyden (phillipuniverse)
  • Field Details

  • Constructor Details

  • Method Details

    • canProcess

      public boolean canProcess(Import importMetadata)
      Description copied from interface: ImportProcessor
      Whether or not this processor can handle the given import.
      Specified by:
      canProcess in interface ImportProcessor
      Parameters:
      importMetadata - details about a particular import that needs to be processed
      Returns:
      true if this processor should handle the import, false otherwise
    • process

      public void process(ImportProcessingContext<? extends FileReaderContext> context)
      Description copied from interface: ImportProcessor
      Performs the operations required to transform the given file 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. The Import.errorCount is updated accordingly.

      If at the end of this processing, the processor detects that the Import.successCount and Import.errorCount sum to Import.totalItems, it will mark the import as complete.

      Specified by:
      process in interface ImportProcessor
      Parameters:
      context - the current import being executed
    • markCompleted

      @Nullable protected Import markCompleted(String importId)
    • 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 the rows of the given BatchRecord 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 to errors. Any dependents which failed resolution will be removed from their parent record's BatchRecord.getDependents() list, leaving only those which were successful.

      Parameters:
      record - a BatchRecord whose correlation ID references should be resolved and replaced. Should already have all of its BatchRecord.getDependents() set and correctly organized into a hierarchy.
      context - context about the import that is currently being processed
      errors - any records deemed to be errored should have a BatchItemCompletion generated and added to this list
      topLevelParentCorrelationId - the correlation ID of the top-level (main-record) parent the record belongs to. This is used to set BatchItemCompletion.setTopLevelParentCorrelationId(String). If the given record 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 of true 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 case errors will have been updated to have their completions, and those dependents will have been removed from their parent record's BatchRecord.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 given record into a BatchRecord.
      Parameters:
      context - information about the current import being processed
      rowMap - the record read from the file
      lineNumber - the line number to assign to the BatchRecord.lineNumber
      Returns:
      a newly created BatchRecord representing the given record
    • resolveAndRemoveOperationType

      @Nullable protected com.broadleafcommerce.common.dataimport.messaging.OperationType resolveAndRemoveOperationType(Map<String,String> row)
      Resolves the operation type value from the given row.
      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

      @Nullable protected String resolveAndRemoveId(Map<String,String> row)
      Resolves the ID value from the given row.

      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

      protected void normalizeRowData(Map<String,String> row, ImportSpecification spec)
    • replaceHeaderNameWithPropertyName

      protected Map<String,String> replaceHeaderNameWithPropertyName(Map<String,String> row, ImportSpecification spec)
    • resolveAndRemoveCorrelationId

      @Nullable protected String resolveAndRemoveCorrelationId(Map<String,String> row)
      Resolves the correlation ID value from the given row.
      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