Fork me on GitHub Fork me on GitHub

MetadataStore


<%
var dataStore = new MetadataStore("admin", "admin");
var resource = dataStore.newResource();
resource.content = "<a>Hello Jaggery</a>";
resource.addProperty("url", "http://wso2.com");
resource.addProperty("company", "WSO2 Inc.");
dataStore.put("wso2products.xml", resource);

//now we read the resource again
var res = dataStore.get("wso2products.xml");

//html to show the result
var resource = {};
resource.content = res.content.toXMLString();
resource.props = {};
resource.props.url = res.getProperty("url");
resource.props.company = res.getProperty("company");

print(resource);
%>

Overview

This enables data manipulation through registry (metadata store) resources.


Operations

Operation Returns Description
MetadataStore("username", "password")MetadataStore
var dataStore = new MetadataStore("username", "password");
Returns a new metadata store
resourceExists(String path);Boolean
var dataStore = new MetadataStore("username", "password");
boolean existance = dataStore.resourceExists("middleware/wso2/products");

This method returns true or false depending on the existence of either a Resource or a Collection in the specified path.

Above code returns true if a resource exists in the path /_system/governance/middleware/wso2/products.

get(String path, [Number start, Number pageSize]);ObjectThis method returns the resource in the specified path. If the resource in the path is a collection, then a Collection object is returned. Else, it returns a Resource object. If it is a collection, then you can specfify optional start and pageSize parameters to filter your results.

remove(String path);NoneThis method removes the resource in the specified path from the Metadata store.
put(String suggestedPath, Resource|Collection resource);StringThis method adds either a Resource or a Collection into the specified path in the Metadata store.
createLink(String path, String target);StringCreates a link to a existing resource.
newResource();ResourceWhere you insert a new Resource into the Metadata store, then you should use this method to create the initial Resource object.

newCollection();CollectionWhere you insert a new Resource into the Metadata store, then you should use this method to create the initial Resource object.