diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-new.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-new.get.js deleted file mode 100644 index f45233afb1..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/discussions/forum/forum-posts-new.get.js +++ /dev/null @@ -1,50 +0,0 @@ - - - - - -const DEFAULT_NUM_DAYS = 30; - -/** - * Fetches all posts added to the forum in the last numdays days - */ -function getTopicPostList(node, numdays, index, count) -{ - var fromDate = getTodayMinusXDays(numdays); - - // query information - var luceneQuery = " +TYPE:\"{http://www.alfresco.org/model/forum/1.0}topic\"" + - " +PATH:\"" + node.qnamePath + "/*\" " + - getCreationDateRangeQuery(fromDate, null); - 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; - var numdays = args["numdays"] != undefined ? parseInt(args["numdays"]) : DEFAULT_NUM_DAYS; - - // fetch the data and assign it to the model - model.data = getTopicPostList(node, numdays, 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 0e02ed54f8..fdd49961c6 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -1620,6 +1620,12 @@ parent="abstractDiscussionWebScript"> + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java new file mode 100644 index 0000000000..3433278cac --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/discussion/ForumTopicsRecentGet.java @@ -0,0 +1,102 @@ +/* + * 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.Date; +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-new.get webscript. + * + * @author Nick Burch + * @since 4.0 + */ +public class ForumTopicsRecentGet extends AbstractDiscussionWebScript +{ + protected static final int RECENT_SEARCH_PERIOD_DAYS = 30; + protected static final long ONE_DAY_MS = 24*60*60*1000; + + @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 date range to search over + String numDaysS = req.getParameter("numdays"); + int numDays = RECENT_SEARCH_PERIOD_DAYS; + if(numDaysS != null) + { + numDays = Integer.parseInt(numDaysS); + } + + Date now = new Date(); + Date from = new Date(now.getTime() - numDays*ONE_DAY_MS); + Date to = new Date(now.getTime() + ONE_DAY_MS); + + // Get the topics for the user + PagingResults topics = null; + PagingRequest paging = buildPagingRequest(req); + if(site != null) + { + topics = discussionService.listTopics(site.getShortName(), from, to, paging); + } + else + { + topics = discussionService.listTopics(nodeRef, from, to, 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; + } +}