mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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
This commit is contained in:
@@ -1,99 +0,0 @@
|
|||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/requestutils.lib.js">
|
|
||||||
<import resource="classpath:alfresco/templates/webscripts/org/alfresco/repository/discussions/topicpost.lib.js">
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
@@ -1595,6 +1595,12 @@
|
|||||||
parent="abstractDiscussionWebScript">
|
parent="abstractDiscussionWebScript">
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- Lists the discussions replies for a topic or post -->
|
||||||
|
<bean id="webscript.org.alfresco.repository.discussions.posts.forum-post-replies.get"
|
||||||
|
class="org.alfresco.repo.web.scripts.discussion.ForumPostRepliesGet"
|
||||||
|
parent="abstractDiscussionWebScript">
|
||||||
|
</bean>
|
||||||
|
|
||||||
<!-- Lists the Discussions for a site -->
|
<!-- Lists the Discussions for a site -->
|
||||||
<!--
|
<!--
|
||||||
<bean id="webscript.org.alfresco.repository.discussions.forum.forum-posts.get"
|
<bean id="webscript.org.alfresco.repository.discussions.forum.forum-posts.get"
|
||||||
|
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.web.scripts.discussion;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.discussion.PostInfo;
|
||||||
|
import org.alfresco.service.cmr.discussion.PostWithReplies;
|
||||||
|
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 page creating forum-post-replies.get webscript.
|
||||||
|
*
|
||||||
|
* @author Nick Burch
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public class ForumPostRepliesGet extends AbstractDiscussionWebScript
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef,
|
||||||
|
TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json,
|
||||||
|
Status status, Cache cache)
|
||||||
|
{
|
||||||
|
// How many levels did they want?
|
||||||
|
int levels = 1;
|
||||||
|
String levelsS = req.getParameter("levels");
|
||||||
|
if(levelsS != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
levels = Integer.parseInt(levelsS);
|
||||||
|
}
|
||||||
|
catch(NumberFormatException e)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Level depth parameter invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch the replies
|
||||||
|
PostWithReplies replies;
|
||||||
|
if(post != null)
|
||||||
|
{
|
||||||
|
replies = discussionService.listPostReplies(post, levels);
|
||||||
|
}
|
||||||
|
else if(topic != null)
|
||||||
|
{
|
||||||
|
replies = discussionService.listPostReplies(topic, levels);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
String error = "Node was of the wrong type, only Topic and Post are supported";
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the common model parts
|
||||||
|
Map<String, Object> model = buildCommonModel(site, topic, post, req);
|
||||||
|
|
||||||
|
// Build the JSON for the replies
|
||||||
|
model.put("data", renderReplies(replies, site).get("children"));
|
||||||
|
|
||||||
|
// All done
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> renderReplies(PostWithReplies replies, SiteInfo site)
|
||||||
|
{
|
||||||
|
Map<String, Object> reply = renderPost(replies.getPost(), site);
|
||||||
|
reply.put("childCount", replies.getReplies().size());
|
||||||
|
|
||||||
|
List<Map<String,Object>> r = new ArrayList<Map<String,Object>>();
|
||||||
|
for(PostWithReplies child : replies.getReplies())
|
||||||
|
{
|
||||||
|
r.add(renderReplies(child, site));
|
||||||
|
}
|
||||||
|
reply.put("children", r);
|
||||||
|
|
||||||
|
return reply;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user