Saturday, March 16, 2013

Lifecycle transition using WSO2 Governance Registry - Governance API

[NOTE] This article is not recommended for a beginner of WSO2 Governance Registry. If you are a beginner you can refer WSO2 Governance Registry documentation and come back to this article.

In SOA Governance lifecycle management of a SOA artifact is playing a major role. In WSO2 Governance Registry 4.6.0 which is oncoming release there are several ways of manipulating Lifecycle of an artifact. 

  1. Using Governance Registry Management console
  2. Using set of administrative services 
    • LifeCycleManagementService
    • CustomLifecyclesChecklistAdminService
  3. Governance API
Here I am discussing about lifecycle manipulation using Governance API which is introduced for the release. For all the details related to Governance API you can visit WSO2 Governance Registry documentation here.

Here I am using the term artifact for any SOA Governance artifact defined in WSO2 Governance Registry. E.g. Service, WSDL, Policy, Schema, WADL, URI, API which is already there default and any other generic artifact defined by the users.

You can use Governance API to invoke the following operations,
  1. Associating a lifecycle to a artifact
  2. Checking associated lifecycle name of an artifact 
  3. Checking the current state of the lifecycle associated with the artifact
  4. Get the checklist item list
  5. Checking checklist item
  6. Checking whether a checklist item is checked
  7. Unchecking checklist item
  8. Get voting event list
  9. Voting for an event
  10. Checking whether the current user already voted for an event
  11. Unvoting for an event, current user already voted
  12. Get all action list
  13. Invoking action
Now lets look at what each operation do and how it can be done.

Associating a lifecycle to a artifact
This method is use to associate a lifecycle to a artifact. If you want to know about creating a lifecycle please refer this
artifact.attachLifecycle(lifecycleName);
Here you need to set the lifecycle name as the parameter. This will throw GovernanceException if the operation failed.

Checking associated lifecycle name of an artifact
This method is use to get the lifecycle name of the associated lifecycle of an artifact.
String lifecycleName = artifact.getLifecycleName();
Checking the current state of the lifecycle associated with the artifact
This method is use to get the current state of the artifact in its lifecycle.
String lifecycleState = artifact.getLifecycleState();
Get the checklist item list
This method is use to get all the check list item names of the current state of the associated artifact.
String[] checklistItems = artifact.getAllCheckListItemNames();

Checking checklist item
This method is use to check a check list item of the current state of the associated artifact.
artifact.checkLCItem(checkListItemIndex);
Here checkListItemIndex is the index of the checklist name in the checklist items list returned by  artifact.getLCCheckListItemNames() method.

Checking whether a checklist item is checked
This method is use to check whether a checklist item of the current state is clicked or not.
boolean lcItemChecked = artifact.isLCItemChecked(checkListItemIndex);
Here checkListItemIndex is the index of the checklist name in the checklist items list returned by  artifact.getAllCheckListItemNames() method.

Unchecking checklist item
This method is use to reverse a checked check list item of the current state of the associated artifact.
artifact.uncheckLCItem(checkListItemIndex);
Here checkListItemIndex is the index of the checklist name in the checklist items list returned by   artifact.getAllCheckListItemNames() method.

Get voting event list
This method is use to get the event list which need certain amount of votes before it invoke.
String[] votingEvents = artifact.getAllVotingItems();

Voting for an event
This method is use to vote for an event.
artifact.vote(eventIndex);
Here eventIndex is the index of the voting event in the voting events list returned by  artifact. artifact.getAllVotingItems() method.

Checking whether the current user already voted for an event
This method is use to check whether the current user is already voted to an event.
boolean currentUserVoted = artifact.isVoted(eventIndex);
Here eventIndex is the index of the voting event in the voting events list returned by  artifact. artifact.getAllVotingItems() method.

Unvoting for an event, current user already voted 
This method is use to reverse the vote for an event.
artifact.unvote(eventIndex);
Here eventIndex is the index of the voting event in the voting events list returned by  artifact. artifact.getVotingItems() method.

Get all action list
This methods is use to get all the actions for current lifecycle state.
artifact.getAllLifecycleActions();

Invoking action
These methods are use to invoke an action in current lifecycle state.
artifact.invokeAction(action);
artifact.invokeAction(action, parameterMap);
Here the second method allows to parse a parameter map which can be use in transition executors.

So, that's all with the lifecycle transitions using WSO2 Governance Registry Governance API.