From a66a4099f8d598251db99ed1eaecb6aaed37320b Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 22 Aug 2011 13:25:38 +0000 Subject: [PATCH] ALF-9153 Convert the user discussions listing webscript to be Java backed and lucene free git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29950 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../discussions/forum/forum-posts-mine.get.js | 44 --------- .../web-scripts-application-context.xml | 6 ++ .../discussion/DiscussionRestApiTest.java | 13 +-- .../discussion/ForumTopicsMineGet.java | 90 +++++++++++++++++++ 4 files changed, 100 insertions(+), 53 deletions(-) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-mine.get.js create mode 100644 source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-mine.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-mine.get.js deleted file mode 100644 index 323b8e26cb..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-mine.get.js +++ /dev/null @@ -1,44 +0,0 @@ - - - - -/** - * Fetches all posts added to the forum in the last numdays days - */ -function getTopicPostList(node, index, count) -{ - // query information - var luceneQuery = "+TYPE:\"{http://www.alfresco.org/model/forum/1.0}topic\" " + - "+PATH:\"" + node.qnamePath + "/*\" " + - "+@cm\\:creator:\"" + person.properties.userName + "\""; - var sortAttribute = "@{http://www.alfresco.org/model/content/1.0}published"; - - // get the data - return getPagedResultsDataByLuceneQuery(node, luceneQuery, sortAttribute, false, index, count, getTopicPostData); -} - -function main() -{ - // get requested node - var node = getRequestNode(); - if (status.getCode() != status.STATUS_OK) - { - return; - } - - // process additional parameters - var index = args["startIndex"] != undefined ? parseInt(args["startIndex"]) : 0; - var count = args["pageSize"] != undefined ? parseInt(args["pageSize"]) : 10; - - // fetch the data and assign it to the model - model.data = getTopicPostList(node, index, count); - - // fetch the contentLength param - var contentLength = args["contentLength"] != undefined ? parseInt(args["contentLength"]) : -1; - model.contentLength = isNaN(contentLength) ? -1 : contentLength; - - // also set the forum node - model.forum = node; -} - -main(); diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index aae3ffa14b..0e02ed54f8 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1614,6 +1614,12 @@ parent="abstractDiscussionWebScript"> + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java b/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java index e8f5930095..e298f54c4b 100644 --- a/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java +++ b/source/java/org/alfresco/repo/web/scripts/discussion/DiscussionRestApiTest.java @@ -190,11 +190,9 @@ public class DiscussionRestApiTest extends BaseWebScriptTest // add the user as a member with the given role this.siteService.setMembership(SITE_SHORT_NAME_DISCUSSION, userName, role); - // Give them access to the test node - // TODO This shouldn't be needed when the webscripts use the service properly - // (We only need it because they go about adding tag scopes and aspects) + // Give the test user access to the test node + // They need to be able to read it, and create children of it permissionService.setPermission(FORUM_NODE, userName, PermissionService.READ, true); - permissionService.setPermission(FORUM_NODE, userName, PermissionService.WRITE, true); permissionService.setPermission(FORUM_NODE, userName, PermissionService.CREATE_CHILDREN, true); } @@ -1099,11 +1097,8 @@ public class DiscussionRestApiTest extends BaseWebScriptTest assertEquals(2, result.getInt("total")); assertEquals(2, result.getInt("itemCount")); assertEquals(2, result.getJSONArray("items").length()); - // TODO This appears to be incorrect... - assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title")); - assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(1).getString("title")); -// assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title")); -// assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title")); + assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title")); + assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title")); assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount")); assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount")); diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java new file mode 100644 index 0000000000..9aa6a142f5 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsMineGet.java @@ -0,0 +1,90 @@ +/* + * 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.discussion; + +import java.util.Map; + +import org.alfresco.query.PagingRequest; +import org.alfresco.query.PagingResults; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.service.cmr.discussion.PostInfo; +import org.alfresco.service.cmr.discussion.TopicInfo; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.site.SiteInfo; +import org.json.JSONObject; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * This class is the controller for the discussions topics fetching forum-posts-mine.get webscript. + * + * @author Nick Burch + * @since 4.0 + */ +public class ForumTopicsMineGet extends AbstractDiscussionWebScript +{ + @Override + protected Map executeImpl(SiteInfo site, NodeRef nodeRef, + TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, + Status status, Cache cache) + { + // They shouldn't be trying to list of an existing Post or Topic + if(topic != null || post != null) + { + String error = "Can't list Topics inside an existing Topic or Post"; + throw new WebScriptException(Status.STATUS_BAD_REQUEST, error); + } + + // Grab the current user to list for + String username = AuthenticationUtil.getFullyAuthenticatedUser(); + + // Get the topics for the user + PagingResults topics = null; + PagingRequest paging = buildPagingRequest(req); + if(site != null) + { + topics = discussionService.listTopics(site.getShortName(), username, paging); + } + else + { + topics = discussionService.listTopics(nodeRef, username, paging); + } + + + // If they did a site based search, and the component hasn't + // been created yet, use the site for the permissions checking + if(site != null && nodeRef == null) + { + nodeRef = site.getNodeRef(); + } + + + // Build the common model parts + Map model = buildCommonModel(site, topic, post, req); + model.put("forum", nodeRef); + + // Have the topics rendered + model.put("data", renderTopics(topics, paging, site)); + + // All done + return model; + } +}