Wednesday, August 31, 2016

How to extend an asset's store view in WSO2 GREG 5.3.0

This blog post is an amendment to Niranjan's blog post [1] on the same topic. The blog post while correct needs to be updated for G-REG 5.3.0 as there have been several minor changes to the templates. A set of ready to use templates with updated changes can be found here [2]

I will first summarize the steps performed by Niranjan:

  1. The default implementation of the details page in the Store application does not display all of the attributes visible in the Publisher. One important factor behind the decision to reduced information is that some of the data such as endpoints are not in a format which is easily digestible by templates
  2. In order to rectify this Niranjan has introduced the jsonFormatter method which converts these hard to digest attributes into a format easily consumed by templates.
  3. To display the information he has introduced several new templates which mirror the information in the Publisher [3]
The release of G-REG 5.3.0 has necessitated several changes to the above steps:
  1. Alterations to the overview.hbs (Notice that . has been replaced with assets)
  2. Omitting the  asset-attributes.hbs
  3. Adding rows to the doclinks template
EDIT: A colleague (Chandana Napagoda) has pointed out an issue in the doclinks template.This has now been corrected in the git repo.

Reference
[1] http://niranjankaru.blogspot.com/2016/02/how-to-extend-assets-store-view-in-wso2.html
[2] https://github.com/splinter/greg-tutorial-1/tree/master

Sunday, August 14, 2016

Destructuring in ES2015

This is a first in a series of blog posts that will chronicle my exploration of the ECMA Script 2015 language update. The ES2015 is a specification which updates JavaScript with several additions to the language syntax. These improvements fall under the broad umbrella of ECMA Script 6 (ES6).

Why now?

I recently started working on a hobby project involving React and React Native which contain a lot of examples written in ES6.Hence, I thaught I would kill two birds with one stone and learn a bit about ES6 language features.

Important: I am in no ways a JS language expert and these blogs are a self learning tool (Caveat Emptor!)

What is Destructuring?

The process of extracting values from an object or an array [1]. It allows you to write concise code by:
  1. More cleanly handling functions which return multiple values
  2. More concisely access nested properties in objects

The syntax for destructuring in ES6 changes based on whether your working with an object or an array(Refer to Case#1 and Case#2 in the example below).

JS Sample on JSBIN 


When destructuring an Object JS will call toObject method on the left side of the expression.Hence, attempting to destructure undefined or null will cause an exception [1] [2].This means that primitives can be destructured too! (Refer to Case#5)

Loads of examples can be found here [4] and here [5].

I will be updating this post with more info once I get a bit of practice with this new syntax.

References


[1] http://exploringjs.com/es6/ch_destructuring.html
[2] http://www.ecma-international.org/ecma-262/6.0/#sec-toobject
[3] https://babeljs.io/docs/learn-es2015/
[4] https://ponyfoo.com/articles/es6-destructuring-in-depth
[5] https://gist.github.com/mikaelbr/9900818

Wednesday, August 10, 2016

Enabling Taxonomies for Content Type RXTs


The Problem
Those who have tried out the G-REG 5.3.0 will notice that content type RXTs strangely do not have a way for users to categorize assets using Taxonomies.The list of affected RXTs include:

  • Swagger
  • WSDL
  • WADL
  • Policy
  • Schema
Although, there is currently no way to enable this functionality at creation time (short of writing a custom create page), it is possible to access this feature using the edit page. However, we run into another hurdle as the edit page is not present for content type RXTs.





The Solution
It is thankfully not that hard to enable the update page.The Enterprise Store (ES) Extension framework auto generates create, update and delete pages for all the asset types deployed to the G-REG server.Hence, we just need to enable the update button and the ES will take care of rendering the page for us.This auto generated page


The bit of code which hides the edit page is shown below (swagger/asset.js) [1] :

The above snippet of code is present in each of the content type asset extensions:

  • <CARBON_HOME>/repository/deployment/server/jaggeryapps/publisher/extensions/assets/swagger/asset.js
  • <CARBON_HOME>/repository/deployment/server/jaggeryapps/publisher/extensions/assets/wsdl/asset.js
  • <CARBON_HOME>/repository/deployment/server/jaggeryapps/publisher/extensions/assets/wadl/asset.js
  • <CARBON_HOME>/repository/deployment/server/jaggeryapps/publisher/extensions/assets/policy/asset.js
  • <CARBON_HOME>/repository/deployment/server/jaggeryapps/publisher/extensions/assets/schema/asset.js
In order to enable to the update button comment out the following bit of code:



You should now be able presented with the update button and the update page:



The update page with the Taxonomy:




References
[1] https://github.com/wso2/product-greg/blob/v5.3.0-rc2/modules/es-extensions/publisher/asset/swagger/asset.js#L352