From 8d41b70486dfefdf1714c9d93ad6dad544839498 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 12 Oct 2011 18:04:40 +0000 Subject: [PATCH] ALF-10413 Blog GET webscripts can now correctly work in a R/O transaction git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31186 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/blogs/blog/blog.get.desc.xml | 4 +- .../blogs/post/blog-post.get.desc.xml | 4 +- .../posts/blog-posts-mydrafts.get.desc.xml | 4 +- .../posts/blog-posts-mypublished.get.desc.xml | 4 +- .../blogs/posts/blog-posts-new.get.desc.xml | 4 +- .../posts/blog-posts-per-month.get.desc.xml | 4 +- .../blog-posts-publishedext.get.desc.xml | 4 +- .../blogs/posts/blog-posts.get.desc.xml | 4 +- .../web/scripts/blogs/RequestUtilsLibJs.java | 213 ------------------ 9 files changed, 16 insertions(+), 229 deletions(-) delete mode 100644 source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog/blog.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog/blog.get.desc.xml index aaaa4e439b..058e7c31d2 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog/blog.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/blog/blog.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id} argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.get.desc.xml index b63bdc6994..cff7fe929a 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/post/blog-post.get.desc.xml @@ -5,5 +5,5 @@ /api/blog/post/node/{store_type}/{store_id}/{id} argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.desc.xml index a0b72c51a1..2034cc1d29 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mydrafts.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id}/posts/mydrafts argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.desc.xml index 83128aca18..43d7daa9a4 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-mypublished.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id}/posts/mypublished argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.desc.xml index cf13563e9b..b7c28a782e 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-new.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id}/posts/new?numdays={numdays} argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.desc.xml index 9bef09a10c..c45f9d3bc4 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-per-month.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id}/postspermonth argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-publishedext.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-publishedext.get.desc.xml index 4709c476b8..7691a1ae2a 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-publishedext.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts-publishedext.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id}/posts/publishedext argument user - required - \ No newline at end of file + required + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.desc.xml index 854995813d..d7933a67ca 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/blogs/posts/blog-posts.get.desc.xml @@ -6,5 +6,5 @@ /api/blog/node/{store_type}/{store_id}/{id}/posts argument user - required - \ No newline at end of file + required + diff --git a/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java b/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java deleted file mode 100644 index c74b7e50de..0000000000 --- a/source/java/org/alfresco/repo/web/scripts/blogs/RequestUtilsLibJs.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (C) 2005-2011 Alfresco Software Limited. - * - * This file is part of Alfresco - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - */ -package org.alfresco.repo.web.scripts.blogs; - -import java.util.Map; -import java.util.StringTokenizer; - -import javax.servlet.http.HttpServletResponse; - -import org.alfresco.model.ContentModel; -import org.alfresco.repo.jscript.ScriptNode; -import org.alfresco.repo.nodelocator.CompanyHomeNodeLocator; -import org.alfresco.repo.nodelocator.NodeLocatorService; -import org.alfresco.repo.nodelocator.SitesHomeNodeLocator; -import org.alfresco.repo.nodelocator.UserHomeNodeLocator; -import org.alfresco.repo.security.permissions.AccessDeniedException; -import org.alfresco.service.ServiceRegistry; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.site.SiteInfo; -import org.alfresco.service.namespace.QName; -import org.springframework.extensions.webscripts.WebScriptException; -import org.springframework.extensions.webscripts.WebScriptRequest; - -/** - * This class is a port of a previous JavaScript library. - * - * @author Neil Mc Erlean (based on previous JavaScript) - * @since 4.0 - * @deprecated Not to be used/extended as this is likely to be refactored. - */ -public class RequestUtilsLibJs -{ - //FIXME It will be refactored when the other services are ported from JavaScript to Java. - - /** - * Gets the NodeRef requested based on the following templates: - * - *
-     * /api/blog/site/{site}/{container}/{path}/posts
-     * /api/blog/site/{site}/{container}/posts
-     * /api/blog/node/{store_type}/{store_id}/{id}/posts
-     * 
- */ - public static NodeRef getRequestNode(WebScriptRequest req, ServiceRegistry services) - { - NodeRef result = null; - - Map templateVars = req.getServiceMatch().getTemplateVars(); - - // If the template args contains a "store_type" then we we have a standard NodeRef URI template pattern - // check whether we got a node reference or a site related uri - final String storeType = templateVars.get("store_type"); - final String site = templateVars.get("site"); - if (storeType != null) - { - result = findFromReference(templateVars, services); - } - else if (site != null) - { - result = findNodeInSite(templateVars, services); - } - else - { - throw new WebScriptException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unknown request parameters (webscript incorrectly configured?)"); - } - - if (!services.getNodeService().exists(result)) - { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find node: " + result.toString()); - } - - return result; - } - - private static NodeRef findFromReference(final Map templateVars, ServiceRegistry services) - { - NodeRef result = null; - - String nodeRefString = templateVars.get("store_type") + "://" + templateVars.get("store_id") + "/" + templateVars.get("id"); - - // These webscripts support some non-standard NodeRef URI constructions. - - NodeLocatorService nodeLocatorService = services.getNodeLocatorService(); - if (nodeRefString.equals("alfresco://company/home")) - { - result = nodeLocatorService.getNode(CompanyHomeNodeLocator.NAME, null, null); - } - else if (nodeRefString.equals("alfresco://user/home")) - { - result = nodeLocatorService.getNode(UserHomeNodeLocator.NAME, null, null); - } - else if (nodeRefString.equals("alfresco://sites/home")) - { - result = nodeLocatorService.getNode(SitesHomeNodeLocator.NAME, null, null); - } - else if (NodeRef.isNodeRef(nodeRefString)) - { - result = new NodeRef(nodeRefString); - } - else - { -// result = new Nodesearch.findNode(nodeRef); - } - - if (result == null) - { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Node " + nodeRefString + "does not exist"); - } - return result; - } - - /** - * Returns the node as specified by the given arguments. - * - * @param siteId the site for which a node is requested - * @param containerId the component to look in for the node. - * @param path a path to the node. Returns the root node in case path is null or '' - * return null in case no node can be found for the given path - * @return the node or a json error in case the node could not be fetched. Check with . - */ - private static NodeRef findNodeInSite(final Map templateVars, ServiceRegistry services) - { - final String siteId = templateVars.get("site"); - final String containerId = templateVars.get("container"); - String path = templateVars.get("path"); - if (path == null) path = ""; - - SiteInfo site = services.getSiteService().getSite(siteId); - if (site == null) - { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Site not found: '" + siteId + "'"); - } - - NodeRef node = services.getSiteService().getContainer(siteId, containerId); - if (node == null) - { - node = services.getSiteService().createContainer(siteId, containerId, null, null); - if (node == null) - { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to fetch container '" + containerId + "' of site '" + siteId + "'. (No write permission?)"); - } - } - - // try to fetch the the path is there is any - if (path != null && !path.isEmpty()) - { - node = childByNamePath(path, node, services); - if (node == null) - { - throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "No node found for the given path: \"" + path + "\" in container " + containerId + " of site " + siteId); - } - } - - return node; - } - - - /** - * Gets a descendant node by navigating a cm:name-based path e.g. /QA/Testing/Docs - * - * @see ScriptNode#childByNamePath(String) - */ - private static NodeRef childByNamePath(String path, NodeRef rootNode, ServiceRegistry services) - { - // This is based partially on ScriptNode.childByNamePath, but supports less path variations. - NodeRef result = null; - QName nodeType = services.getNodeService().getType(rootNode); - - if (services.getDictionaryService().isSubClass(nodeType, ContentModel.TYPE_FOLDER)) - { - /** - * The current node is a folder. - * optimized code path for cm:folder and sub-types supporting getChildrenByName() method - */ - StringTokenizer t = new StringTokenizer(path, "/"); - if (t.hasMoreTokens()) - { - result = rootNode; - while (t.hasMoreTokens() && result != null) - { - String name = t.nextToken(); - try - { - result = services.getNodeService().getChildByName(result, ContentModel.ASSOC_CONTAINS, name); - } - catch (AccessDeniedException ade) - { - result = null; - } - } - } - } - - return result; - } - -}