<% 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); %>
Registry contains all functions related to Carbon registry which can be done in Jaggery.
Operations | Returns | Description |
---|---|---|
Registry(server, options) | None | Following parameters should be passed to the constructor:
var carbon = require('carbon');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:
var path ='/_system/config/wso2/sample';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:
var path ='/_system/config/wso2/sample';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:
var path ='/_system/config/wso2/sample'; |
move(src, dest) | None | Moving a resource: Move a resource to a new location in registry. parameters:
var src ='/_system/config/wso2/sample'; |
copy(src, dest) | None | Copping a resource: Copy a resource to a new location in registry. parameters:
var src ='/_system/config/wso2/sample'; |
rename(path, name) | None | Renaming a resource: Rename a resource to a different name. parameters:
var path ='/_system/config/wso2/sample'; |
remove(path) | None | Removing a resource: Remove a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
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:
var path ='/_system/config/wso2/sample'; |
tag(path, tags) | None | Adding tags: Add a tag for a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
tags(path) | array | Retrieving tags: Retrieve all tags for a resource as a string array. parameters:
var path ='/_system/config/wso2/sample'; |
untag(path, tags) | None | Removing tags: Remove tags from a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
rate(path, rate) | None | Rating Resources: Rate a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
addProperty(path, propName, value) | None | Adding a property to resource: Add properties to a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
properties(path) | object | Retrieving Properties: Return properties as a object. ex: {'prop2' : ['val2'], 'prop1' : ['val1']} parameters:
var path ='/_system/config/wso2/sample'; |
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:
var path ='/_system/config/wso2/sample'; |
unrate(path) | None | Unrating a resource: Unrating a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
comment(path, comment) | None | Adding a comment: Comment a resource in registry. parameters:
var path ='/_system/config/wso2/sample'; |
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:
var path ='/_system/config/wso2/sample'; |
commentCount(path) | number | Getting comment count: Get the number of comment for a resource parameters:
var path ='/_system/config/wso2/sample'; |
uncomment(commentPath) | None | Unrating a resource: Remove a comment for a resource in registry parameters:
var commentPath =/_system/config/wso2/sample;comments:2'; |
version(path) | None | Versioning a resource: Versioning a resource in registry parameters:
var path ='/_system/config/wso2/sample'; |
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:
var path ='/_system/config/wso2/sample'; |
restore(versionPath) | None | Restoring a resource: Restore a resource to a previous version. parameters:
var versionPath ='/_system/config/wso2/sample;version:5'; |
unversion(path, versionId) | None | Removing a version of resource: Remove a previous version of a resource from the version history.
var path ='/_system/config/wso2/sample'; |
link(linkPath, target) | None | Linking a resource: Link a resource to another resource path.
var linkPath ='/_system/local/wso2/sample'; |
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:
var qpath ='/_system/config/repository/components/org.wso2.carbon.registry/queries/allTags'; |