Saturday, June 21, 2014




Project: Implement Registry Extension (RXT) 2.0 + Associated UI support - Updates and Notes




This is an update of  my project so far in GSOC 2014. There was a slight change in the project scope since the JSON support for RXT was temporarily removed and the scope was narrowed down to creating a Jaggery app which could support creating a new artifact type with an intuitive drag and drop UI.


I had a meeting with my mentor and few others in WSO2 last week and below are the facts which were discussed.


  • Finalized the requirement of a Jaggery app to create a new artifact type which could be installed to either Greg or ES via Management Console
  • RXT <content> should be generated using drag and drop components and user shall be able to change the fields easily by dragging components here and there.
  • The RXT XML should be generated in the client side using JS as well as some metadata should be kept with UI fields in order for ES to generate its ‘add metadata’ model.
  • This model should also facilitate creating a JSON out of the UI, at some point of time.
  • Once the XML is generated, a backend call will be made to Registry to add the RXT via Jaggery.


Current Progress


In the Process of finding a suitable plugin for drag and drop functionality, I looked upon Gridster.js [1] was used in UES and is very flexible in generating UIs. But it seems to be bit difficult to use it in this purpose, since it needed a lot of fine tuning to be able to cater this requirement. Then I found Bootsnipp Form Builder [2] which seems to be bit similar to the one which is required under MIT license and built on bootstrap. So decided to go on with it.


I was able to create a simple UI, create a Jaggery app and host it in Greg/ES and test the functionality. Below is a sample UI which has only the basic functionality to create a RXT.


                                           japp.png



I was told several issues the existing RXT, XML model has and the difficulties in rendering the UI (in ES) only with the information it provides and necessity of keeping other metadata along with the xml model. So I’ working on a way to find out the best possible way to bridge the gap between the RXT xml and the UI it is generating in ES side.

Next Steps


  • Write a JS script to generate the RXT xml from the form data/HTML
  • Keep other metadata which are not going in to the xml in a JSON model (tentative)
  • Call backend Registry client/stub and send the RXT to registry.
  • Try to load RXT xml data to the UI back when editing a RXT artifact.





Friday, June 13, 2014


JSON Parsing and Validation

Step I - JSON Parsing
To parse JSON data we can use  GSON library.
When given the json file as a String to parse method above, it will return the parsed JsonObject as tree.

public static JsonObject parse(String jsonString) {
JsonParser jsonParser = new JsonParser();
JsonElement rxtJsonElement = jsonParser.parse(jsonString);
JsonObject rxtJsonArtifactTypeObject = rxtJsonElement.getAsJsonObject().getAsJsonObject("artifactType");
return rxtJsonArtifactTypeObject;
}

Step II - JSON data format Validation
Develop Shema
JSON Schema is a tool for validating the structure of JSON data. When we consider data format we need to know what does data elements mean and what the valid inputs for these elements are. To ensure we have obtained the required data we write a schema.

I.Manually write Schema for JSON:

There are certain keywords that are used to develop a Schema for any sort of json data.
Most frequently used key words are:
Ø  type
Ø  properties
Ø  items
Ø  required
Ø  maxItems

JSON is built on two structures:
Ø  A collection of name/value pairs commonly realized as “objects”.
Ø  An ordered list of values commonly realized as “ arrays”.
This defines the type keyword in a Schema.
properties are defined to validate the attributes in an object.
Within an array the list of items are defined by items keyword.
Whether a particular object array or property and item is a must for it to validate is defined by required keyword. 
MaxItems defines the maximum number of elements in array type of object type.
Similarly you can find how any of this keyword defines the validity of the JSON data against the Schema we develop.

Example:
JSON data to be validated:
{
"address":{
"streetAddress": "21 2nd Street",
"city":"New York"
},
"phoneNumber":
[
{
"type":"home",
"number":"212 555-1234"
}
]
}

Schema developed:

{
"type":"object",
"required":false,
"properties":{
"address": {
"type":"object",
"required":false,
"properties":{
"city": {
"type":"string",
"required":false
},
"streetAddress": {
"type":"string",
"required":false
}
}
},
"phoneNumber": {
"type":"array",
"required":false,
"items":[
{
"type":"object",
"required":false,
"properties":{
"number": {
"type":"string",
"required":false
},
"type": {
"type":"string",
"required":false
}
}
}
}
}
}
  


II. Directly generates Schema for specific parsed JSON data format:

Step III - Validate functionality.
We can directly validate Schema functionality online.

Note:
To validate JSON content - http://jsonschemalint.com/