From c6c2788fc324af036fa7b5cd40fbf3e32a2b29b5 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 18 Aug 2011 14:38:58 +0000 Subject: [PATCH] ALF-9153 Convert the topic+post creation webscript to be Java backed and Lucene free git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29884 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../forum/forum-posts.post.json.js | 100 -------------- .../web-scripts-application-context.xml | 7 + .../scripts/discussion/ForumTopicPost.java | 122 ++++++++++++++++++ 3 files changed, 129 insertions(+), 100 deletions(-) delete mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts.post.json.js create mode 100644 source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicPost.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts.post.json.js deleted file mode 100644 index 3965a7f67f..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts.post.json.js +++ /dev/null @@ -1,100 +0,0 @@ - - - - -function ensureTagScope(node) -{ - if (! node.isTagScope) - { - node.isTagScope = true; - } - - // also check the parent (the site!) - if (! node.parent.isTagScope) - { - node.parent.isTagScope = true; - } -} - -/** - * Adds a post to the passed forum node. - */ -function createPost(forumNode) -{ - // fetch the data required to create a topic - var title = ""; - if (json.has("title")) - { - title = json.get("title"); - } - var content = ""; - if (json.has("content")) - { - content = json.get("content"); - } - var tags = []; - if (json.has("tags")) - { - // get the tags JSONArray and copy it into a real javascript array object - var tmp = json.get("tags"); - for (var x=0; x < tmp.length(); x++) - { - tags.push(tmp.get(x)); - } - } - - // create the topic node, and add the first child node representing the topic text - // NOTE: this is a change from the old web client, where the topic title was used as name - // for the topic node. We will use generated names to make sure we won't have naming - // clashes. - var name = getUniqueChildName(forumNode, "post"); - var topicNode = forumNode.createNode(name, "fm:topic"); - topicNode.properties.title = title; - topicNode.save(); - - // We use twice the same name for the topic and the post in it - var contentNode = topicNode.createNode(name, "fm:post"); - contentNode.mimetype = "text/html"; - contentNode.properties.title = title; - contentNode.content = content; - contentNode.save(); - - // add the cm:syndication aspect - var props = new Array(); - props["cm:published"] = new Date(); - contentNode.addAspect("cm:syndication", props); - - // add the tags to the topic node for now - topicNode.tags = tags; - - return topicNode; -} - -function main() -{ - // get requested node - var node = getRequestNode(); - if (status.getCode() != status.STATUS_OK) - { - return; - } - - ensureTagScope(node); - - var topicPost = createPost(node); - - model.postData = getTopicPostData(topicPost); - - // create an activity entry - if (json.has("site") && json.has("page")) - { - var data = - { - title: model.postData.post.properties.title, - page: json.get("page") + "?topicId=" + model.postData.topic.name - } - activities.postActivity("org.alfresco.discussions.post-created", json.get("site"), "discussions", jsonUtils.toJSONString(data)); - } -} - -main(); diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index e9aad1e26a..523d71c2e9 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1600,6 +1600,13 @@ class="org.alfresco.repo.web.scripts.discussion.ForumPostRepliesGet" parent="abstractDiscussionWebScript"> + + + + +