Class AbstractJsonArrayToCSVFileTransformer<S,D>

java.lang.Object
com.broadleafcommerce.datafeed.service.publisher.file.transformer.AbstractJsonArrayToCSVFileTransformer<S,D>
Type Parameters:
S - see DataFeedElementTransformer.getSourceElementType()
D - see DataFeedElementTransformer.getDestinationElementType(). This should contain any CSV serialization configuration details as necessary, since it will be used to build the CSV schema. See buildCsvSchema(CsvMapper)
All Implemented Interfaces:
DataFeedFileTransformer, org.springframework.core.Ordered
Direct Known Subclasses:
CollectedProductJsonArrayToCommerceManagerFeedCSVFileTransformer

public abstract class AbstractJsonArrayToCSVFileTransformer<S,D> extends Object implements DataFeedFileTransformer
Common starting point for a DataFeedFileTransformer for transforming a source JSON array to a destination CSV.

This is not intended for use as a singleton bean, and each eligible use-case should define its own new extension of this type. Due to delegation of actual element conversion to DataFeedElementTransformer, this component is fairly generic and multiple beans of this type can be declared (with different names) as needed with different element transformers.

  • Constructor Details

    • AbstractJsonArrayToCSVFileTransformer

      public AbstractJsonArrayToCSVFileTransformer(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, DataFeedElementTransformer<S,D> elementTransformer, int maxSourceElementsToReadInBatch)
  • Method Details

    • transform

      Specified by:
      transform in interface DataFeedFileTransformer
      Parameters:
      publishContext - details around the file publish process
      Returns:
      details about the success/failure of the operation
    • buildCsvMapper

      protected com.fasterxml.jackson.dataformat.csv.CsvMapper buildCsvMapper()
      Generally sensible defaults for a CSV mapper.
      Returns:
      the CsvMapper to write with
    • buildCsvSchema

      protected com.fasterxml.jackson.dataformat.csv.CsvSchema buildCsvSchema(com.fasterxml.jackson.dataformat.csv.CsvMapper csvMapper)
      Parameters:
      csvMapper - the csvMapper that can be used to help construct this schema
      Returns:
      the CsvSchema to write with
    • buildFailedResponse

      protected DataFeedFileTransformResponseDetails buildFailedResponse(List<String> errorDetails)
    • buildSuccessResponse

      protected DataFeedFileTransformResponseDetails buildSuccessResponse(boolean resultShouldBeSubmitted)
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getElementTransformer

      protected DataFeedElementTransformer<S,D> getElementTransformer()
      Delegate for converting source elements into destination elements.
    • getMaxSourceElementsToReadInBatch

      protected int getMaxSourceElementsToReadInBatch()
      Limits the number of elements that are read from the source file at a time.