Class AbstractJsonArrayToXMLFileTransformer<S,D>

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

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

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

    • AbstractJsonArrayToXMLFileTransformer

      public AbstractJsonArrayToXMLFileTransformer(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
    • buildXMLMapper

      protected com.fasterxml.jackson.dataformat.xml.XmlMapper buildXMLMapper()
      Generally sensible defaults for a XmlMapper.
      Returns:
      the XmlMapper to write with
    • buildFailedResponse

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

      protected DataFeedFileTransformResponseDetails buildSuccessResponse(boolean resultShouldBeSubmitted)
    • writePreDefinition

      protected abstract void writePreDefinition(BufferedWriter bufferedWriter, com.fasterxml.jackson.dataformat.xml.XmlMapper xmlMapper, AbstractFileFeedPublisher.FilePublishContext filePublishContext) throws IOException
      This is a hook point allowing implementations to write anything to the output file before the main elements are serialized. For example, an implementation could use this method to write an XML declaration and any desired tags.
      Parameters:
      bufferedWriter - a buffered writer for writing to the file. Implementations MUST NOT CLOSE this writer. Opening/closing this writer is already handled by the calling method.
      xmlMapper - the configured XML mapper for XML-POJO transformation
      filePublishContext - details around the file publish process
      Throws:
      IOException - if there was an I/O issue
    • writePostDefinition

      protected abstract void writePostDefinition(BufferedWriter bufferedWriter, com.fasterxml.jackson.dataformat.xml.XmlMapper xmlMapper, AbstractFileFeedPublisher.FilePublishContext filePublishContext) throws IOException
      This is a hook point allowing implementations to write anything to the output file after the main elements are serialized. For example, an implementation could use this method to close any tags that were previously written in writePreDefinition(BufferedWriter, XmlMapper, FilePublishContext).
      Parameters:
      bufferedWriter - a buffered writer for writing to the file. Implementations MUST NOT CLOSE this writer. Opening/closing this writer is already handled by the calling method.
      xmlMapper - the configured XML mapper for XML-POJO transformation
      filePublishContext - details around the file publish process
      Throws:
      IOException - if there was an I/O issue
    • 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.