Friday, December 5, 2014

Loading data into WSO2 Governance Registry using an Excel data sheet

Storing data as files is one of the basic features of a Registry/Repository. Some advanced repositories have the capability of loading data into itself by reading various types of files including text, CSV and Excel. This post describes about how we can use an Excel sheet to load data into WSO2 Governance Registry.

The WSO2 Governance Registry has many extension points that can be used to alter its behavior.It also has a set of clients that can be used to access data in the repository without the use of the Management Console. A sample that uses the Remote Registry API can be found using this link.

In this post I'm going to describe how we can use the Governance API of WSO2 Governance Registry to create a set of governance artifacts by reading the content of an Excel file.


The Data Set


I have used the Reception to Year 2 books list which is listed in here, as my data set in this post. The data set contains information about a set of books with the following set of information.
  • Author(s)
  • Title
  • Series
  • Publisher
  • Published Year
  • Annotation

Governance Client


I have written a Remote Governance Client using the Governance API of WSO2 Governance Registry to read the data from the Excel files and add them to the Governance Registry. More information about the Governance API can be found here.

The Governance Client is written to map the data in each row of the Excel sheets into 2 separate Governance artifacts.

Book Publishers


RXT configuration is as follows.


Books



RXT configuration is as follows.

The Governance Client does the following.

  1. Read any Excel file in the pre-defined resource location.
  2. Read through each file and get the column headers.
  3. Use the properties files to map the column names to the Governance Artifact.
  4. Create a Governance Artifact for each row and add the row data to the attributes.
  5. Add the Governance Artifact.
After executing the Governance client, the book and publisher artifacts are added to the Registry. Sample output from the Management Console is something similar to the following.



The content of a book is like this. We also create an association to the book publisher from a book.




The complete Governance client code can be found at the end of this post. Let me highlight the important code segments. Also one of the important facts to highlight is that this Governance Client code is not a generic code and only covers this scenario. I only did little effort to make some parts of the code generic but with little more effort, this client can be made fully generic.

This code segment is used to read the Excel cell values and store them against the governance artifact field. There is a check to see whether this is the books Governance artifact because we need to add a relationship to the book publishers Governance artifact.


The following code is used to create the Governance artifact and add it to the Registry.



The Complete Code


The final code segment I used can be found in my git repo using this link. It contains the Java source as well as the RXT configurations too.  In order to make it easy for the readers, I have added the Governance client Java code below as well.

If you want to try out the complete sample, then these are the steps that should be followed.

  1. Download and extract a wso2greg-4.6.0 pack.
  2. Start the server.
  3. Login to the Management Console and add the RXT files to the Registry. Read through the docs to if you are not familiar on how to do it.
  4. Change the following constants in the RegistryResourceImporter.
    • CARBON_HOME - should point to where the wso2greg-4.6.0 pack is unzipped.
    • SERVICE_URL - Should be changed if you are not running with the default ports.
    • USERNAME - Should be changed if you change the default admin user name.
    • PASSWORD - Should be changed if you change the default admin password.
  5. Execute the client and the check from the Management Console.


RegistryResourceImporter.java

No comments:

Post a Comment