Tuesday, August 30, 2016

Enable debug logs for a jaggery app

Goto  [Product-Home]/repository/deployment/server/jaggeryapps/<app-folder>
    ex: to enable debug logs for WSO2 GREG  Publisher app,             [GREG-HOME]/repository/deployment/server/jaggeryapps/publisher

Open the jaggery.conf file


Modify the "logLevel": "info" entry to "logLevel": "debug"


Restart the server and now you can see debug logs in the console.


[1] http://jaggeryjs.org/documentation.jag?api=jagconf
Read More

Monday, August 15, 2016

WSO2 G-Reg-5.30 Associations Publisher REST API

WSO2 Governance Registry product provides a set of resources under its Publisher Rest API to perform CRUD operations over Associations of an asset instance.

Default it provides below API resources under /{context}/apis/association/

GET /{type}/{association}/{id}

    Returns list of possible associatable target assets list.
    {type} - source asset type
    {association} - association name
    {id} - source asset id

Parameters:
    q="name":"*"
Returns associatable assets subject to default paging

    q="name":"aa"
Returns associatable assets subject to search over name attribute for the provided input.

Ex: https://localhost:9443/publisher/apis/association/soapservices/reference/404cada0-5e8d-4e39-8c21-fdc96c1f0ccc?q="name"%3A"te"

Response:
{
  "results":[
     {
        "uuid":"aaeab854-547d-4fcd-ac1f-f906e623877f",
        "text":"tets",
        "version":"1.2.3",
        "type":"application/vnd.wso2-soap-service+xml",
        "shortName":"soapservice"
     },
     {
        "uuid":"e47d7197-14a1-45a0-b43b-d46468ad58a0",
        "text":"API_Test",
        "version":"1.2.3",
        "type":"application/vnd.wso2-restservice+xml",
        "shortName":"restservice"
     },
     {
        "uuid":"e98b151b-6711-4963-84ef-6607a219817d",
        "text":"testRest",
        "version":"1.2.3",
        "type":"application/vnd.wso2-restservice+xml",
        "shortName":"restservice"
     }
  ]
}


GET  /{type}


    Returns association types defined in governance.xml for a given asset type.

Ex:https://localhost:9443/publisher/apis/association/soapservices

Response:
    [
  {
     "key":"ownedBy",
     "value":"fw-user"
  },
  {
     "key":"security",
     "value":"fw-security"
  },
  {
     "key":"depends",
     "value":"fw-store"
  },
  {
     "key":"usedBy",
     "value":"fw-globe"
  }
]

POST /*

    Add an association to a given asset instance
Ex: https://localhost:9443/publisher/apis/association
Request Payload
    {
  "sourceUUID":"b26d640b-9239-42ec-aeda-d4fbb79d665a",
  "destUUID":"e98b151b-6711-4963-84ef-6607a219817d",
  "sourceType":"soapservice",
  "destType":"restservice",
  "associationType":"depends"
}

DELETE /remove

    Remove added association from an asset instance.
Ex: https://localhost:9443/publisher/apis/association/remove
Request Payload
        {
  "sourceUUID":"b26d640b-9239-42ec-aeda-d4fbb79d665a",
  "destUUID":"e98b151b-6711-4963-84ef-6607a219817d",
  "sourceType":"soapservice",
  "destType":"restservice",
  "associationType":"depends"
}

Read More

Change the default icon of an asset type in WSO2 G-Reg 5.3.0

WSO2 G-Reg 5.3.0 is the latest release version of Governance Registry product.

In a vanilla pack all the thumbnails are rendered to be default to an unique color and the first letter of the asset name.

But if someone wants to customize this thumbnail here are the steps.

In this post I will explain how to change the thumbnail of a particular asset type, namely I will take 'reserservice' type as an example.

Let's say we want to change all the occurrences of thumbnails of 'restservice' type to a custom image icon shown below.
api-thumbnail.png



Let's start with copying desired thumbnail icon to following location where <asset-type> refers to the interested type.

[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/<asset-type>/themes/default/imgs/

Ex: I have added api_thumbnail.png into
[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/imgs/

Consider Details page of an asset. By default it looks like below image.


default-thumbnain-in-details.png

To change the thumbnail of this page to the custom image refer the newly added image from

[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/partials/view-asset-top-common-container.hbs file. 
If you already don't have view-asset-top-common-container.hbs in location take a copy of 
[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/app/greg-publisher-defaults/themes/default/partials/view-asset-top-common-container.hbs
into
[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/partials/view-asset-top-common-container.hbs 

It is default to below
<div class="ast-name-icon">{{this.nameToChar}}</div>
Change it to
<div class="ast-name-icon">
     <img alt="thumbnail" class="square-element img-thumbnail" src='{{url ""}}/extensions/assets/restservice/themes/default/imgs/api_thumbnail.png'>
</div>

And change the style configurations to align the custom image nicely. I have removed  style="background: {{this.uniqueColor}}" from parent div as well.

Now
[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/partials/view-asset-top-common-container.hbs looks like below.


{{#with assets}}
    <div class="well asset-well">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="pull-left ast-img setbgcolor" title="{{name}}">
                        <span class="ast-type-icon" title="{{this.singularLabel}}">
                            <i class="{{icon}} fw-lg"></i>
                        </span>
                        <!--div class="ast-name-icon">{{this.nameToChar}}</div-->
                        <div class="ast-name-icon">
                            <img alt="thumbnail" class="square-element img-thumbnail" src='{{url ""}}/extensions/assets/restservice/themes/default/imgs/api_thumbnail.png'>
                        </div>
                    </div>
                    <div class="asset-details-right">
                        <h4>{{name}}</h4>
                        {{#if version}}
                            <p>Version : {{version}}</p>
                        {{/if}}
                        {{#if lifecycleState}}
                        <p>{{lifecycle}} : {{lifecycleState}}</p>
                        {{/if}}
                        <div class="well-description">{{tables.0.fields.createdtime.value}}</div>
                    </div>
                 </div>
            </div>
        </div>
    </div>

{{/with}}

When you refresh the details page, the thumbnail should be changes as in below image. make sure to refresh the browser cache if the change is not appearing.


changed-details.png




Now consider overriding the default thumbnail in ‘Edit’ page which is default rendered as below.


default-thumbnain-in-edit.png

Same as in the previous step, now edit the
[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/partials/update_asset.hbs

After changing it should look like below.

{{#with assets}}

    <div class="well asset-well">

        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="pull-left ast-img setbgcolor" title="{{name}}">
                        <span class="ast-type-icon" title="{{this.singularLabel}}">
                            <i class="fw fw-rest-service fw-lg"></i>
                        </span>
                        <!--div class="ast-name-icon">{{this.nameToChar}}</div-->
                        <div class="ast-name-icon">
                            <img alt="thumbnail" class="square-element img-thumbnail" src='{{url ""}}/extensions/assets/restservice/themes/default/imgs/api_thumbnail.png'>
                        </div>
                    </div>
                    <div class="asset-details-right">
                        <h4>{{name}}</h4>
                        {{#if version}}
                            <p>Version : {{version}}</p>
                        {{/if}}
                        {{#if lifecycleState}}
                            <p>{{lifecycle}} : {{lifecycleState}}</p>
                        {{/if}}
                        <div class="well-description">{{tables.0.fields.createdtime.value}}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{{/with}}


{{> update_form .}}

When you refresh the browser Edit page of the asset will get rendered with below change.

changed-update.png




To override the default thumbnail in asset Listing page, you need to edit 

[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/partials/list_assets_table_body.hbs



default thumbnail.png
To override the default thumbnail in asset listing page.


[HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/restservice/themes/default/partials/list_assets_table_body.hbs

After changing it should look like below.
{{#each .}}


    <div class="ctrl-wr-asset">
        <div class="itm-ast">
            <a id="{{this.id}}" class="ast-img" href='{{url ""}}/assets/{{type}}/details/{{this.id}}' title="{{this.attributes.overview_name}}">
                <div class="ast-img setbgcolor" >
                    <span class="ast-type-icon" title="{{this.singularLabel}}">
                        <i class="fw fw-rest-service fw-lg"></i>
                    </span>
                    <!--div class="ast-name-icon">{{this.nameToChar}}</div-->
                    <div class="ast-name-icon">
                        <img alt="thumbnail" class="square-element img-thumbnail" src='{{url ""}}/extensions/assets/restservice/themes/default/imgs/api_thumbnail.png'>
                    </div>
                </div>
            </a>
            <div class="ast-desc">
                <a href='{{url ""}}/assets/{{type}}/details/{{this.id}}'>
                    <h3 class="ast-name" title="{{this.attributes.overview_name}}">{{this.attributes.overview_name}}</h3>
                </a>
                {{#if this.attributes.overview_version}}
                    <span class="ast-ver">V{{this.attributes.overview_version}} </span>
                {{/if}}
                <span class="ast-published">{{this.attributes.overview_namespace}}</span>
                {{#if this.currentLCStateDurationColour}}
                    <span class="lifecycle-state">
                    <small>
                        <div class="colorbar" Title="Current Lifecycle State Duration: {{this.currentLCStateDuration}}"
                             style="background-color: {{this.currentLCStateDurationColour}}"></div>
                        <i class="icon-circle lc-state-{{this.currentLCStateDuration}}"></i> {{this.lifecycleState}}
                    </small></span>
                {{else}}
                    {{#if this.lifecycleState}}
                        <span class="lifecycle-state"><small><i
                                class="icon-circle lc-state-{{this.lifecycleState}}"></i> {{this.lifecycleState}}
                        </small></span>
                    {{/if}}
                {{/if}}
            </div>
            <br class="c-both" />
        </div><br class="c-both" />
    </div>
{{/each}}

Refreshing restservices 'Listing' page, restservice thumbnails should be changes as below.


To see the same behavior in Store side for restservices,

First copy the desired image to 
[HOME]/repository/deployment/server/jaggeryapps/store/extensions/assets/restservice/themes/store/imgs/api_thumbnail.png

Then edit 
[HOME]/repository/deployment/server/jaggeryapps/store/extensions/assets/restservice/themes/store/partials/default-thumbnail.hbs
to refer to the custom image. If
[HOME]/repository/deployment/server/jaggeryapps/store/extensions/assets/restservice/themes/store/partials/default-thumbnail.hbs 
is not available default in this location, take a copy from 
[HOME]/repository/deployment/server/jaggeryapps/store/extensions/app/greg-store-defaults/themes/store/partials/default-thumbnail.hbs

After edit the file it should look like below.

<div class="ast-img setbgcolor" data-toggle="tooltip" title="{{name}}">
    <span class="ast-type-icon"  title="{{this.singularLabel}}">
      <i class="fw fw-rest-service fw-lg"></i>
      </span>
    <!--div class="ast-name-icon">{{this.nameToChar}}</div-->
    <div class="ast-name-icon">
        <img alt="thumbnail" class="square-element img-thumbnail" src='{{url ""}}/extensions/assets/restservice/themes/store/imgs/api_thumbnail.png'>
    </div>

</div>

Read More

Wednesday, August 10, 2016

Selectively Attach a Lifecycle for an asset instance based on custom logic in WSO2GREG 5.1.0 version onwards

In some Governance use cases where we want to selectively attach a lifecycle for an artifact based on some custom logic.
Currently we attach a lifecycle for an artifact using below methods.
  1. Configuring in RXT.
  2. Configuring in asset.js using the properties(ex: meta.lifecycle.name) explained in here
    1. This is inherited from ES
  3. Manually attach lifecycles from Management console

As of now we only have option 3. to cater this requirement of selectively attaching a lifecycle.
But we need to automate that.
We can do this in two ways.
  1. Incorporate a custom handler to intercept artifact put method.
  2. Override asset.js ‘attachLifecycle’ method via publisher's asset extension.

In this blogpost I will explain how to achive this using above method 2.Override asset.js ‘attachLifecycle’ method via publisher's asset extension

As a sample let’s consider ‘soapservice’ artifact type in Governance Center.

  1. Remove Lifecycle reference from the soapservice rxt.
i.e: remove <lifecycle>ServiceLifeCycle</lifecycle> from soapservice.rxt
  1. Override ‘attachLifecycle’ method in [GREG_HOME]/repository/deployment/server/jaggeryapps/publisher/extensions/assets/soapservice/asset.js asset.manager section.
Ex: add new method ‘attachLifecycle’ there to override the default behaviour implemented in here




asset.manager = function(ctx) {
. . . . . . . . .
. . . . . . . . .
      ,
      postCreate:function(){
         
      },
      attachLifecycle:function(asset, lifecycle){
          var lifecycle = “”;
          /* write your custom logic to populate lifecycle
          ** asset object that comes into this method has all the content of the artifact instance
          ** there for you can implement a custom logic based on values of artifact metadata as well */          
          if (lifecycle == '') {
               return success;
           }
          try {
              this.am.attachLifecycle(lifecycle, asset);
               success = true;
           } catch (e) {
               //handle exception
           }
              return success;
      }
  }
};
. . . . .
. . . . .
Read More
Designed ByBlogger Templates