Search in sources :

Example 6 with RegistryException

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");
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) Collection(org.wso2.carbon.registry.core.Collection) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 7 with RegistryException

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);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 8 with RegistryException

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);
    }
}
Also used : org.wso2.carbon.registry.core(org.wso2.carbon.registry.core) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 9 with RegistryException

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]);
}
Also used : ResourceData(org.wso2.carbon.registry.common.ResourceData) SolrDocument(org.apache.solr.common.SolrDocument) SolrClient(org.wso2.carbon.registry.indexing.solr.SolrClient) SolrDocumentList(org.apache.solr.common.SolrDocumentList)

Example 10 with RegistryException

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;
}
Also used : ResourceData(org.wso2.carbon.registry.common.ResourceData) Collection(org.wso2.carbon.registry.core.Collection)

Aggregations

ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)10 RegistryException (org.wso2.carbon.registry.api.RegistryException)10 ResourceData (org.wso2.carbon.registry.common.ResourceData)3 Collection (org.wso2.carbon.registry.core.Collection)3 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 XMLObject (org.mozilla.javascript.xml.XMLObject)1 CarbonException (org.wso2.carbon.CarbonException)1 TagCount (org.wso2.carbon.registry.common.TagCount)1 org.wso2.carbon.registry.core (org.wso2.carbon.registry.core)1 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)1 SolrClient (org.wso2.carbon.registry.indexing.solr.SolrClient)1 AdvancedSearchResultsBean (org.wso2.carbon.registry.search.beans.AdvancedSearchResultsBean)1 CustomSearchParameterBean (org.wso2.carbon.registry.search.beans.CustomSearchParameterBean)1 UserRealm (org.wso2.carbon.user.core.UserRealm)1 UserStoreException (org.wso2.carbon.user.core.UserStoreException)1