ALF-2166 Update the new Discussions Java Service to allow control of if newer or older topics come first in listings (previously was always older)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30200 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-09-02 15:29:36 +00:00
parent a1ce9d37f0
commit e74b786fd2
3 changed files with 149 additions and 89 deletions

View File

@@ -584,7 +584,7 @@ public class DiscussionServiceImpl implements DiscussionService
@Override @Override
public PagingResults<TopicInfo> listTopics(String siteShortName, public PagingResults<TopicInfo> listTopics(String siteShortName,
PagingRequest paging) { boolean sortAscending, PagingRequest paging) {
NodeRef container = getSiteDiscussionsContainer(siteShortName, false); NodeRef container = getSiteDiscussionsContainer(siteShortName, false);
if(container == null) if(container == null)
{ {
@@ -593,15 +593,15 @@ public class DiscussionServiceImpl implements DiscussionService
} }
// We can now fetch by parent nodeRef // We can now fetch by parent nodeRef
return listTopics(container, paging); return listTopics(container, sortAscending, paging);
} }
@Override @Override
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef, public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
PagingRequest paging) { boolean sortAscending, PagingRequest paging) {
// Do the listing, oldest first // Do the listing, oldest first
CannedQueryResults<NodeBackedEntity> nodes = CannedQueryResults<NodeBackedEntity> nodes =
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, null, null, true, paging); listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, null, null, sortAscending, paging);
// Wrap and return // Wrap and return
return wrap(nodes, nodeRef); return wrap(nodes, nodeRef);
@@ -609,7 +609,7 @@ public class DiscussionServiceImpl implements DiscussionService
@Override @Override
public PagingResults<TopicInfo> listTopics(String siteShortName, public PagingResults<TopicInfo> listTopics(String siteShortName,
String username, PagingRequest paging) { String username, boolean sortAscending, PagingRequest paging) {
NodeRef container = getSiteDiscussionsContainer(siteShortName, false); NodeRef container = getSiteDiscussionsContainer(siteShortName, false);
if(container == null) if(container == null)
{ {
@@ -618,15 +618,15 @@ public class DiscussionServiceImpl implements DiscussionService
} }
// We can now fetch by parent nodeRef // We can now fetch by parent nodeRef
return listTopics(container, username, paging); return listTopics(container, username, sortAscending, paging);
} }
@Override @Override
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef, public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
String username, PagingRequest paging) { String username, boolean sortAscending, PagingRequest paging) {
// Do the listing, oldest first // Do the listing, oldest first
CannedQueryResults<NodeBackedEntity> nodes = CannedQueryResults<NodeBackedEntity> nodes =
listEntries(nodeRef, ForumModel.TYPE_TOPIC, username, null, null, true, paging); listEntries(nodeRef, ForumModel.TYPE_TOPIC, username, null, null, sortAscending, paging);
// Wrap and return // Wrap and return
return wrap(nodes, nodeRef); return wrap(nodes, nodeRef);
@@ -634,7 +634,7 @@ public class DiscussionServiceImpl implements DiscussionService
@Override @Override
public PagingResults<TopicInfo> listTopics(String siteShortName, public PagingResults<TopicInfo> listTopics(String siteShortName,
Date from, Date to, PagingRequest paging) { Date from, Date to, boolean sortAscending, PagingRequest paging) {
NodeRef container = getSiteDiscussionsContainer(siteShortName, false); NodeRef container = getSiteDiscussionsContainer(siteShortName, false);
if(container == null) if(container == null)
{ {
@@ -643,15 +643,15 @@ public class DiscussionServiceImpl implements DiscussionService
} }
// We can now fetch by parent nodeRef // We can now fetch by parent nodeRef
return listTopics(container, from, to, paging); return listTopics(container, from, to, sortAscending, paging);
} }
@Override @Override
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef, public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
Date from, Date to, PagingRequest paging) { Date from, Date to, boolean sortAscending, PagingRequest paging) {
// Do the listing, oldest first // Do the listing, with the sort order as requested
CannedQueryResults<NodeBackedEntity> nodes = CannedQueryResults<NodeBackedEntity> nodes =
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, from, to, true, paging); listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, from, to, sortAscending, paging);
// Wrap and return // Wrap and return
return wrap(nodes, nodeRef); return wrap(nodes, nodeRef);
@@ -690,7 +690,7 @@ public class DiscussionServiceImpl implements DiscussionService
@Override @Override
public PagingResults<TopicInfo> findTopics(String siteShortName, public PagingResults<TopicInfo> findTopics(String siteShortName,
String username, String tag, PagingRequest paging) { String username, String tag, boolean sortAscending, PagingRequest paging) {
NodeRef container = getSiteDiscussionsContainer(siteShortName, false); NodeRef container = getSiteDiscussionsContainer(siteShortName, false);
if(container == null) if(container == null)
{ {
@@ -699,12 +699,12 @@ public class DiscussionServiceImpl implements DiscussionService
} }
// We can now search by parent nodeRef // We can now search by parent nodeRef
return findTopics(container, username, tag, paging); return findTopics(container, username, tag, sortAscending, paging);
} }
@Override @Override
public PagingResults<TopicInfo> findTopics(NodeRef nodeRef, public PagingResults<TopicInfo> findTopics(NodeRef nodeRef,
String username, String tag, PagingRequest paging) { String username, String tag, boolean sortAscending, PagingRequest paging) {
// Build the query // Build the query
StringBuilder luceneQuery = new StringBuilder(); StringBuilder luceneQuery = new StringBuilder();
luceneQuery.append( luceneQuery.append(
@@ -734,7 +734,7 @@ public class DiscussionServiceImpl implements DiscussionService
sp.addStore(nodeRef.getStoreRef()); sp.addStore(nodeRef.getStoreRef());
sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(luceneQuery.toString()); sp.setQuery(luceneQuery.toString());
sp.addSort(sortOn, true); sp.addSort(sortOn, sortAscending);
if (paging.getMaxItems() > 0) if (paging.getMaxItems() > 0)
{ {
sp.setLimit(paging.getMaxItems()); sp.setLimit(paging.getMaxItems());

View File

@@ -136,10 +136,10 @@ public class DiscussionServiceImplTest
// Nothing to start with // Nothing to start with
PagingResults<TopicInfo> results = PagingResults<TopicInfo> results =
DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10)); DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, new PagingRequest(10));
assertEquals(0, results.getPage().size()); assertEquals(0, results.getPage().size());
results = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10)); results = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, new PagingRequest(10));
assertEquals(0, results.getPage().size()); assertEquals(0, results.getPage().size());
@@ -219,10 +219,10 @@ public class DiscussionServiceImplTest
// Nothing to start with // Nothing to start with
PagingResults<TopicInfo> results = PagingResults<TopicInfo> results =
DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10)); DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, new PagingRequest(10));
assertEquals(0, results.getPage().size()); assertEquals(0, results.getPage().size());
results = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10)); results = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, new PagingRequest(10));
assertEquals(0, results.getPage().size()); assertEquals(0, results.getPage().size());
@@ -551,10 +551,10 @@ public class DiscussionServiceImplTest
// To start with, there will be no topics // To start with, there will be no topics
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
@@ -574,33 +574,63 @@ public class DiscussionServiceImplTest
// Check now, will order by creation date // Check now, will order by creation date
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle()); assertEquals("ST1", topics.getPage().get(0).getTitle());
assertEquals("ST2", topics.getPage().get(1).getTitle()); assertEquals("ST2", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, new PagingRequest(10));
assertEquals(3, topics.getPage().size()); assertEquals(3, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle()); assertEquals("NT1", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle()); assertEquals("NT2", topics.getPage().get(1).getTitle());
assertEquals("NT3", topics.getPage().get(2).getTitle()); assertEquals("NT3", topics.getPage().get(2).getTitle());
// And requested newest ones first too
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), false, new PagingRequest(10));
assertEquals(2, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle());
assertEquals("ST1", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, false, new PagingRequest(10));
assertEquals(3, topics.getPage().size());
assertEquals("NT3", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle());
assertEquals("NT1", topics.getPage().get(2).getTitle());
// Check by user // Check by user
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle()); assertEquals("ST1", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, ADMIN_USER, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, ADMIN_USER, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("NT2", topics.getPage().get(0).getTitle()); assertEquals("NT2", topics.getPage().get(0).getTitle());
assertEquals("NT3", topics.getPage().get(1).getTitle()); assertEquals("NT3", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), TEST_USER, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), TEST_USER, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle()); assertEquals("ST2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, TEST_USER, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, TEST_USER, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle());
// Check by user, newest first
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, false, new PagingRequest(10));
assertEquals(1, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, ADMIN_USER, false, new PagingRequest(10));
assertEquals(2, topics.getPage().size());
assertEquals("NT3", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), TEST_USER, false, new PagingRequest(10));
assertEquals(1, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, TEST_USER, false, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle()); assertEquals("NT1", topics.getPage().get(0).getTitle());
@@ -612,26 +642,38 @@ public class DiscussionServiceImplTest
Date future = new Date(now.getTime()+10*ONE_DAY_MS); Date future = new Date(now.getTime()+10*ONE_DAY_MS);
Date fourDaysAgo = new Date(now.getTime()-4*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)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), yesterday, tomorrow, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle()); assertEquals("ST1", topics.getPage().get(0).getTitle());
assertEquals("ST2", topics.getPage().get(1).getTitle()); assertEquals("ST2", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, true, new PagingRequest(10));
assertEquals(3, topics.getPage().size()); assertEquals(3, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle()); assertEquals("NT1", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle()); assertEquals("NT2", topics.getPage().get(1).getTitle());
assertEquals("NT3", topics.getPage().get(2).getTitle()); assertEquals("NT3", topics.getPage().get(2).getTitle());
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, yesterday, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, yesterday, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, fourDaysAgo, yesterday, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, fourDaysAgo, yesterday, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), tomorrow, future, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), tomorrow, future, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, tomorrow, future, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, tomorrow, future, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
// Now check by created date, newest first
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), yesterday, tomorrow, false, new PagingRequest(10));
assertEquals(2, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle());
assertEquals("ST1", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, false, new PagingRequest(10));
assertEquals(3, topics.getPage().size());
assertEquals("NT3", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle());
assertEquals("NT1", topics.getPage().get(2).getTitle());
// Add tags to a few // Add tags to a few
@@ -645,12 +687,12 @@ public class DiscussionServiceImplTest
// Find without tags // Find without tags
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, null, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, null, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle()); assertEquals("ST1", topics.getPage().get(0).getTitle());
assertEquals("ST2", topics.getPage().get(1).getTitle()); assertEquals("ST2", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, null, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, null, true, new PagingRequest(10));
assertEquals(3, topics.getPage().size()); assertEquals(3, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle()); assertEquals("NT1", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle()); assertEquals("NT2", topics.getPage().get(1).getTitle());
@@ -658,69 +700,81 @@ public class DiscussionServiceImplTest
// Find with tags // Find with tags
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_1, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_1, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle()); assertEquals("ST2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_1, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_1, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("NT2", topics.getPage().get(0).getTitle()); assertEquals("NT2", topics.getPage().get(0).getTitle());
assertEquals("NT3", topics.getPage().get(1).getTitle()); assertEquals("NT3", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_2, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), null, TAG_2, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_2, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, null, TAG_2, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("NT2", topics.getPage().get(0).getTitle()); assertEquals("NT2", topics.getPage().get(0).getTitle());
// Find by user but not by tag // Find by user but not by tag
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, null, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, null, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle()); assertEquals("ST1", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("NT2", topics.getPage().get(0).getTitle()); assertEquals("NT2", topics.getPage().get(0).getTitle());
assertEquals("NT3", topics.getPage().get(1).getTitle()); assertEquals("NT3", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, null, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, null, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle()); assertEquals("ST2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, null, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, null, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle()); assertEquals("NT1", topics.getPage().get(0).getTitle());
// Find by user and tag together // Find by user and tag together
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, TAG_1, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), ADMIN_USER, TAG_1, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, TAG_1, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(DISCUSSION_SITE.getShortName(), TEST_USER, TAG_1, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle()); assertEquals("ST2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, TAG_2, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, TAG_2, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("NT2", topics.getPage().get(0).getTitle()); assertEquals("NT2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, TAG_2, new PagingRequest(10)); topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, TEST_USER, TAG_2, true, new PagingRequest(10));
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
// Do a find to check the ordering alters as requested
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size());
assertEquals("NT2", topics.getPage().get(0).getTitle());
assertEquals("NT3", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.findTopics(FORUM_NODE, ADMIN_USER, null, false, new PagingRequest(10));
assertEquals(2, topics.getPage().size());
assertEquals("NT3", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle());
// Alter the creation date on a couple, see the ordering change // Alter the creation date on a couple, see the ordering change
pushAuditableDatesBack(siteT2, 2, 2); pushAuditableDatesBack(siteT2, 2, 2);
pushAuditableDatesBack(nodeT3, 3, 3); pushAuditableDatesBack(nodeT3, 3, 3);
pushAuditableDatesBack(nodeT1, 1, 1); pushAuditableDatesBack(nodeT1, 1, 1);
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle()); assertEquals("ST2", topics.getPage().get(0).getTitle());
assertEquals("ST1", topics.getPage().get(1).getTitle()); assertEquals("ST1", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, new PagingRequest(10));
assertEquals(3, topics.getPage().size()); assertEquals(3, topics.getPage().size());
assertEquals("NT3", topics.getPage().get(0).getTitle()); assertEquals("NT3", topics.getPage().get(0).getTitle());
assertEquals("NT1", topics.getPage().get(1).getTitle()); assertEquals("NT1", topics.getPage().get(1).getTitle());
@@ -729,20 +783,20 @@ public class DiscussionServiceImplTest
// Try listing by date range // Try listing by date range
// Only Site1 and Node2 are still created today, Node1 was a day ago // 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)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), yesterday, tomorrow, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST1", topics.getPage().get(0).getTitle()); assertEquals("ST1", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, yesterday, tomorrow, true, new PagingRequest(10));
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
assertEquals("NT1", topics.getPage().get(0).getTitle()); assertEquals("NT1", topics.getPage().get(0).getTitle());
assertEquals("NT2", topics.getPage().get(1).getTitle()); assertEquals("NT2", topics.getPage().get(1).getTitle());
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, yesterday, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), fourDaysAgo, yesterday, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("ST2", topics.getPage().get(0).getTitle()); assertEquals("ST2", topics.getPage().get(0).getTitle());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, fourDaysAgo, yesterday, new PagingRequest(10)); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, fourDaysAgo, yesterday, true, new PagingRequest(10));
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
assertEquals("NT3", topics.getPage().get(0).getTitle()); assertEquals("NT3", topics.getPage().get(0).getTitle());
@@ -1397,11 +1451,11 @@ public class DiscussionServiceImplTest
PagingResults<PostInfo> posts; PagingResults<PostInfo> posts;
// Nothing to start with in either site or on the node // Nothing to start with in either site or on the node
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, paging); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, paging);
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
// Double check that we're only allowed to see the 1st site // Double check that we're only allowed to see the 1st site
@@ -1452,11 +1506,11 @@ public class DiscussionServiceImplTest
testNodesToTidy.add(topicNB.getNodeRef()); testNodesToTidy.add(topicNB.getNodeRef());
// Check again, as we're not in the 2nd site won't see any there // Check again, as we're not in the 2nd site won't see any there
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, paging); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
@@ -1473,11 +1527,11 @@ public class DiscussionServiceImplTest
} }
}); });
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(3, topics.getPage().size()); assertEquals(3, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, paging); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
@@ -1488,11 +1542,11 @@ public class DiscussionServiceImplTest
PERMISSION_SERVICE.setInheritParentPermissions(topicNB.getNodeRef(), false); PERMISSION_SERVICE.setInheritParentPermissions(topicNB.getNodeRef(), false);
PERMISSION_SERVICE.clearPermission(topicNB.getNodeRef(), TEST_USER); PERMISSION_SERVICE.clearPermission(topicNB.getNodeRef(), TEST_USER);
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, paging); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, paging);
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
@@ -1569,28 +1623,28 @@ public class DiscussionServiceImplTest
} }
}); });
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(2, topics.getPage().size()); assertEquals(2, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), true, paging);
assertEquals(0, topics.getPage().size()); assertEquals(0, topics.getPage().size());
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, paging); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, paging);
assertEquals(1, topics.getPage().size()); assertEquals(1, topics.getPage().size());
// Tidy // Tidy
paging = new PagingRequest(10); paging = new PagingRequest(10);
AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER); AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), true, paging);
for(TopicInfo topic : topics.getPage()) for(TopicInfo topic : topics.getPage())
{ {
PUBLIC_NODE_SERVICE.deleteNode(topic.getNodeRef()); PUBLIC_NODE_SERVICE.deleteNode(topic.getNodeRef());
} }
topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), paging); topics = DISCUSSION_SERVICE.listTopics(ALTERNATE_DISCUSSION_SITE.getShortName(), true, paging);
for(TopicInfo topic : topics.getPage()) for(TopicInfo topic : topics.getPage())
{ {
PUBLIC_NODE_SERVICE.deleteNode(topic.getNodeRef()); PUBLIC_NODE_SERVICE.deleteNode(topic.getNodeRef());
} }
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, paging); topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, true, paging);
for(TopicInfo topic : topics.getPage()) for(TopicInfo topic : topics.getPage())
{ {
PUBLIC_NODE_SERVICE.deleteNode(topic.getNodeRef()); PUBLIC_NODE_SERVICE.deleteNode(topic.getNodeRef());

View File

@@ -155,54 +155,60 @@ public interface DiscussionService {
/** /**
* Retrieves all topics in a site * Retrieves all topics in a site, sorted by either oldest
* or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> listTopics(String siteShortName, PagingRequest paging); PagingResults<TopicInfo> listTopics(String siteShortName, boolean sortAscending, PagingRequest paging);
/** /**
* Retrieves all topics attached to the specified Node * Retrieves all topics attached to the specified Node, sorted by
* either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> listTopics(NodeRef nodeRef, PagingRequest paging); PagingResults<TopicInfo> listTopics(NodeRef nodeRef, boolean sortAscending, PagingRequest paging);
/** /**
* Retrieves all topics in a site, filtered by username * Retrieves all topics in a site, filtered by username, sorted by
* either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> listTopics(String siteShortName, String username, PagingRequest paging); PagingResults<TopicInfo> listTopics(String siteShortName, String username, boolean sortAscending, PagingRequest paging);
/** /**
* Retrieves all topics attached to the specified Node, filtered by username * Retrieves all topics attached to the specified Node, filtered by username,
* sorted by either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> listTopics(NodeRef nodeRef, String username, PagingRequest paging); PagingResults<TopicInfo> listTopics(NodeRef nodeRef, String username, boolean sortAscending, PagingRequest paging);
/** /**
* Retrieves all topics in a site, created in the given date range * Retrieves all topics in a site, created in the given date range, sorted by
* either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> listTopics(String siteShortName, Date from, Date to, PagingRequest paging); PagingResults<TopicInfo> listTopics(String siteShortName, Date from, Date to, boolean sortAscending, PagingRequest paging);
/** /**
* Retrieves all topics attached to the specified Node, created in the * Retrieves all topics attached to the specified Node, created in the
* given date range * given date range, sorted by either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> listTopics(NodeRef nodeRef, Date from, Date to, PagingRequest paging); PagingResults<TopicInfo> listTopics(NodeRef nodeRef, Date from, Date to, boolean sortAscending, PagingRequest paging);
/** /**
* Searches for all topics in a site, filtered by username or tag * Searches for all topics in a site, filtered by username or tag, sorted by
* either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> findTopics(String siteShortName, String username, String tag, PagingRequest paging); PagingResults<TopicInfo> findTopics(String siteShortName, String username, String tag, boolean sortAscending, PagingRequest paging);
/** /**
* Searches for all topics attached to the specified Node, filtered * Searches for all topics attached to the specified Node, filtered
* by username or tag * by username or tag, sorted by either oldest or newest topics first.
*/ */
@NotAuditable @NotAuditable
PagingResults<TopicInfo> findTopics(NodeRef nodeRef, String username, String tag, PagingRequest paging); PagingResults<TopicInfo> findTopics(NodeRef nodeRef, String username, String tag, boolean sortAscending, PagingRequest paging);
/** /**