ALF-2166 Update the discussions webscripts for control of the ordering, and switch the "Recent Topics" listing to request newest topics first

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30201 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-09-02 15:30:24 +00:00
parent f8d413d5a0
commit 28b7e033d9
4 changed files with 24 additions and 23 deletions

View File

@@ -1008,26 +1008,26 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
// Check for recent (new)
// We should get all the topics
// We should get all the topics, with the newest one first (rather than last as with others)
result = getPosts("new?numdays=2", Status.STATUS_OK);
assertEquals(2, result.getInt("total"));
assertEquals(2, result.getInt("itemCount"));
assertEquals(2, result.getJSONArray("items").length());
assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
assertEquals(2, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
assertEquals(3, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
assertEquals("SiteTitle2", result.getJSONArray("items").getJSONObject(0).getString("title"));
assertEquals("SiteTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
assertEquals(3, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
assertEquals(2, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
result = getPosts(FORUM_NODE, "new?numdays=2", Status.STATUS_OK);
assertEquals(3, result.getInt("total"));
assertEquals(3, result.getInt("itemCount"));
assertEquals(3, result.getJSONArray("items").length());
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
assertEquals("NodeTitle2", result.getJSONArray("items").getJSONObject(1).getString("title"));
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(2).getString("title"));
assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
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"));
assertEquals(0, result.getJSONArray("items").getJSONObject(2).getInt("replyCount"));
assertEquals(1, result.getJSONArray("items").getJSONObject(2).getInt("replyCount"));
// Check for hot
@@ -1093,10 +1093,10 @@ public class DiscussionRestApiTest extends BaseWebScriptTest
assertEquals(2, result.getInt("total"));
assertEquals(2, result.getInt("itemCount"));
assertEquals(2, result.getJSONArray("items").length());
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(0).getString("title"));
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(1).getString("title"));
assertEquals(0, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
assertEquals(1, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
assertEquals("NodeTitle1", result.getJSONArray("items").getJSONObject(0).getString("title"));
assertEquals("NodeTitle3", result.getJSONArray("items").getJSONObject(1).getString("title"));
assertEquals(1, result.getJSONArray("items").getJSONObject(0).getInt("replyCount"));
assertEquals(0, result.getJSONArray("items").getJSONObject(1).getInt("replyCount"));
result = getPosts(FORUM_NODE, "new?numdays=2", Status.STATUS_OK);
assertEquals(1, result.getInt("total"));

View File

@@ -61,6 +61,7 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
}
// Get the topics
boolean oldestTopicsFirst = true;
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if(tagSearch)
@@ -68,22 +69,22 @@ public class ForumTopicsGet extends AbstractDiscussionWebScript
// Tag based is a search rather than a listing
if(site != null)
{
topics = discussionService.findTopics(site.getShortName(), null, tag, paging);
topics = discussionService.findTopics(site.getShortName(), null, tag, oldestTopicsFirst, paging);
}
else
{
topics = discussionService.findTopics(nodeRef, null, tag, paging);
topics = discussionService.findTopics(nodeRef, null, tag, oldestTopicsFirst, paging);
}
}
else
{
if(site != null)
{
topics = discussionService.listTopics(site.getShortName(), paging);
topics = discussionService.listTopics(site.getShortName(), oldestTopicsFirst, paging);
}
else
{
topics = discussionService.listTopics(nodeRef, buildPagingRequest(req));
topics = discussionService.listTopics(nodeRef, oldestTopicsFirst, buildPagingRequest(req));
}
}

View File

@@ -56,16 +56,16 @@ public class ForumTopicsMineGet extends AbstractDiscussionWebScript
// Grab the current user to list for
String username = AuthenticationUtil.getFullyAuthenticatedUser();
// Get the topics for the user
// Get the topics for the user, oldest first
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if(site != null)
{
topics = discussionService.listTopics(site.getShortName(), username, paging);
topics = discussionService.listTopics(site.getShortName(), username, true, paging);
}
else
{
topics = discussionService.listTopics(nodeRef, username, paging);
topics = discussionService.listTopics(nodeRef, username, true, paging);
}

View File

@@ -68,16 +68,16 @@ public class ForumTopicsRecentGet extends AbstractDiscussionWebScript
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
// Get the recent topics, newest first
PagingResults<TopicInfo> topics = null;
PagingRequest paging = buildPagingRequest(req);
if(site != null)
{
topics = discussionService.listTopics(site.getShortName(), from, to, paging);
topics = discussionService.listTopics(site.getShortName(), from, to, false, paging);
}
else
{
topics = discussionService.listTopics(nodeRef, from, to, paging);
topics = discussionService.listTopics(nodeRef, from, to, false, paging);
}