mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
ALF-9153 Convert the Discussions Topics Listing webscript to be Java backed and Lucene free, though not fully optimised yet
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29893 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,12 +19,15 @@
|
||||
package org.alfresco.repo.web.scripts.discussion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.discussion.DiscussionServiceImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.site.SiteServiceImpl;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
@@ -157,7 +160,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
}
|
||||
|
||||
PagingRequest paging = new PagingRequest( startIndex, pageSize );
|
||||
paging.setRequestTotalCountMax( Math.max(10,startIndex+1) * pageSize );
|
||||
paging.setRequestTotalCountMax( Math.max(10*pageSize,startIndex+2*pageSize) );
|
||||
return paging;
|
||||
}
|
||||
|
||||
@@ -350,6 +353,33 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
return item;
|
||||
}
|
||||
|
||||
/*
|
||||
* Renders out the list of topics
|
||||
* TODO Fetch the post data in one go, rather than one at a time
|
||||
*/
|
||||
protected Map<String, Object> renderTopics(PagingResults<TopicInfo> topics,
|
||||
PagingRequest paging, SiteInfo site)
|
||||
{
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// Paging info
|
||||
model.put("total", topics.getTotalResultCount().getFirst());
|
||||
model.put("pageSize", paging.getMaxItems());
|
||||
model.put("startIndex", paging.getSkipCount());
|
||||
model.put("itemCount", topics.getPage().size());
|
||||
|
||||
// Data
|
||||
List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
|
||||
for(TopicInfo topic : topics.getPage())
|
||||
{
|
||||
items.add(renderTopic(topic, site));
|
||||
}
|
||||
model.put("items", items);
|
||||
|
||||
// All done
|
||||
return model;
|
||||
}
|
||||
|
||||
protected Map<String, Object> buildCommonModel(SiteInfo site, TopicInfo topic,
|
||||
PostInfo post, WebScriptRequest req)
|
||||
{
|
||||
@@ -452,6 +482,14 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
}
|
||||
nodeRef = topic.getNodeRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
// The NodeRef is the container (if it exists)
|
||||
if(siteService.hasContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT))
|
||||
{
|
||||
nodeRef = siteService.getContainer(siteName, DiscussionServiceImpl.DISCUSSION_COMPONENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(templateVars.containsKey("store_type") &&
|
||||
templateVars.containsKey("store_id") &&
|
||||
|
@@ -1054,11 +1054,8 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
|
||||
assertEquals(3, result.getInt("total"));
|
||||
assertEquals(3, result.getInt("itemCount"));
|
||||
assertEquals(3, 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("NodeTitle1", result.getJSONArray("items").getJSONObject(2).getString("title"));
|
||||
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||
assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
|
||||
@@ -1141,9 +1138,7 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
|
||||
assertEquals(3, result.getInt("total"));
|
||||
assertEquals(1, result.getInt("itemCount"));
|
||||
assertEquals(1, 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(0).getString("title"));
|
||||
assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
|
||||
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
* This class is the controller for the discussions page editing forum-posts.postt webscript.
|
||||
* This class is the controller for the discussions page editing forum-posts.post webscript.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
|
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.Map;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
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.get webscript.
|
||||
*
|
||||
* @author Nick Burch
|
||||
* @since 4.0
|
||||
*/
|
||||
public class ForumTopicsGet extends AbstractDiscussionWebScript
|
||||
{
|
||||
@Override
|
||||
protected Map<String, Object> 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);
|
||||
}
|
||||
|
||||
// Do we need to list or search?
|
||||
boolean tagSearch = false;
|
||||
String tag = req.getParameter("tag");
|
||||
if(tag != null && tag.length() > 0)
|
||||
{
|
||||
tagSearch = true;
|
||||
}
|
||||
|
||||
// Get the topics
|
||||
PagingResults<TopicInfo> topics = null;
|
||||
PagingRequest paging = buildPagingRequest(req);
|
||||
if(tagSearch)
|
||||
{
|
||||
if(site != null)
|
||||
{
|
||||
topics = discussionService.findTopics(site.getShortName(), tag, paging);
|
||||
}
|
||||
else
|
||||
{
|
||||
topics = discussionService.findTopics(nodeRef, tag, paging);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(site != null)
|
||||
{
|
||||
topics = discussionService.listTopics(site.getShortName(), paging);
|
||||
}
|
||||
else
|
||||
{
|
||||
topics = discussionService.listTopics(nodeRef, buildPagingRequest(req));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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<String, Object> 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user