Fork me on GitHub Fork me on GitHub

Registry


<%
var carbon = require('carbon');
var url = 'https://10.100.0.49:9443/admin/services/';
var server = new carbon.server.Server(url);
var options = {username: 'admin',  domain: 'carbon.super' , tenantId: -1234};  
var registry = new carbon.registry.Registry(server, options);


//Add a resource to the registry
var path ='/_system/config/wso2/sample'; 
var resource ={ 
	content: 'This is a sample text.', 
	mediaType: 'text/plain', 
	description: 'This is a sample description', 
	uuid: '0123', 
		properties:{prop1: 'val1', prop2: 'val2'}
	}; 
registry.put(path,resource);


//retriving a resource from registry
var retrivedresource = registry.get(path);
print('Retrived Resource : ');
print(retrivedresource);

//checking the existency
var bol = registry.exists(path);
print('<br>');
print("check the existence in the location /_system/config/wso2/sample :");
print(bol);

//add tags
var tags =['tag1','tag2'];
registry.tag(path,tags);

//retrive tags
var retrivedtags = registry.tags(path);
print('<br>');
print(retrivedtags);

//rating a resource
var rate = 3;
registry.rate(path,rate);

//getting a ratings of a resource
var user ='admin';
var rating = registry.rating(path,user);
print('<br>');
print("Rating for the resource :");
print(rating);

%>

Overview

Registry contains all functions related to Carbon registry which can be done in Jaggery.


Operations

Operations Returns Description
Registry(server, options)NoneFollowing parameters should be passed to the constructor:
  • server - carbon server instance which we connect to the registry. This parameter is not mandatory. If we don’t provide the server, it will connect to the local server where the jaggery code will be executed.
  • options - This is the json object which contain all other options to create the registry object
    • var carbon = require('carbon'); 
      var url = 'https://10.100.0.49:9443/admin/services/';
      var server = new carbon.server.Server(url);
      var options = {username: 'admin', domain: 'carbon.super' , tenantId: -1234};
      var registry = new carbon.registry.Registry(server, options);
      username - user which will be used in registry operations. Rather than sending user name we can send “system: true” in the options. then it will use the default registry system user. If we pass nothing it will use the default anonymous registry user.
      domain - tenant domain for the user. This will be used to get the tenant id.
      tenantId - tenant id of registry user
put(path, resource)None Adding a resource
parameters:
  • path - Path for the resource in registry. (resource path)
  • resource - this is the json object which contains all data related to the resource which will be created.
    • var path ='/_system/config/wso2/sample'; 
      var resource ={ content: 'This is a sample text.', mediaType: 'text/plain', description: 'This is a sample description', uuid: '0123', properties:{prop1: 'val1', prop2: 'val2'} };
      registry.put(path,resource);
      content - content of the resource.
      mediaType - type of the resource’s content
      description - a description about the resource.
      uuid -
      properties - properties of the resource. This is a json object which contains property name and its value.
put(path, collection)None Adding a collection
Collection is also a resource which contains set of resources. Can use put method as below to add a collection.
parameters:
  • path - Path for the resource in registry. (resource path)
  • collection - this is the json object which contains all data related to the collction which will be created.
    • var path ='/_system/config/wso2/sample'; 
      var resource ={ collection: true, description: 'This is a sample description', uuid: '0123', properties:{prop1: 'val1', prop2: 'val2'} };
      registry.put(path,collection);
      collection - boolean value to identify the resource as a collection.
      description - a description about the resource.
      uuid -
      properties - properties of the resource. This is a json object which contains property name and its value.
get(path)object Retrieving a resource
Retrieve a resource to jaggery as a json object which contains all data about the resource.
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample'; 
      var
      resource = registry.get(path)
move(src, dest)None Moving a resource:
Move a resource to a new location in registry.
parameters:
  • src - Current location(path) of the resource.
  • dest - Destination location(path) of the resource.
    • var src ='/_system/config/wso2/sample'; 
      var dest ='/_system/config/wso2/dest/sample';
      registry.move(src,dest);
copy(src, dest)None Copping a resource:
Copy a resource to a new location in registry.
parameters:
  • src - Current location(path) of the resource.
  • dest - Destination location(path) of the resource.
    • var src ='/_system/config/wso2/sample'; 
      var dest ='/_system/config/wso2/dest/sample';
      registry.copy(src,dest);
rename(path, name)None Renaming a resource:
Rename a resource to a different name.
parameters:
  • path - Path for the resource in registry. (resource path)
  • name - new name for the resource.
    • var path ='/_system/config/wso2/sample'; 
      var name = 'newsample';
      registry.rename(path,name);
remove(path)None Removing a resource:
Remove a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample';
      registry.remove(path);
exists(path)boolean Checking for the Existence of a Resource:
Check for the existence of a resource and this method returns a boolean value. If resource exists it will return “true”.
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample'; 
      var
      bol = registry.exists(path);
tag(path, tags)None Adding tags:
Add a tag for a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
  • tags - String array which contains tags.
    • var path ='/_system/config/wso2/sample';
      var tags =['tag1','tag2'];
      registry.tag(path,tags);
tags(path)array Retrieving tags:
Retrieve all tags for a resource as a string array.
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample';
      var tags = registry.tags(path)
untag(path, tags)None Removing tags:
Remove tags from a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
  • tags - String array which contains tags.
    • var path ='/_system/config/wso2/sample';
      var tags =['tag1','tag2'];
      registry.untag(path,tags);
rate(path, rate)None Rating Resources:
Rate a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
  • rate - Rate for the resource.
    • var path ='/_system/config/wso2/sample';
      var rate = 3;
      registry.rate(path,rate);
addProperty(path, propName, value)None Adding a property to resource:
Add properties to a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
  • propName - name of the property
  • value - value for the property
    • var path ='/_system/config/wso2/sample';
      var propName = 'prop';
      var value = 'val';
      registry.addProperty(path,propName,value);
properties(path)object Retrieving Properties:
Return properties as a object. ex: {'prop2' : ['val2'], 'prop1' : ['val1']}
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample';
      var tags = registry.tags(path)
rating(path, user)object Getting rating of a resource:
Get rating of a resource as a json which contains average rating and user rating.
parameters:
  • path - Path for the resource in registry. (resource path)
  • user - user name of rate to get
    • var path ='/_system/config/wso2/sample';
      var user ='admin';
      var rating = registry.rating(path,user)
unrate(path)None Unrating a resource:
Unrating a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample';
      registry.unrate(path);
comment(path, comment)None Adding a comment:
Comment a resource in registry.
parameters:
  • path - Path for the resource in registry. (resource path)
  • comment - String type comment
    • var path ='/_system/config/wso2/sample'; 
      var comment = 'this is a sample comment';
      registry.comment(path,comment);
comments(path)array Checking for the Existence of a Resource:
Returns a comment object array.
ex: [{'content' : 'this is a sample comment 2', 'created' : {'author' : 'admin', 'time' : 1380091607480}, 'path' : '/_system/config/wso2/sample;comments:2'},{'content' : 'this is a sample comment', 'created' : {author : admin, time : 1380091557115}, path : '/_system/config/wso2/sample;comments:1'}]
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample'; 
      var
      comments = registry.comments(path);
commentCount(path)number Getting comment count:
Get the number of comment for a resource
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample';
      var tags = registry.commentCount(path)
uncomment(commentPath)None Unrating a resource:
Remove a comment for a resource in registry
parameters:
  • commentPath - Path for the resource in registry with comment id.
    • var commentPath =/_system/config/wso2/sample;comments:2';
      registry.uncomment(commentPath);
version(path)None Versioning a resource:
Versioning a resource in registry
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample';
      registry.version(path);
versions(path)array Getting versions of a resource:
Returns an array of resource paths with version.
ex: ['/_system/config/wso2/sample;version:59', '/_system/config/wso2/sample;version:58']
parameters:
  • path - Path for the resource in registry. (resource path)
    • var path ='/_system/config/wso2/sample'; 
      var
      versions = registry.versions(path);
restore(versionPath)None Restoring a resource:
Restore a resource to a previous version.
parameters:
  • versionPath - Path for the resource in registry with version
    • var versionPath ='/_system/config/wso2/sample;version:5';
      registry.version(versionPath);
unversion(path, versionId)None Removing a version of resource:
Remove a previous version of a resource from the version history.
  • path - Path for the resource in registry. (resource path)
  • versionId - Id of the version to be removed
    • var path ='/_system/config/wso2/sample';
      var versionId = 4;
      registry.rate(path,versionId);
link(linkPath, target)None Linking a resource:
Link a resource to another resource path.
  • linkPath - resource path where the link will be created.
  • target - resource path where the resource is exists.
    • var linkPath  ='/_system/local/wso2/sample';
      var target='/_system/config/wso2/sample';
      registry.link(linkPath,target);
versions(path)array Executing a query:
can execute a query stored in registry. The query should be stored as “mediaType: 'application/vnd.sql.query' ”.
parameters:
  • qpath - resource path to the query
    • var qpath ='/_system/config/repository/components/org.wso2.carbon.registry/queries/allTags'; 
      var
      qresults = registry.query(qpath);