IBM Support

Registry Services on the Glass – Part 2: Queries

Technical Blog Post


Abstract

Registry Services on the Glass – Part 2: Queries

Body

I think this to be one of the most interesting parts of the series started with the "Hitchhiker’s Guide to Interfacing with Registry Services" entries: the ability to query data registered from other applications and integrate it into front-end applications.

Once again, before you start, the entire example is available on GitHub.

Querying Service Providers…

One the first steps to query Registry Services is to determine the list of service providers. The collection of service providers essentially has a list of oslc:ServiceProvider elements under a parent rdfs:Container element, like in the example below, which shows the response from Registry Services with a collection of 3 Service Providers:

 

      @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.      @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.       @prefix oslc: <http://open-services.net/ns/core#>.      @prefix dcterms: <http://purl.org/dc/terms/>.      <http://oslc-registry/oslc/pr/collection> a rdfs:Container;  	rdfs:member <http://oslc-registry/oslc/providers/url1>,  		<http://oslc-registry/oslc/providers/url2>,  		<http://oslc-registry/oslc/providers/url3>.      <http://oslc-registry/oslc/providers/url1> dcterms:description "…"^^rdf:XMLLiteral;  	dcterms:title "…"^^rdf:XMLLiteral;  	a oslc:ServiceProvider.      <http://oslc-registry/oslc/providers/url2> dcterms:title "…"^^rdf:XMLLiteral;  	a oslc:ServiceProvider.      <http://oslc-registry/oslc/providers/url3> dcterms:description "…"^^rdf:XMLLiteral;  	a oslc:ServiceProvider.  
   

If you follow the RDFQuery wiki, you will find examples of queries where you can indicate the type of resource being searched and the attributes to be extracted from each record. As a point of caution here, several attributes in a ServiceProvider record are optional, which means you should use the “$rdf.optional” function instead of the more obvious “$rdf.where” function, like in the example below:

 

      $.ajax({          url : "/oslc/pr/collection?oslc.select=*",          success : function(data, textStatus, jqXHR) {              var                  spRdf = $.rdf().load(data, {});                  spRdf                      .prefix("dcterms", "http://purl.org/dc/terms/")                      .prefix("rr", "http://jazz.net/ns/ism/registry#")                      .where("?s a <http://open-services.net/ns/core#ServiceProvider>")                      .optional("?s dcterms:title ?title")                      .optional("?s dcterms:description ?description")                      .optional("?s rr:sourceRecord ?sourceRecord")                      .each(function () {                          var                              title = this.title === undefined ?                                   "No title" :                                   this.title.value,                              description = this.description === undefined ?                                   "No description" :                                   this.description.value,                              spUrl = this.s.value,                                  sourceRecordUrl = this.sourceRecord === undefined ?                                   "" :                               this.sourceRecord.value; 

 

When you run the sample, you should see a table of service providers, as depicted in Figure 1.
 

imageFigure 1- Table of service providers queried from Registry Services via Javascript

 

…then Registration Records for a Service Provider…

For each service provider queried in the snippet above, it is simple enough to query all registration records created by that service provider. Before the code example, here is a shortened example of a collection of registration records pulled from Registry Services:

        @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.      @prefix oslc: <http://open-services.net/ns/core#>.      @prefix rr: <http://jazz.net/ns/ism/registry#>.      @prefix dcterms: <http://purl.org/dc/terms/>.      @prefix crtv: <http://open-services.net/ns/crtv#>.      <http://host:port/oslc/rr/registration/collection> a rdfs:Container;          rdfs:member <http://host:port/oslc/registration/rr_url_1>,            <http://host:port/oslc/registration/rr_url_2>,            <http://host:port/oslc/registration/rr_url_3>.      <http://host:port/oslc/registration/rr_url_1> rr:sourceRecord <src_url_1>;          oslc:serviceProvider <http://host:port/oslc/providers/url1>;          dcterms:modified "2013-04-17T04:47:48.848Z";          a rr:RegistrationRecord,            crtv:ServerAccessPoint.      <http://host:port/oslc/registration/rr_url_2> rr:sourceRecord <src_url_2>;          oslc:serviceProvider <http://host:port/oslc/providers/url1>;          dcterms:modified "2013-04-17T04:53:18.899Z";          a rr:RegistrationRecord,            crtv:SoftwareModule.      <http://host:port/oslc/registration/rr_url_3> rr:sourceRecord <src_url_3>;          oslc:serviceProvider <http://host:port/oslc/providers/url1>;          dcterms:modified "2013-04-17T04:53:26.212Z";          a rr:RegistrationRecord,            crtv:ComputerSystem.

 

The following block of code builds the Registry Services URL for querying registration records, adding a oslc.where clause for the service provider. Following the URI specification, all URI components must be percent-encoded. Later, using the RDFQuery syntax for where clauses, we will be looking for all elements in that registration record collection that have a “http://jazz.net/ns/ism/registry#sourceRecord” property (that would be all of them) .

 

      var spFilter = encodeURIComponent("oslc:serviceProvider=<" + spUrl +">"),          whereClause = "oslc.where=" + spFilter;
         $.ajax({          url : "/oslc/rr/registration/collection?oslc.select=*&" + whereClause,          success : function(data, textStatus, jqXHR) {              regrRdf = $.rdf().load(data, {});                  var regrRdfMatches = regrRdf                      .prefix("rr", "http://jazz.net/ns/ism/registry#")                      .prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#")                      .where("?collection rdfs:member ?regRecord")                      .where("?regRecord rr:sourceRecord ?sourceRecord");
     

 
            regrRdfMatches.each(function () {
                var
                  rrUrl = this.s.value,
                  sourceRecordUrl = this.sourceRecord.value;


 

…then Resource Records for that Service Provider

 

As mentioned before, resource records are the main reason for sending application data to Registry Services, offering a consolidated view of the IT resources across all service providers. The example below shows the RDF model for a resource record collection retrieved from Registry Services. Notice how that resource record contains two sub-elements of http://jazz.net/ns/ism/registry#ProviderRecord type, which means Registry Services determined the two underlying registration records represent the same IT resource:

 

      @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.      @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.      @prefix crtv: <http://open-services.net/ns/crtv#>.      @prefix oslc: <http://open-services.net/ns/core#>.      @prefix dcterms: <http://purl.org/dc/terms/>.      @prefix rr: <http://jazz.net/ns/ism/registry#>.      <http://host:port/oslc/rr/collection> a rdfs:Container;          rdfs:member <rr_url_1>.      <rr_url_1> rr:providerRecord _:bnode_provider_record_1,            _:bnode_provider_record_2;          crtv:fileName "isclite.war";          crtv:name "isclite:isclite.war";          crtv:observationTime "2012-02-14T12:13:27.000Z";          dcterms:modified "2013-04-17T05:06:30.713Z";          a crtv:J2EEApplication,            crtv:SoftwareModule.      _:bnode_provider_record_1 rr:registrationRecord <reg_record_url_1>;          rr:sourceRecord <source_record_url_1>;          oslc:serviceProvider <sp_url_1>;          a rr:ProviderRecord.      _:bnode_provider_record_2 rr:registrationRecord <reg_record_url_2>;          rr:sourceRecord <source_record_url_2>;          oslc:serviceProvider <sp_url_2>;          a rr:ProviderRecord.

 

In order to query the resource records related to registration records for a given provider, one needs an OSLC where clause that references the oslc:serviceProvider URLs within the rr:ProviderRecord elements of the resource records, which is exemplified in the code snipped below:

 

    var
        spFilter = encodeURI("rr:providerRecord{oslc:serviceProvider=<" +
            spUrl + ">}"),
        whereClause = "oslc.where=" + spFilter;

    $.ajax({
        url : "/oslc/rr/collection?oslc.select=*&" + whereClause,
        success : function(data, textStatus, jqXHR) {
            rrRdf = $.rdf().load(data, {});
            var rrRdfMatches = rrRdf
               .prefix("dcterms", "http://purl.org/dc/terms/")
               .prefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
               .where("?collection rdfs:member ?rr")
               .where("?rr dcterms:modified ?time");

            ...

 

Once the entire sample is executed, clicking on the icon next to a service provider record will launch the queries for registration records associated with that service provider and for the resource records representing registration records for that service provider, rendering the responses in tables, as depicted in the Figure 2.


image

Figure 2 – Table of registration and resource records queried from Registry Services via Javascript

 

You can always query some more

I hope this entry was helpful to complement the concepts introduced in the "Hitchhiker’s Guide to interacting with Registry Services" articles and also to form a good basis for creating client applications, with examples that are at the same time general for dealing with RDF models in Javascript and specific to the semantics supported in Registry Services.

I can answer questions directly here or even be coaxed into extending this series towards variations on the theme of creating client applications for Registry Services. One of my areas of interest right now is to showcase a simple example of rendering data directly from Registry Services into DASH, the UI branch of Jazz for Service Management.

[{"Business Unit":{"code":"BU050","label":"BU NOT IDENTIFIED"},"Product":{"code":"SSHPN2","label":"Tivoli"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"","label":""}}]

UID

ibm11275634