Search in sources :

Example 11 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class AbstractRuleWebScript method parseRequestForNodeRef.

/**
 * Parses the request and providing it's valid returns the NodeRef.
 *
 * @param req The webscript request
 * @return The NodeRef passed in the request
 */
protected NodeRef parseRequestForNodeRef(WebScriptRequest req) {
    // get the parameters that represent the NodeRef, we know they are present
    // otherwise this webscript would not have matched
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    String storeType = templateVars.get("store_type");
    String storeId = templateVars.get("store_id");
    String nodeId = templateVars.get("id");
    // create the NodeRef and ensure it is valid
    StoreRef storeRef = new StoreRef(storeType, storeId);
    NodeRef nodeRef = new NodeRef(storeRef, nodeId);
    if (!this.nodeService.exists(nodeRef)) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + nodeRef.toString());
    }
    return nodeRef;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 12 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class AbstractBlogWebScript method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    if (templateVars == null) {
        String error = "No parameters supplied";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    // Parse the JSON, if supplied
    JSONObject json = null;
    String contentType = req.getContentType();
    if (contentType != null && contentType.indexOf(';') != -1) {
        contentType = contentType.substring(0, contentType.indexOf(';'));
    }
    if (MimetypeMap.MIMETYPE_JSON.equals(contentType)) {
        JSONParser parser = new JSONParser();
        try {
            json = (JSONObject) parser.parse(req.getContent().getContent());
        } catch (IOException io) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
        } catch (ParseException pe) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
        }
    }
    // Did they request it by node reference or site?
    NodeRef nodeRef = null;
    SiteInfo site = null;
    BlogPostInfo blog = null;
    if (templateVars.containsKey("site")) {
        // Site, and Optionally Blog Post
        String siteName = templateVars.get("site");
        site = siteService.getSite(siteName);
        if (site == null) {
            String error = "Could not find site: " + siteName;
            throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
        }
        // Did they give a blog post name too?
        if (templateVars.containsKey("path")) {
            String name = templateVars.get("path");
            blog = blogService.getBlogPost(siteName, name);
            if (blog == null) {
                String error = "Could not find blog '" + name + "' for site '" + site.getShortName() + "'";
                throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
            }
            nodeRef = blog.getNodeRef();
        } else {
            // The NodeRef is the container (if it exists)
            if (siteService.hasContainer(siteName, BlogServiceImpl.BLOG_COMPONENT)) {
                nodeRef = siteService.getContainer(siteName, BlogServiceImpl.BLOG_COMPONENT);
            }
        }
    } else if (templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("id")) {
        // NodeRef, should be a Blog Post
        StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
        nodeRef = new NodeRef(store, templateVars.get("id"));
        if (!nodeService.exists(nodeRef)) {
            String error = "Could not find node: " + nodeRef;
            throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
        }
        // Try to build the appropriate object for it
        blog = blogService.getForNodeRef(nodeRef);
        // See if it's actually attached to a site
        if (blog != null) {
            NodeRef container = blog.getContainerNodeRef();
            if (container != null) {
                NodeRef maybeSite = nodeService.getPrimaryParent(container).getParentRef();
                if (maybeSite != null) {
                    // Try to make it a site, will return Null if it isn't one
                    site = siteService.getSite(maybeSite);
                }
            }
        }
    } else {
        String error = "Unsupported template parameters found";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    // Have the real work done
    return executeImpl(site, nodeRef, blog, req, json, status, cache);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) StoreRef(org.alfresco.service.cmr.repository.StoreRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) IOException(java.io.IOException) ParseException(org.json.simple.parser.ParseException) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo)

Example 13 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class DownloadDelete method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    if (templateVars == null) {
        String error = "No parameters supplied";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    if (!(templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("node_id"))) {
        String error = "Missing template variables (store_type, store_id or node_id).";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
    NodeRef nodeRef = new NodeRef(store, templateVars.get("node_id"));
    if (!nodeService.exists(nodeRef)) {
        String error = "Could not find node: " + nodeRef;
        throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
    }
    downloadService.cancelDownload(nodeRef);
    status.setCode(HttpServletResponse.SC_OK);
    return new HashMap<String, Object>();
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap)

Example 14 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project alfresco-remote-api by Alfresco.

the class DownloadStatusGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    if (templateVars == null) {
        String error = "No parameters supplied";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    if (!(templateVars.containsKey("store_type") && templateVars.containsKey("store_id") && templateVars.containsKey("node_id"))) {
        String error = "Missing template variables (store_type, store_id or node_id).";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    StoreRef store = new StoreRef(templateVars.get("store_type"), templateVars.get("store_id"));
    NodeRef nodeRef = new NodeRef(store, templateVars.get("node_id"));
    if (!nodeService.exists(nodeRef)) {
        String error = "Could not find node: " + nodeRef;
        throw new WebScriptException(Status.STATUS_NOT_FOUND, error);
    }
    DownloadStatus downloadStatus = downloadService.getDownloadStatus(nodeRef);
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("downloadStatus", downloadStatus);
    return result;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) DownloadStatus(org.alfresco.service.cmr.download.DownloadStatus)

Example 15 with StoreRef

use of org.alfresco.service.cmr.repository.StoreRef in project acs-community-packaging by Alfresco.

the class AdminNodeBrowseBean method getStores.

/**
 * Gets the list of repository stores
 *
 * @return stores
 */
public DataModel getStores() {
    if (stores == null) {
        List<StoreRef> storeRefs = getNodeService().getStores();
        stores = new ListDataModel(storeRefs);
    }
    return stores;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) ListDataModel(javax.faces.model.ListDataModel)

Aggregations

StoreRef (org.alfresco.service.cmr.repository.StoreRef)67 NodeRef (org.alfresco.service.cmr.repository.NodeRef)50 HashMap (java.util.HashMap)18 QName (org.alfresco.service.namespace.QName)17 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)13 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)13 PropertyValue (org.alfresco.solr.client.PropertyValue)11 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)10 ArrayList (java.util.ArrayList)9 ContentPropertyValue (org.alfresco.solr.client.ContentPropertyValue)9 MLTextPropertyValue (org.alfresco.solr.client.MLTextPropertyValue)9 IOException (java.io.IOException)7 Date (java.util.Date)6 MultiPropertyValue (org.alfresco.solr.client.MultiPropertyValue)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 PermissionService (org.alfresco.service.cmr.security.PermissionService)5 SolrCore (org.apache.solr.core.SolrCore)5 StringTokenizer (java.util.StringTokenizer)4 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4