Open main menu

CDOT Wiki β

Changes

JSON Integration Adapter

5,482 bytes added, 22:41, 26 January 2014
no edit summary
{{Admon/obsolete}} [[category: NexJ Current Past Projects]]
[[category: NexJ Express JSON Message Adapter]]
 
== Project Repository ==
 
https://bitbucket.org/b_lim/nexj-express-json-integration-adapter/overview
 
== Project Goal==
To create an adapter for the NexJ Core similar in methodology and design of existing message adapters (XML, Fixed, CSV etc.) but using the JSON format
===Contributors===
* [[User:Gbatumbya|Grace Batumbya]]
* [[User:Brianlim | Brian Lim]]
 
== Current Status==
* '''Completed''' (February 02, 2012)
See https://bitbucket.org/b_lim/nexj-express-json-integration-adapter/changesets for changesets.
Forked NexJ code and created public repository for others to monitor progress and contribute== Project Repository ==BitBucket : https://bitbucket.org/gbatumbya/nexjexpress-jsonintergrationadapter/<br/>Deprecated: <del>https://bitbucket.org/b_lim/nexj-express-json-integration-adapter/</del>
Completed overview of NexJ Integration classes and coding method and class stubs. In process of creating unit tests.
==Project PhasesDefinitions == {| class="wikitable" border="1"|-! Term! Description|-| Formatter| Turns data into JSON|-| Parser| Turns JSON into data|-| Message| The metadata to be used when formatting and parsing a message. The grammar. It is a tree-like structure.|-| MessageInstance| The information to be parsed or formatted|} Because the Integration layer allows a Model to interact with external applications asynchronously, a description / grammar of the data to be exchanged between the two systems is defined using a Message in the Model.  * Formatting is turning internal NexJ representation of a MessageInstance into JSON. The formatter is given a Message (the grammar), MessageInstance (the data), and a pipe. This accomplished by walking the Message tree-like structure while validating the data in the MessageInstance and streaming JSON format to the pipe. If the data in the MessageInstance does not conform to the Message, the formatter throws an exception. * Parsing is turning JSON representation of a MessageInstance into an internal NexJ representation of a MessageInstance. The parser is given a Message (the grammar) and an input stream. First the input stream is parsed for JSON using a JSONParser which returns either an Object or an Array. The formatter walks the Message building the structure of the MessageInstance and adding validated values in the object returned by the JSONParser to the MessageInstance. If the data from the input stream does not match the expected input at any time, the parser throws an exception.  ==== Message Fundamentals ====Message - Messages can contain values or other messages. The red nodes are messages, the green nodes are values. [[File:NexJExpressMessages.gif|NexJ Express Messages]] Internally, messages are Transfer Objects. To determine if a node is a message, use instanceof on CompositeMessagePartInstance after retrieving the MessagePart. For example, <pre>public void format(TransferObject tobj, Message message, Output out) throws IntegrationException{...CompositeMessagePart root = message.getRoot(); // Gets the root of the message.Iterator it = root.getPartIterator();while (it.hasNext()){ part = (MessagePart)it.next()); if (part instanceof CompositeMessagePartInstance) { // This part is a message } else if (part instanceof PrimitiveMessagePart) { // This part is a value }...}...</pre>
JSON Integration Adapter PhasesNOTE: THE MESSAGE PARAMETER DOES NOT CONTAIN THE MESSAGE VALUES. THE MESSAGE PARAMETER CONTAINS THE MESSAGE METADATA. THE TRANSFER OBJECT CONTAINS THE MESSAGE VALUES WHICH MUST BE VALIDATED AGAINST THE MESSAGE TO ENSURE CORRECT FORMAT.
Phase I; MessagePart:Parts of a message. Messages can contain values or other messages. NexJ Express has two types of message parts, ''CompositeMessagePart'' and ''PrimitiveMessagePart''. Research
# ; CompositeMessagePart: implementation is CompositeMessagePartInstance . The relationship between CompositeMessagePartInstance and PrimitiveMessagePart with the above picture is as follows - CompositeMessagePartInstance are messages (the red nodes) and PrimitiveMessagePart are values (the green nodes). To determine multiplicity of MessageParts, use isCollection() method of MessagePart. Note that multiplicity of the above screenshot are all '''[0..1]''', that is zero or one instance. Possible node multiplicities:; '''[0..1]''' : zero or one instance (i.e. Complete Fundamentals an optional entry); '''[1..1]''' : exactly one instance (i.e. required); '''[1..N]''' : collection of NexJ Studio tutorialat least one, at most N instances# 2; '''[0.. Complete NexJ Integration tutorial0]''' : collection of zero to infinite instances (displayed as '''[*]''')# 3; '''[1. Install NexJ Studio Express from source.0]''' : collection of at least one, possibly unlimited instances
Phase II; XMLJSONMessageMappingLoader: Used by the framework to autoload JSONMessagePartMapping for each of the message parts. Planning and Approval
# 1; JSONMessagePartMapping: Each node in the above picture ''may'' has a corresponding JSONMessagePartMapping. Each node may have its own mapping, with its own values initialized in XMLJSONMessageMappingLoader. In order to get the mapping, first cast MessagePart to a concrete class such as CompositeMessagePartInstance or PrimitiveMessagePart, then use part. Receive general approval for project# 2getMapping(). Receive approval The purpose of the mapping is metadata for JSON encoding options# 3each node. Receive approval for JSON formatting options
Phase III; JSONMessageFormatter: Used to turn messages into JSON format. Message Formatter
# 1. Add JSON ; JSONMessageParser: Used to .XSD base types# 2. Create sample JSON .message # 3. Parse sample turn JSON .into a message with JUnit Test# 4. Create first set of unit tests for Message Formatter# 5. Code Message Formatter first draft# 6. Resolve issues with first set of unit tests# 7. Create second set of unit tests# 8. Resolve issues with second set of unit tests# 9. Refactor and code message formatter Phase IV. Message Parser First Draft
# 1. Discover how to connect JSON RPC parser with Message Parser# 2. Create first set of trivial unit tests for Message Parser# 3. Code Message Parser skeleton# 4. Pass first set of trivial unit tests# 5. Create second set of unit tests (non-trivial) for Message Parser# 6. Code Message Formatter first draft# 7. Resolve issues with second set of unit tests# 8. Refactor==== Algorithm ====
Phase Vformat(TransferObject tobj, Message message, Output out)Algorithm for format method is as follows# Retrieve the root of the message# Iterate through each of the parts of the root## If the part is a CompositeMessagePartInstance, it is a message node## If the part is a PrimitiveMessagePart, it is a value node## Validate the part against the MessagePartMapping. Integration Different types of validation must be done if the part is a Composite versus if it is a Primitive.## If the part is a CompositeMessagePartInstance, recursively call the format method with TransferObject set to the part. Suggested to overload the format method to format(TransferObject tobj, MessagePart message, Output out) and Stress Testspass in the part, since retrieving a message root with getRoot() will always get the highest root of the message but what you want is the parent.## If the part is a PrimitiveMessagePart, write the message part to the output.
# 1. Test Message Formatter and Message Parser with integration and stress tests
# 2. Test through NexJ Studio Express GUI (manual testing)
Phase VI. Internal Code Review==Project Phases==
# ===Phase 1. Internally review code at CDOTResearch (DONE)===# Complete Fundamentals of NexJ Studio tutorial# Complete NexJ Integration tutorial# Install NexJ Studio Express from source
===Phase VII2. OptimizationDesign Proposal (DONE)===# Receive general approval for project# Receive approval for JSON encoding options# Receive approval for JSON formatting options# [https://docs.google.com/document/d/1wAjG-xSJi227GBPUZtADAROSydIn3KuimoZarqO7xDQ/edit?hl=en_US Final Project Proposal]
===Phase 3. Create Classes (DONE)===# JSONMessagePartMapping# XMLJSONMessageMappingLoader# JSONMessageFormatter# 1. Find more code optimizations relevant to Enterprise environmentsJSONMessageParser# JSONMessageFormatterTest
===Phase VIII4. First Internal Code Review (DONE)===# Internally review code at NexJCDOT
===Phase 5. Code Review 1 (DONE)===# August 9, 2011# 1Code review took place at NexJ with [[User:Gbatumbya|Grace Batumbya]], [[User:Brianlim | Brian Lim]] and Andrew Borzenko (NexJ Developer) in attendance. Date TBA
===Phase IX6. Apply Changes from Code RewriteReview 1===# Estimated Duration: 3 Weeks (August 29, 2011)# [[JSON_Integration_Adapter_Code_Review_1_Changes | Changes to make]]'''Summary of [[JSON_Integration_Adapter_Code_Review_1_Changes | changes]]'''# Allowing modes for all Composite message parts, not just the root.# Refactoring methods to check for != right condition instead of checking for the wrong condition to throw an exception. (whitelist instead of blacklist)# Formatting all primitives before writing or storing them (e.g. timestamps, decimal numbers.)# Creating a RootJSONMessagePartMapping extending JSONMessagePartMapping
# 1===Phase 7. Rewrite code to conform with NexJ suggestions and Code Review 2===* Proposed Date: Week of <del>September 23</del> October 15
===Phase X8. Second Apply Changes from Code Review at NexJ2===*[[JSON_Integration_Adapter_Code_Review_2_Changes | Changes to make]]
# 1===Phase 9. Date TBACode Review 3===* Week of November 14
===Phase XI10. Project CompletionApply Changes from Code Review 3===*[[JSON_Integration_Adapter_Code_Review_3_Changes | Changes to make]]
== Project Repository ==
To be determined
== Resources ==
JSON RFC : http://www.ietf.org/rfc/rfc4627.txt<br />
Introduction to NexJ Studio Express : https://www.projects.openhealthtools.org/sf/go/doc1771?nav=1<br />
NexJ Developer's Guide<br />
NexJ Integration Fundamentals<br />Open Health Tools Integration Platform https://www.projects.openhealthtools.org/sf/projects/oht_aip/<br />