use of org.wso2.carbon.registry.api.RegistryException in project jaggery by wso2.
the class RegistryHostObject method jsFunction_newCollection.
public static Scriptable jsFunction_newCollection(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
RegistryHostObject rho = (RegistryHostObject) thisObj;
if (arguments.length == 0) {
if (rho.registry != null) {
try {
Collection collection = rho.registry.newCollection();
CollectionHostObject cho = (CollectionHostObject) cx.newObject(rho, "Collection", new Object[] { collection });
return cho;
} catch (RegistryException e) {
throw new ScriptException("Error occurred while creating a new Collection", e);
}
} else {
throw new ScriptException("Registry has not initialized");
}
} else {
throw new ScriptException("newCollection() Method doesn't accept arguments");
}
}
use of org.wso2.carbon.registry.api.RegistryException in project jaggery by wso2.
the class RegistryHostObject method jsFunction_getRating.
public static Number jsFunction_getRating(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "getRating";
int argsCount = args.length;
if (argsCount != 2) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
}
RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
}
if (!(args[1] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "2", "string", args[1], false);
}
try {
return registryHostObject.registry.getRating((String) args[0], (String) args[1]);
} catch (RegistryException e) {
throw new ScriptException(e);
}
}
use of org.wso2.carbon.registry.api.RegistryException in project jaggery by wso2.
the class RegistryHostObject method jsFunction_addComment.
public static void jsFunction_addComment(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "addComment";
int argsCount = args.length;
if (argsCount != 2) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
}
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
}
if (!(args[1] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "2", "string", args[1], false);
}
RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
try {
registryHostObject.registry.addComment((String) args[0], new org.wso2.carbon.registry.core.Comment((String) args[1]));
} catch (RegistryException e) {
throw new ScriptException(e);
}
}
use of org.wso2.carbon.registry.api.RegistryException in project jaggery by wso2.
the class RegistryHostObject method search.
private ResourceData[] search(UserRegistry registry, String searchQuery) throws IndexerException, RegistryException {
SolrClient client = SolrClient.getInstance();
SolrDocumentList results = client.query(searchQuery, registry.getTenantId());
if (log.isDebugEnabled())
log.debug("result received " + results);
List<ResourceData> filteredResults = new ArrayList<ResourceData>();
for (int i = 0; i < results.getNumFound(); i++) {
SolrDocument solrDocument = results.get(i);
String path = getPathFromId((String) solrDocument.getFirstValue("id"));
//if (AuthorizationUtils.authorize(path, ActionConstants.GET)){
if ((registry.resourceExists(path)) && (isAuthorized(registry, path, ActionConstants.GET))) {
filteredResults.add(loadResourceByPath(registry, path));
}
}
if (log.isDebugEnabled()) {
log.debug("filtered results " + filteredResults + " for user " + registry.getUserName());
}
return filteredResults.toArray(new ResourceData[0]);
}
use of org.wso2.carbon.registry.api.RegistryException in project jaggery by wso2.
the class RegistryHostObject method loadResourceByPath.
private ResourceData loadResourceByPath(UserRegistry registry, String path) throws RegistryException {
ResourceData resourceData = new ResourceData();
resourceData.setResourcePath(path);
if (path != null) {
if (RegistryConstants.ROOT_PATH.equals(path)) {
resourceData.setName("root");
} else {
String[] parts = path.split(RegistryConstants.PATH_SEPARATOR);
resourceData.setName(parts[parts.length - 1]);
}
}
Resource child = registry.get(path);
resourceData.setResourceType(child instanceof Collection ? "collection" : "resource");
resourceData.setAuthorUserName(child.getAuthorUserName());
resourceData.setDescription(child.getDescription());
resourceData.setAverageRating(registry.getAverageRating(child.getPath()));
Calendar createdDateTime = Calendar.getInstance();
createdDateTime.setTime(child.getCreatedTime());
resourceData.setCreatedOn(createdDateTime);
CommonUtil.populateAverageStars(resourceData);
child.discard();
return resourceData;
}
Aggregations