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;
      }
  }
};
. . . . .
. . . . .


No comments:

Post a Comment

Designed ByBlogger Templates