Class AbstractJsonArrayToXMLFileTransformer<S,D>
java.lang.Object
com.broadleafcommerce.datafeed.service.publisher.file.transformer.AbstractJsonArrayToXMLFileTransformer<S,D>
- Type Parameters:
S
- seeDataFeedElementTransformer.getSourceElementType()
D
- seeDataFeedElementTransformer.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.
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionAbstractJsonArrayToXMLFileTransformer
(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, DataFeedElementTransformer<S, D> elementTransformer, int maxSourceElementsToReadInBatch) -
Method Summary
Modifier and TypeMethodDescriptionprotected DataFeedFileTransformResponseDetails
buildFailedResponse
(List<String> errorDetails) protected DataFeedFileTransformResponseDetails
buildSuccessResponse
(boolean resultShouldBeSubmitted) protected com.fasterxml.jackson.dataformat.xml.XmlMapper
Generally sensible defaults for a XmlMapper.protected DataFeedElementTransformer<S,
D> Delegate for converting source elements into destination elements.protected int
Limits the number of elements that are read from the source file at a time.protected com.fasterxml.jackson.databind.ObjectMapper
protected com.broadleafcommerce.common.extension.TypeFactory
transform
(AbstractFileFeedPublisher.FilePublishContext publishContext) For reference, see this article on writing XML with Jacksonprotected abstract void
writePostDefinition
(BufferedWriter bufferedWriter, com.fasterxml.jackson.dataformat.xml.XmlMapper xmlMapper, AbstractFileFeedPublisher.FilePublishContext filePublishContext) This is a hook point allowing implementations to write anything to the output file after the main elements are serialized.protected abstract void
writePreDefinition
(BufferedWriter bufferedWriter, com.fasterxml.jackson.dataformat.xml.XmlMapper xmlMapper, AbstractFileFeedPublisher.FilePublishContext filePublishContext) This is a hook point allowing implementations to write anything to the output file before the main elements are serialized.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.datafeed.service.publisher.file.transformer.DataFeedFileTransformer
canHandle, createLocalOutputFile, getOrder
-
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
public DataFeedFileTransformResponseDetails transform(AbstractFileFeedPublisher.FilePublishContext publishContext) For reference, see this article on writing XML with Jackson- Specified by:
transform
in interfaceDataFeedFileTransformer
- 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
-
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 transformationfilePublishContext
- 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 inwritePreDefinition(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 transformationfilePublishContext
- 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
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.
-