Inbound Support
Let's say you have an existing CSV inbound interface in the Bookstore module. It contains 4 fields: Title, PublishedDate, Rating, and PublisherAddress.
Sample data in CSV format:
#* Title,Published Date (MM/dd/yyyy),
"Rating (#,#.#####)"
,PublisherAddress
Introduction To Platform,
04
/
02
/
2014
,
9
Platform User Guide,
04
/
02
/
2014
,
10
,US~TX~Dallas~~~~
4055
Valley View Ln~~~
75000
~~~
Using CSV-as-JSON support, Platform can support the same interface using the following JSON format:
[{
"Title"
:
"Introduction To Platform"
,
"PublishedDate"
:
"04/02/2014"
,
"Rating"
:
9
,
"PublisherAddress"
:
{
"COUNTRY"
:
"US"
,
"STATE"
:
"TX"
,
"CITY"
:
"Dallas"
,
"STREET1"
:
"4055 Valley View Ln"
,
"ZIP"
:
"75000"
}
},
{
"Title"
:
"Platform User Guide"
,
"PublishedDate"
:
"04/02/2014"
,
"Rating"
:
10
,
"PublisherAddress"
:
{
"COUNTRY"
:
"CANADA"
,
"PROVINCE"
:
"Ontario"
,
"CITY"
:
"Toronto"
,
"STREET1"
:
"123 Test Street West"
,
"POSTAL_CODE"
:
"A1A 1A1"
}
}]
The input should be in the format of a JSON Array containing a JSON Object for each "row" of input, and each JSON Object has fields named as per the CSV interface to hold the data.
To process data in JSON format above, you need to define a MessageTransform with TransformClass "com.transcendsys.platform.integ.message.InboundJSONToCsvTransform". (This is in addition to any MessageQueue, MessageSource, MessageSourcePoll and Grid configuration you would use for any interface.)
After the message has been enqueued and the dequeue happens for processing, the transformer gets invoked. It transforms the JSON file to CSV. Platform processes the CSV using the CSV framework and enqueues the success or error CSV message to the response queue.
If the incoming JSON is not properly formatted, an error response will be enqueued and the task will fail.
Also if you have an identically named field across levels in the interface (e.g. State for both ShipmentHeader and ShipmentLine), then the field name in the JSON should be qualified with the level name. For example:
[{
"ShipmentNumber"
:
"ShipmentNumber9003"
,
"CreationOrganizationName"
:
"SampleOrg"
,
"CreationEnterpriseName"
:
"SampleEnterprise"
,
"ShipmentHeader.State"
:
"Awaiting"
,
"ShipmentLineNumber"
:
"ShipmentLineNumber1"
,
"ItemName"
:
"SampleItem1"
,
"ShipmentLine.State"
:
"Open"
}]
Success Response
When CSV processing is successful, Platform enqueues an empty message to the success response queue. But for JSON, we need the response to be in JSON format which would be an empty JSON array. To make this work, define another MessageTransform for Enqueue with TransformClass as "com.transcendsys.platform.integ.message.OutboundCsvToJSONTransform".
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
standalone
=
"yes"
?>
<
ModelList
xmlns
=
"http://www.onenetwork.com/Platform"
>
<
ValueChainId
>9123</
ValueChainId
>
<
CustomModelName
>Standard MessageTransform</
CustomModelName
>
<
ActionName
>PLT.Create</
ActionName
>
<
MessageTransform
>
<
ValueChainId
>9123</
ValueChainId
>
<
OutboundQueueValueChainId
>9123</
OutboundQueueValueChainId
>
<
OutboundQueueName
>outbox/Bookstore/success</
OutboundQueueName
>
<
OutboundInterface
>ZBKS.BookLoad/success</
OutboundInterface
>
<
TransformClass
>com.transcendsys.platform.integ.message.OutboundCsvToJSONTransform</
TransformClass
>
<
TransformOn
>Enqueue</
TransformOn
>
<
Precedence
>1</
Precedence
>
</
MessageTransform
>
</
ModelList
>
Please note that the OutboundQueueName and OutboundInterface in the MessageTransform XML are suffixed with "/success".
When executed, OutboundCsvToJSONTransform will generate an empty JSON array message for an empty CSV success response.
Error Response
If processing is not successful because required fields are missing, permission issues were encountered or due to business logic errors, platform enqueues an error CSV message to the error response queue. Again, to generate an outbound error response in JSON, define a MessageTransform for Enqueue with TransformClass as "com.transcendsys.platform.integ.message.OutboundCsvToJSONTransform".
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
standalone
=
"yes"
?>
<
ModelList
xmlns
=
"http://www.onenetwork.com/Platform"
>
<
ValueChainId
>9123</
ValueChainId
>
<
CustomModelName
>Standard MessageTransform</
CustomModelName
>
<
ActionName
>PLT.Create</
ActionName
>
<
MessageTransform
>
<
ValueChainId
>9123</
ValueChainId
>
<
OutboundQueueValueChainId
>9123</
OutboundQueueValueChainId
>
<
OutboundQueueName
>outbox/Bookstore/error</
OutboundQueueName
>
<
OutboundInterface
>ZBKS.BookLoad/error</
OutboundInterface
>
<
TransformClass
>com.transcendsys.platform.integ.message.OutboundCsvToJSONTransform</
TransformClass
>
<
TransformOn
>Enqueue</
TransformOn
>
<
Precedence
>1</
Precedence
>
</
MessageTransform
>
</
ModelList
>
Please note that the OutboundQueueName and OutboundInterface in the MessageTransform XML are suffixed with "/error".
When executed, the OutboundCsvToJSONTransform will generate a JSON error message for a CSV error message. Note the RecordNumber (roughly equivalent to row number in CSV) and Error (processing error detail message) in the Error response.
[{
"RecordNumber"
:
1
,
"Error"
:
"Missing required field Title"
,
"Title"
:
""
,
"PublishedDate"
:
"04/02/2014"
,
"Rating"
:
9
}]]