mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9153 Support listing discussion topics by created date, as needed by the hot webscript, with service tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29961 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -560,7 +560,7 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
// to get the most recent nodes
|
||||
PagingRequest paging = new PagingRequest(0, 1);
|
||||
CannedQueryResults<NodeBackedEntity> results =
|
||||
listEntries(topic.getNodeRef(), ForumModel.TYPE_POST, null, false, paging);
|
||||
listEntries(topic.getNodeRef(), ForumModel.TYPE_POST, null, null, null, false, paging);
|
||||
|
||||
// Bail if the topic lacks posts
|
||||
if(results.getPage().size() == 0)
|
||||
@@ -596,7 +596,7 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
PagingRequest paging) {
|
||||
// Do the listing, oldest first
|
||||
CannedQueryResults<NodeBackedEntity> nodes =
|
||||
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, true, paging);
|
||||
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, null, null, true, paging);
|
||||
|
||||
// Wrap and return
|
||||
return wrap(nodes, nodeRef);
|
||||
@@ -621,7 +621,32 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
String username, PagingRequest paging) {
|
||||
// Do the listing, oldest first
|
||||
CannedQueryResults<NodeBackedEntity> nodes =
|
||||
listEntries(nodeRef, ForumModel.TYPE_TOPIC, username, true, paging);
|
||||
listEntries(nodeRef, ForumModel.TYPE_TOPIC, username, null, null, true, paging);
|
||||
|
||||
// Wrap and return
|
||||
return wrap(nodes, nodeRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<TopicInfo> listTopics(String siteShortName,
|
||||
Date from, Date to, PagingRequest paging) {
|
||||
NodeRef container = getSiteDiscussionsContainer(siteShortName, false);
|
||||
if(container == null)
|
||||
{
|
||||
// No topics
|
||||
return new EmptyPagingResults<TopicInfo>();
|
||||
}
|
||||
|
||||
// We can now fetch by parent nodeRef
|
||||
return listTopics(container, from, to, paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
|
||||
Date from, Date to, PagingRequest paging) {
|
||||
// Do the listing, oldest first
|
||||
CannedQueryResults<NodeBackedEntity> nodes =
|
||||
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, from, to, true, paging);
|
||||
|
||||
// Wrap and return
|
||||
return wrap(nodes, nodeRef);
|
||||
@@ -711,7 +736,7 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
{
|
||||
// Do the listing, oldest first
|
||||
CannedQueryResults<NodeBackedEntity> nodes =
|
||||
listEntries(topic.getNodeRef(), ForumModel.TYPE_POST, null, true, paging);
|
||||
listEntries(topic.getNodeRef(), ForumModel.TYPE_POST, null, null, null, true, paging);
|
||||
|
||||
// Wrap and return
|
||||
return wrap(nodes, topic);
|
||||
@@ -840,7 +865,8 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
* type, optionally filtered by creator
|
||||
*/
|
||||
private CannedQueryResults<NodeBackedEntity> listEntries(NodeRef parent,
|
||||
QName nodeType, String creatorUsername, boolean oldestFirst, PagingRequest paging)
|
||||
QName nodeType, String creatorUsername, Date from, Date to,
|
||||
boolean oldestFirst, PagingRequest paging)
|
||||
{
|
||||
// Grab the factory
|
||||
GetChildrenAuditableCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenAuditableCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
|
||||
@@ -858,7 +884,7 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
|
||||
// Run the canned query
|
||||
GetChildrenAuditableCannedQuery cq = (GetChildrenAuditableCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
|
||||
parent, nodeType, creatorUsername, null, null, null,
|
||||
parent, nodeType, creatorUsername, from, to, null,
|
||||
null, null, sorting, paging);
|
||||
|
||||
// Execute the canned query
|
||||
|
@@ -604,7 +604,36 @@ public class DiscussionServiceImplTest
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals("NT1", topics.getPage().get(0).getTitle());
|
||||
|
||||
|
||||
// Check by created date, everything was just created
|
||||
Date now = new Date();
|
||||
Date yesterday = new Date(now.getTime()-ONE_DAY_MS-60000);
|
||||
Date tomorrow = new Date(now.getTime()+ONE_DAY_MS);
|
||||
Date future = new Date(now.getTime()+10*ONE_DAY_MS);
|
||||
Date fourDaysAgo = new Date(now.getTime()-4*ONE_DAY_MS);
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), yesterday, tomorrow, new PagingRequest(10));
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals("ST1", topics.getPage().get(0).getTitle());
|
||||
assertEquals("ST2", topics.getPage().get(1).getTitle());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, new PagingRequest(10));
|
||||
assertEquals(3, topics.getPage().size());
|
||||
assertEquals("NT1", topics.getPage().get(0).getTitle());
|
||||
assertEquals("NT2", topics.getPage().get(1).getTitle());
|
||||
assertEquals("NT3", topics.getPage().get(2).getTitle());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, yesterday, new PagingRequest(10));
|
||||
assertEquals(0, topics.getPage().size());
|
||||
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, fourDaysAgo, yesterday, new PagingRequest(10));
|
||||
assertEquals(0, topics.getPage().size());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), tomorrow, future, new PagingRequest(10));
|
||||
assertEquals(0, topics.getPage().size());
|
||||
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, tomorrow, future, new PagingRequest(10));
|
||||
assertEquals(0, topics.getPage().size());
|
||||
|
||||
|
||||
// Add tags to a few
|
||||
siteT2.getTags().add(TAG_1);
|
||||
nodeT2.getTags().add(TAG_1);
|
||||
@@ -698,6 +727,26 @@ public class DiscussionServiceImplTest
|
||||
assertEquals("NT2", topics.getPage().get(2).getTitle());
|
||||
|
||||
|
||||
// Try listing by date range
|
||||
// Only Site1 and Node2 are still created today, Node1 was a day ago
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), yesterday, tomorrow, new PagingRequest(10));
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals("ST1", topics.getPage().get(0).getTitle());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, new PagingRequest(10));
|
||||
assertEquals(2, topics.getPage().size());
|
||||
assertEquals("NT1", topics.getPage().get(0).getTitle());
|
||||
assertEquals("NT2", topics.getPage().get(1).getTitle());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, yesterday, new PagingRequest(10));
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals("ST2", topics.getPage().get(0).getTitle());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, fourDaysAgo, yesterday, new PagingRequest(10));
|
||||
assertEquals(1, topics.getPage().size());
|
||||
assertEquals("NT3", topics.getPage().get(0).getTitle());
|
||||
|
||||
|
||||
// Now create a couple of check posts
|
||||
PostInfo siteCP1 = DISCUSSION_SERVICE.createPost(siteT2, "Check");
|
||||
PostInfo nodeCP1 = DISCUSSION_SERVICE.createPost(nodeT2, "Check");
|
||||
|
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.alfresco.service.cmr.discussion;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
@@ -176,6 +178,19 @@ public interface DiscussionService {
|
||||
@NotAuditable
|
||||
PagingResults<TopicInfo> listTopics(NodeRef nodeRef, String username, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all topics in a site, created in the given date range
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<TopicInfo> listTopics(String siteShortName, Date from, Date to, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all topics attached to the specified Node, created in the
|
||||
* given date range
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<TopicInfo> listTopics(NodeRef nodeRef, Date from, Date to, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Searches for all topics in a site, filtered by username or tag
|
||||
*/
|
||||
@@ -210,15 +225,17 @@ public interface DiscussionService {
|
||||
|
||||
/**
|
||||
* Retrieves all posts in a site, across all topics
|
||||
* TODO Is this needed?
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<PostInfo> listPosts(String siteShortName, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all posts attached to the specified Node, across all topics
|
||||
* TODO Is this needed?
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<PostInfo> listPosts(NodeRef nodeRef, PagingRequest paging);
|
||||
|
||||
// TODO Hot, New and Mine listing support
|
||||
// TODO Hot topics support
|
||||
}
|
||||
|
Reference in New Issue
Block a user