Interface CsvService
- All Superinterfaces:
Service
public interface CsvService extends Service
Service for converting between CSV and Model objects.
-
Method Summary
Modifier and Type Method Description java.util.List<Model>
csvToModel(java.io.InputStream csvData, java.lang.String inboundInterfaceName, java.lang.String inboundInterfaceVersion, PlatformUserContext platformUserContext)
Given a stream of CSV data, uses the provided inbound interface (typically defined in the MPT) to convert the given CSV data to model objects.java.lang.String
getFieldDelimiterFromInterface(java.lang.String interfaceName, java.lang.String interfaceVersion, boolean isInbound, PlatformUserContext pltUsrContext)
Returns the field delimiter used by the CsvInterface Default is "," (comma)java.io.InputStream
modelToCsv(ModelList<?> modelList, java.lang.String interfaceName, java.lang.String interfaceVersion, boolean isInbound, PlatformUserContext platformUserContext)
Given a list of models in com.onenetwork.platform.data.model.ModelList, this method uses the provided inbound or outbound interface to convert the given model objects to CSV data.java.io.InputStream
modelToCsv(ModelList<?> modelList, java.lang.String outboundInterfaceName, java.lang.String outboundInterfaceVersion, PlatformUserContext platformUserContext)
LikemodelToCsv(ModelList, String, String, boolean, PlatformUserContext)
, but assumes the interface is outbound.void
transformFieldDelimiter(java.io.InputStream in, char inDelimiter, java.io.OutputStream out, char outDelimiter, PlatformUserContext pltUsrContext)
Transforms the inputStream to change the delimiter to the one specified and writes the new payload to the outputStream.
-
Method Details
-
csvToModel
java.util.List<Model> csvToModel(java.io.InputStream csvData, java.lang.String inboundInterfaceName, java.lang.String inboundInterfaceVersion, PlatformUserContext platformUserContext)Given a stream of CSV data, uses the provided inbound interface (typically defined in the MPT) to convert the given CSV data to model objects. Please note that the Processor for the inbound interface will not be called. This method purely uses the Format of the interface to convert the CSV fields to Model fields. This code operates by looking for fields on Model level fields in the format and mapping those to the corresponding fields on the Model object. If there are errors in processing, like Date format errors/etc, the Model object will still be instantiated, but an Error will be set on the Model object to describe the parse error. (Also InputRefId will reference the row number using a zero-based index) For multi-level models, parent level data should be denormalized. For example, to instantiate two Shipments with two ShipmentLine children each, one might have:ShipmentNo1,ShipmentLine1 ShipmentNo1,ShipmentLine2 ShipmentNo2,ShipmentLine1 ShipmentNo2,ShipmentLine2
- Parameters:
csvData
- comma-separated data (or may use another delimiter if specified as such in the inbound interface)inboundInterfaceName
- name of the inbound interfaceinboundInterfaceVersion
- version of the inbound interfaceplatformUserContext
- caller's context- Returns:
- Model objects
-
modelToCsv
java.io.InputStream modelToCsv(ModelList<?> modelList, java.lang.String outboundInterfaceName, java.lang.String outboundInterfaceVersion, PlatformUserContext platformUserContext)LikemodelToCsv(ModelList, String, String, boolean, PlatformUserContext)
, but assumes the interface is outbound. -
modelToCsv
java.io.InputStream modelToCsv(ModelList<?> modelList, java.lang.String interfaceName, java.lang.String interfaceVersion, boolean isInbound, PlatformUserContext platformUserContext)Given a list of models in com.onenetwork.platform.data.model.ModelList, this method uses the provided inbound or outbound interface to convert the given model objects to CSV data. (Please note that the processor/generator for interface will not be called.) This method purely uses the Format of the interface to convert the Model fields to CSV fields. This code operates by looking for fields on Model level fields in the format and mapping those to the corresponding fields on the Model object. For multi-level models, parent level data will be denormalized. For example, given two Shipments with two ShipmentLine children each, the CSV generated will appear as:ShipmentNo1,ShipmentLine1 ShipmentNo1,ShipmentLine2 ShipmentNo2,ShipmentLine1 ShipmentNo2,ShipmentLine2
- Parameters:
modelList
-interfaceName
-interfaceVersion
-isInbound
- true if interface is inbound, false owplatformUserContext
-- Returns:
- contains the CSV data
-
transformFieldDelimiter
void transformFieldDelimiter(java.io.InputStream in, char inDelimiter, java.io.OutputStream out, char outDelimiter, PlatformUserContext pltUsrContext)Transforms the inputStream to change the delimiter to the one specified and writes the new payload to the outputStream. Note - Caller must close the streams because this can be used in conjunction with other transforms.- Parameters:
in
- InputStream of the orginal payloadinDelimiter
- current delimiter on the input payloadout
- OutputStream of the transformed payloadoutDelimiter
- Custom delimiter that will be used for transformation of the payloadpltUsrContext
- Context contains user information who is performing this transformation
-
getFieldDelimiterFromInterface
java.lang.String getFieldDelimiterFromInterface(java.lang.String interfaceName, java.lang.String interfaceVersion, boolean isInbound, PlatformUserContext pltUsrContext)Returns the field delimiter used by the CsvInterface Default is "," (comma)- Parameters:
interfaceName
- name of the CsvInterfaceinterfaceVersion
- version of the CsvInterfaceisInbound
- to indicate if the interface is inbound when set to true or outbound when set to falsepltUsrContext
- Context contains user information who is performing this transformation- Returns:
- field delimiter used by the CsvInterface
-