From bc5454a8611400cfcfcded28da84e15b59f3901a Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 18 Aug 2011 12:34:27 +0000 Subject: [PATCH] ALF-9153 Convert the discussions replies listing webscript to be lucene free and java backed git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29868 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../posts/forum-post-replies.get.js | 99 ----------------- .../web-scripts-application-context.xml | 6 + .../discussion/ForumPostRepliesGet.java | 105 ++++++++++++++++++ 3 files changed, 111 insertions(+), 99 deletions(-) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post-replies.get.js create mode 100644 source/java/org/alfresco/repo/web/scripts/discussion/ForumPostRepliesGet.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post-replies.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post-replies.get.js deleted file mode 100644 index ad26ec6627..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/posts/forum-post-replies.get.js +++ /dev/null @@ -1,99 +0,0 @@ - - - -/** - * Returns all reply nodes to a post - */ -function getRepliesForPost(post) -{ - var children = post.sourceAssocs["cm:references"]; - if (children === null) - { - return new Array(); - } - else - { - return children; - } -} - -/** - * Returns a data object containing the passed post, - * the number of replies to the post, as well as - * the replies themselves if levels > 1 - */ -function getReplyDataRecursive(post, levels) -{ - // encapsulates the data: node, childCount, children - var data = getReplyPostData(post); - var children = getRepliesForPost(post); - data.childCount = children.length; - if (levels > 1) - { - data.children = new Array(); - var x = 0; - for (x =0; x < children.length; x++) - { - data.children.push(getReplyDataRecursive(children[x], levels-1)); - } - } - return data; -} - -/** - * Returns a data object containing all replies of a post. - * @return data object with "children" property that contains an array of reply data objects - */ -function getRepliesImpl(post, levels) -{ - var data = getReplyDataRecursive(post, levels + 1); - if (data.children != undefined) - { - return data.children; - } - else - { - return new Array(); - } -} - -function getReplies(node, levels) -{ - // we have to differentiate here whether this is a top-level post or a reply - if (node.type == "{http://www.alfresco.org/model/forum/1.0}topic") - { - // find the primary post node. - var data = getTopicPostData(node); - return getRepliesImpl(data.post, levels); - } - else if (node.type == "{http://www.alfresco.org/model/forum/1.0}post") - { - // the node is already a post - return getRepliesImpl(node, levels); - } - else - { - status.setCode(STATUS_BAD_REQUEST, "Incompatible node type. Required either fm:topic or fm:post. Received: " + node.type); - } -} - -function main() -{ - // get requested node - var node = getRequestNode(); - if (status.getCode() != status.STATUS_OK) - { - return; - } - - // process additional parameters - var levels = args["levels"] != undefined ? parseInt(args["levels"]) : 1; - - model.data = getReplies(node, levels); - - // fetch the contentLength param - var contentLength = args["contentLength"] != undefined ? parseInt(args["contentFormat"]) : -1; - model.contentLength = isNaN(contentLength) ? -1 : contentLength; -} - -main(); diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 5eb75d6d28..e9aad1e26a 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1595,6 +1595,12 @@ parent="abstractDiscussionWebScript"> + + + +