mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9153 Add discussions Topic Listing and Posts-in-Topic Listing via CQ, plus tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29724 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
<property name="taggingService" ref="TaggingService"/>
|
||||
<property name="fileFolderService" ref="FileFolderService"/>
|
||||
<property name="transactionService" ref="transactionService" />
|
||||
<property name="cannedQueryRegistry" ref="wikiCannedQueryRegistry" />
|
||||
<property name="cannedQueryRegistry" ref="discussionCannedQueryRegistry" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -25,7 +25,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.query.CannedQueryFactory;
|
||||
@@ -42,7 +41,6 @@ import org.alfresco.service.cmr.discussion.DiscussionService;
|
||||
import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
@@ -51,8 +49,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.Pair;
|
||||
@@ -431,72 +427,6 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
}
|
||||
|
||||
|
||||
public PagingResults<WikiPageInfo> listWikiPages(String siteShortName, String username,
|
||||
Date createdFrom, Date createdTo, Date modifiedFrom, Date modifiedTo, PagingRequest paging)
|
||||
{
|
||||
NodeRef container = getSiteDiscussionsContainer(siteShortName, false);
|
||||
if(container == null)
|
||||
{
|
||||
// No events
|
||||
return new EmptyPagingResults<WikiPageInfo>();
|
||||
}
|
||||
|
||||
// Grab the factory
|
||||
GetChildrenAuditableCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenAuditableCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
|
||||
|
||||
// Do the sorting, newest first by created date
|
||||
CannedQuerySortDetails sorting = getChildrenCannedQueryFactory.createDateDescendingCQSortDetails();
|
||||
|
||||
// Run the canned query
|
||||
GetChildrenAuditableCannedQuery cq = (GetChildrenAuditableCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
|
||||
container, ContentModel.TYPE_CONTENT, username, createdFrom, createdTo, null,
|
||||
modifiedFrom, modifiedTo, sorting, paging);
|
||||
|
||||
// Execute the canned query
|
||||
CannedQueryResults<NodeBackedEntity> results = cq.execute();
|
||||
|
||||
// Convert to Link objects
|
||||
return wrap(results, container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Our class to wrap up paged results of NodeBackedEntities as
|
||||
* WikiPageInfo instances
|
||||
*/
|
||||
private PagingResults<WikiPageInfo> wrap(final PagingResults<NodeBackedEntity> results, final NodeRef container)
|
||||
{
|
||||
return new PagingResults<WikiPageInfo>()
|
||||
{
|
||||
@Override
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return results.getQueryExecutionId();
|
||||
}
|
||||
@Override
|
||||
public List<WikiPageInfo> getPage()
|
||||
{
|
||||
List<WikiPageInfo> pages = new ArrayList<WikiPageInfo>();
|
||||
for(NodeBackedEntity node : results.getPage())
|
||||
{
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
String name = node.getName();
|
||||
//pages.add(buildPage(nodeRef, container, name, null));
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
return results.hasMoreItems();
|
||||
}
|
||||
@Override
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
return results.getTotalResultCount();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public PostInfo getPrimaryPost(TopicInfo topic) {
|
||||
// First up, see if there is a post with the same name as the topic
|
||||
@@ -539,15 +469,23 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
@Override
|
||||
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
|
||||
PagingRequest paging) {
|
||||
// TODO
|
||||
return new EmptyPagingResults<TopicInfo>();
|
||||
// Do the listing
|
||||
CannedQueryResults<NodeBackedEntity> nodes =
|
||||
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, paging);
|
||||
|
||||
// Wrap and return
|
||||
return wrap(nodes, nodeRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<PostInfo> listPosts(TopicInfo topic, PagingRequest paging)
|
||||
{
|
||||
// TODO
|
||||
return new EmptyPagingResults<PostInfo>();
|
||||
// Do the listing
|
||||
CannedQueryResults<NodeBackedEntity> nodes =
|
||||
listEntries(topic.getNodeRef(), ForumModel.TYPE_POST, null, paging);
|
||||
|
||||
// Wrap and return
|
||||
return wrap(nodes, topic);
|
||||
}
|
||||
|
||||
|
||||
@@ -578,4 +516,105 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds nodes in the specified parent container, with the given
|
||||
* type, optionally filtered by creator
|
||||
*/
|
||||
private CannedQueryResults<NodeBackedEntity> listEntries(NodeRef parent,
|
||||
QName nodeType, String creatorUsername, PagingRequest paging)
|
||||
{
|
||||
// Grab the factory
|
||||
GetChildrenAuditableCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenAuditableCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
|
||||
|
||||
// Do the sorting, newest first by created date
|
||||
CannedQuerySortDetails sorting = getChildrenCannedQueryFactory.createDateAscendingCQSortDetails();
|
||||
|
||||
// Run the canned query
|
||||
GetChildrenAuditableCannedQuery cq = (GetChildrenAuditableCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
|
||||
parent, nodeType, creatorUsername, null, null, null,
|
||||
null, null, sorting, paging);
|
||||
|
||||
// Execute the canned query
|
||||
CannedQueryResults<NodeBackedEntity> results = cq.execute();
|
||||
|
||||
// Return for wrapping
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our class to wrap up paged results of NodeBackedEntities as
|
||||
* {@link TopicInfo} instances
|
||||
*/
|
||||
private PagingResults<TopicInfo> wrap(final PagingResults<NodeBackedEntity> results, final NodeRef container)
|
||||
{
|
||||
return new PagingResults<TopicInfo>()
|
||||
{
|
||||
@Override
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return results.getQueryExecutionId();
|
||||
}
|
||||
@Override
|
||||
public List<TopicInfo> getPage()
|
||||
{
|
||||
List<TopicInfo> topics = new ArrayList<TopicInfo>();
|
||||
for(NodeBackedEntity node : results.getPage())
|
||||
{
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
String name = node.getName();
|
||||
topics.add(buildTopic(nodeRef, container, name));
|
||||
}
|
||||
return topics;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
return results.hasMoreItems();
|
||||
}
|
||||
@Override
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
return results.getTotalResultCount();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Our class to wrap up paged results of NodeBackedEntities as
|
||||
* {@link PostInfo} instances
|
||||
*/
|
||||
private PagingResults<PostInfo> wrap(final PagingResults<NodeBackedEntity> results, final TopicInfo topic)
|
||||
{
|
||||
return new PagingResults<PostInfo>()
|
||||
{
|
||||
@Override
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return results.getQueryExecutionId();
|
||||
}
|
||||
@Override
|
||||
public List<PostInfo> getPage()
|
||||
{
|
||||
List<PostInfo> posts = new ArrayList<PostInfo>();
|
||||
for(NodeBackedEntity node : results.getPage())
|
||||
{
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
String name = node.getName();
|
||||
posts.add(buildPost(nodeRef, topic, name, null));
|
||||
}
|
||||
return posts;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
return results.hasMoreItems();
|
||||
}
|
||||
@Override
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
return results.getTotalResultCount();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -228,6 +228,9 @@ public class DiscussionServiceImplTest
|
||||
siteTopic = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "Site Title");
|
||||
nodeTopic = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "Node Title");
|
||||
|
||||
testNodesToTidy.add(siteTopic.getNodeRef());
|
||||
testNodesToTidy.add(nodeTopic.getNodeRef());
|
||||
|
||||
|
||||
// Check these actions in turn
|
||||
for(TopicInfo topic : new TopicInfo[] {siteTopic, nodeTopic})
|
||||
@@ -288,7 +291,7 @@ public class DiscussionServiceImplTest
|
||||
|
||||
// Topic will now have one post listed
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
//assertEquals(1, posts.getPage().size()); // TODO Fix
|
||||
assertEquals(1, posts.getPage().size());
|
||||
|
||||
|
||||
// Add a reply
|
||||
@@ -335,99 +338,287 @@ public class DiscussionServiceImplTest
|
||||
|
||||
// Check the overall count now
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
//assertEquals(3, posts.getPage().size()); // TODO Fix
|
||||
assertEquals(3, posts.getPage().size());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@Test public void createUpdateDeleteEntries() throws Exception
|
||||
{
|
||||
WikiPageInfo page;
|
||||
TopicInfo siteTopic;
|
||||
TopicInfo nodeTopic;
|
||||
PostInfo post;
|
||||
PostInfo reply;
|
||||
|
||||
// Run as the test user instead
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
|
||||
|
||||
|
||||
// Create a page
|
||||
page = DISCUSSION_SERVICE.createWikiPage(
|
||||
DISCUSSION_SITE.getShortName(), "Title", "This Is Some Content"
|
||||
);
|
||||
testNodesToTidy.add(page.getNodeRef());
|
||||
// Create two topics
|
||||
siteTopic = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "Site Title");
|
||||
nodeTopic = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "Node Title");
|
||||
testNodesToTidy.add(siteTopic.getNodeRef());
|
||||
testNodesToTidy.add(nodeTopic.getNodeRef());
|
||||
|
||||
|
||||
// Check it
|
||||
assertEquals("Title", page.getSystemName());
|
||||
assertEquals("Title", page.getTitle());
|
||||
assertEquals("This Is Some Content", page.getContents());
|
||||
assertEquals(TEST_USER, page.getCreator());
|
||||
assertEquals(0, page.getTags().size());
|
||||
// Check them
|
||||
assertEquals("Site Title", siteTopic.getTitle());
|
||||
assertEquals(TEST_USER, siteTopic.getCreator());
|
||||
assertEquals(0, siteTopic.getTags().size());
|
||||
|
||||
assertEquals("Node Title", nodeTopic.getTitle());
|
||||
assertEquals(TEST_USER, nodeTopic.getCreator());
|
||||
assertEquals(0, nodeTopic.getTags().size());
|
||||
|
||||
|
||||
// Change it
|
||||
page.setTitle("New Title");
|
||||
page.setContents("This is new content");
|
||||
// Change them
|
||||
siteTopic.setTitle("Site Changed");
|
||||
nodeTopic.setTitle("Node Changed");
|
||||
|
||||
page = DISCUSSION_SERVICE.updateWikiPage(page);
|
||||
assertEquals("New_Title", page.getSystemName()); // Name has underscores
|
||||
assertEquals("New Title", page.getTitle());
|
||||
siteTopic = DISCUSSION_SERVICE.updateTopic(siteTopic);
|
||||
nodeTopic = DISCUSSION_SERVICE.updateTopic(nodeTopic);
|
||||
|
||||
|
||||
// Fetch, and check
|
||||
page = DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName());
|
||||
assertEquals("New_Title", page.getSystemName()); // Name has underscores
|
||||
assertEquals("New Title", page.getTitle());
|
||||
assertEquals("This is new content", page.getContents());
|
||||
assertEquals(TEST_USER, page.getCreator());
|
||||
assertEquals(0, page.getTags().size());
|
||||
siteTopic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), siteTopic.getSystemName());
|
||||
nodeTopic = DISCUSSION_SERVICE.getTopic(FORUM_NODE, nodeTopic.getSystemName());
|
||||
|
||||
assertEquals("Site Changed", siteTopic.getTitle());
|
||||
assertEquals(TEST_USER, siteTopic.getCreator());
|
||||
assertEquals(0, siteTopic.getTags().size());
|
||||
|
||||
assertEquals("Node Changed", nodeTopic.getTitle());
|
||||
assertEquals(TEST_USER, nodeTopic.getCreator());
|
||||
assertEquals(0, nodeTopic.getTags().size());
|
||||
|
||||
|
||||
// Delete it
|
||||
DISCUSSION_SERVICE.deleteWikiPage(page);
|
||||
// For each, create and edit some posts
|
||||
for(TopicInfo topic : new TopicInfo[] {siteTopic, nodeTopic})
|
||||
{
|
||||
// Create a post and a reply
|
||||
String contents = "This Is Some Content";
|
||||
post = DISCUSSION_SERVICE.createPost(topic, contents);
|
||||
|
||||
// Check it went
|
||||
assertEquals(null, DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName()));
|
||||
String replyContents = "Reply Contents";
|
||||
reply = DISCUSSION_SERVICE.createReply(post, replyContents);
|
||||
|
||||
|
||||
// Create a new node with spaces in title
|
||||
page = DISCUSSION_SERVICE.createWikiPage(
|
||||
DISCUSSION_SITE.getShortName(), "Title Space", "This Is Some Content"
|
||||
);
|
||||
testNodesToTidy.add(page.getNodeRef());
|
||||
// Check them
|
||||
assertEquals(topic.getTitle(), post.getTitle());
|
||||
assertEquals(contents, post.getContents());
|
||||
|
||||
// Check it
|
||||
assertEquals("Title_Space", page.getSystemName());
|
||||
assertEquals("Title Space", page.getTitle());
|
||||
assertEquals("This Is Some Content", page.getContents());
|
||||
assertEquals(TEST_USER, page.getCreator());
|
||||
assertEquals(0, page.getTags().size());
|
||||
assertEquals(null, reply.getTitle());
|
||||
assertEquals(replyContents, reply.getContents());
|
||||
|
||||
|
||||
// Edit it without renaming
|
||||
page.setContents("Changed contents");
|
||||
page = DISCUSSION_SERVICE.updateWikiPage(page);
|
||||
// Fetch and re-check
|
||||
post = DISCUSSION_SERVICE.getPost(topic, post.getSystemName());
|
||||
reply = DISCUSSION_SERVICE.getPost(topic, reply.getSystemName());
|
||||
|
||||
// Check
|
||||
page = DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName());
|
||||
assertEquals("Title_Space", page.getSystemName());
|
||||
assertEquals("Title Space", page.getTitle());
|
||||
assertEquals("Changed contents", page.getContents());
|
||||
assertEquals(TEST_USER, page.getCreator());
|
||||
assertEquals(0, page.getTags().size());
|
||||
assertEquals(topic.getTitle(), post.getTitle());
|
||||
assertEquals(contents, post.getContents());
|
||||
|
||||
assertEquals(null, reply.getTitle());
|
||||
assertEquals(replyContents, reply.getContents());
|
||||
|
||||
|
||||
// Now edit with renaming
|
||||
page.setTitle("Alternate Title");
|
||||
page = DISCUSSION_SERVICE.updateWikiPage(page);
|
||||
// Edit them
|
||||
String pTitle = "Title on the Post";
|
||||
String rTitle = "Title on the Reply";
|
||||
String pContents = "Changed! Changed!";
|
||||
String rContents = "Reply was changed...";
|
||||
post.setTitle(pTitle);
|
||||
post.setContents(pContents);
|
||||
reply.setTitle(rTitle);
|
||||
reply.setContents(rContents);
|
||||
|
||||
// Check
|
||||
page = DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName());
|
||||
assertEquals("Alternate_Title", page.getSystemName());
|
||||
assertEquals("Alternate Title", page.getTitle());
|
||||
assertEquals("Changed contents", page.getContents());
|
||||
assertEquals(TEST_USER, page.getCreator());
|
||||
assertEquals(0, page.getTags().size());
|
||||
post = DISCUSSION_SERVICE.updatePost(post);
|
||||
reply = DISCUSSION_SERVICE.updatePost(reply);
|
||||
|
||||
assertEquals(pTitle, post.getTitle());
|
||||
assertEquals(pContents, post.getContents());
|
||||
|
||||
assertEquals(rTitle, reply.getTitle());
|
||||
assertEquals(rContents, reply.getContents());
|
||||
|
||||
|
||||
// Check the changes were taken
|
||||
post = DISCUSSION_SERVICE.getPost(topic, post.getSystemName());
|
||||
reply = DISCUSSION_SERVICE.getPost(topic, reply.getSystemName());
|
||||
|
||||
assertEquals(pTitle, post.getTitle());
|
||||
assertEquals(pContents, post.getContents());
|
||||
|
||||
assertEquals(rTitle, reply.getTitle());
|
||||
assertEquals(rContents, reply.getContents());
|
||||
|
||||
|
||||
// Remove the title from the topic manually
|
||||
String oldTitle = topic.getTitle();
|
||||
PUBLIC_NODE_SERVICE.setProperty(topic.getNodeRef(), ContentModel.PROP_TITLE, null);
|
||||
|
||||
// Check that we pick it up from the primary post instead
|
||||
// (That's the pre-swift Share fallback case)
|
||||
assertEquals(oldTitle, topic.getTitle());
|
||||
topic = DISCUSSION_SERVICE.getTopic(topic.getContainerNodeRef(), topic.getSystemName());
|
||||
assertEquals(pTitle, topic.getTitle());
|
||||
|
||||
|
||||
// Delete the reply and the post
|
||||
DISCUSSION_SERVICE.deletePost(reply);
|
||||
DISCUSSION_SERVICE.deletePost(post);
|
||||
|
||||
// Check they went
|
||||
post = DISCUSSION_SERVICE.getPost(topic, post.getSystemName());
|
||||
reply = DISCUSSION_SERVICE.getPost(topic, reply.getSystemName());
|
||||
|
||||
assertEquals(null, post);
|
||||
assertEquals(null, reply);
|
||||
}
|
||||
|
||||
// Delete the topics
|
||||
DISCUSSION_SERVICE.deleteTopic(siteTopic);
|
||||
DISCUSSION_SERVICE.deleteTopic(nodeTopic);
|
||||
|
||||
// Check they went
|
||||
siteTopic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), siteTopic.getSystemName());
|
||||
nodeTopic = DISCUSSION_SERVICE.getTopic(FORUM_NODE, nodeTopic.getSystemName());
|
||||
assertEquals(null, siteTopic);
|
||||
assertEquals(null, nodeTopic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests listing of topics in a site/node, and posts in a topic
|
||||
*/
|
||||
@Test public void basicListings() throws Exception
|
||||
{
|
||||
PagingResults<TopicInfo> topics;
|
||||
PagingResults<PostInfo> posts;
|
||||
|
||||
|
||||
// To start with, there will be no topics
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10));
|
||||
assertEquals(0, topics.getPage().size());
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10));
|
||||
assertEquals(0, topics.getPage().size());
|
||||
|
||||
|
||||
// Create several
|
||||
TopicInfo siteT1 = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "ST1");
|
||||
TopicInfo siteT2 = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "ST2");
|
||||
TopicInfo nodeT1 = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "NT1");
|
||||
TopicInfo nodeT2 = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "NT2");
|
||||
TopicInfo nodeT3 = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "NT3");
|
||||
testNodesToTidy.add(siteT1.getNodeRef());
|
||||
testNodesToTidy.add(siteT2.getNodeRef());
|
||||
testNodesToTidy.add(nodeT1.getNodeRef());
|
||||
testNodesToTidy.add(nodeT2.getNodeRef());
|
||||
testNodesToTidy.add(nodeT3.getNodeRef());
|
||||
|
||||
|
||||
// Check now, will order by creation date
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), 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, 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());
|
||||
|
||||
|
||||
// Alter the creation date on a couple, see the ordering change
|
||||
pushAuditableDatesBack(siteT2, 2, 2);
|
||||
pushAuditableDatesBack(nodeT3, 3, 3);
|
||||
pushAuditableDatesBack(nodeT1, 1, 1);
|
||||
|
||||
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), 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, new PagingRequest(10));
|
||||
assertEquals(3, topics.getPage().size());
|
||||
assertEquals("NT3", topics.getPage().get(0).getTitle());
|
||||
assertEquals("NT1", topics.getPage().get(1).getTitle());
|
||||
assertEquals("NT2", topics.getPage().get(2).getTitle());
|
||||
|
||||
|
||||
// Now create a couple of check posts
|
||||
PostInfo siteCP1 = DISCUSSION_SERVICE.createPost(siteT2, "Check");
|
||||
PostInfo nodeCP1 = DISCUSSION_SERVICE.createPost(nodeT2, "Check");
|
||||
testNodesToTidy.add(siteCP1.getNodeRef());
|
||||
testNodesToTidy.add(nodeCP1.getNodeRef());
|
||||
|
||||
|
||||
// For both site and node based topics, check adding and
|
||||
// removing posts correctly affects counts
|
||||
for(TopicInfo topic : new TopicInfo[] {siteT1, nodeT1})
|
||||
{
|
||||
// None to start with
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(0, posts.getPage().size());
|
||||
|
||||
// Create one post
|
||||
PostInfo post = DISCUSSION_SERVICE.createPost(topic, "Post");
|
||||
assertEquals(post.getNodeRef(), DISCUSSION_SERVICE.getPrimaryPost(topic).getNodeRef());
|
||||
|
||||
// Check the count
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(1, posts.getPage().size());
|
||||
assertEquals("Post", posts.getPage().get(0).getContents());
|
||||
|
||||
// Add two replies
|
||||
PostInfo reply1 = DISCUSSION_SERVICE.createReply(post, "R1");
|
||||
PostInfo reply2 = DISCUSSION_SERVICE.createReply(post, "R2");
|
||||
|
||||
// Check
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(3, posts.getPage().size());
|
||||
assertEquals("Post", posts.getPage().get(0).getContents());
|
||||
assertEquals("R1", posts.getPage().get(1).getContents());
|
||||
assertEquals("R2", posts.getPage().get(2).getContents());
|
||||
|
||||
|
||||
// Alter the date of one, order changes
|
||||
pushAuditableDatesBack(reply1, -1, -1);
|
||||
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(3, posts.getPage().size());
|
||||
assertEquals("Post", posts.getPage().get(0).getContents());
|
||||
assertEquals("R2", posts.getPage().get(1).getContents());
|
||||
assertEquals("R1", posts.getPage().get(2).getContents());
|
||||
|
||||
|
||||
// Delete one reply
|
||||
DISCUSSION_SERVICE.deletePost(reply1);
|
||||
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(2, posts.getPage().size());
|
||||
assertEquals("Post", posts.getPage().get(0).getContents());
|
||||
assertEquals("R2", posts.getPage().get(1).getContents());
|
||||
|
||||
|
||||
// Delete the main post
|
||||
DISCUSSION_SERVICE.deletePost(post);
|
||||
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(1, posts.getPage().size());
|
||||
assertEquals("R2", posts.getPage().get(0).getContents());
|
||||
|
||||
|
||||
// Check the last reply now counts as the "primary"
|
||||
assertEquals(reply2.getNodeRef(), DISCUSSION_SERVICE.getPrimaryPost(topic).getNodeRef());
|
||||
|
||||
|
||||
// Zap the last one
|
||||
DISCUSSION_SERVICE.deletePost(reply2);
|
||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||
assertEquals(0, posts.getPage().size());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensures that when we try to write an entry to the
|
||||
@@ -838,13 +1029,30 @@ public class DiscussionServiceImplTest
|
||||
/**
|
||||
* Alters the created date on a wiki page for testing
|
||||
*/
|
||||
private void pushAuditableDatesBack(WikiPageInfo page, int createdDaysAgo, int modifiedDaysAgo) throws Exception
|
||||
private void pushAuditableDatesBack(final Object thing, final int createdDaysAgo, final int modifiedDaysAgo) throws Exception
|
||||
{
|
||||
final NodeRef node = page.getNodeRef();
|
||||
NodeRef tmpNodeRef;
|
||||
if(thing instanceof NodeRef)
|
||||
{
|
||||
tmpNodeRef = (NodeRef)thing;
|
||||
}
|
||||
else if(thing instanceof TopicInfo)
|
||||
{
|
||||
tmpNodeRef = ((TopicInfo)thing).getNodeRef();
|
||||
}
|
||||
else if(thing instanceof PostInfo)
|
||||
{
|
||||
tmpNodeRef = ((PostInfo)thing).getNodeRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("Unknown thing " + thing);
|
||||
}
|
||||
final NodeRef node = tmpNodeRef;
|
||||
|
||||
final Date created = page.getCreatedAt();
|
||||
final Date created = (Date)PUBLIC_NODE_SERVICE.getProperty(node, ContentModel.PROP_CREATED);
|
||||
final Date newCreated = new Date(created.getTime() - createdDaysAgo*ONE_DAY_MS);
|
||||
final Date modified = page.getModifiedAt();
|
||||
final Date modified = (Date)PUBLIC_NODE_SERVICE.getProperty(node, ContentModel.PROP_MODIFIED);
|
||||
final Date newModified = new Date(modified.getTime() - modifiedDaysAgo*ONE_DAY_MS);
|
||||
|
||||
// Update the created date
|
||||
@@ -881,8 +1089,16 @@ public class DiscussionServiceImplTest
|
||||
}, false, true);
|
||||
|
||||
// Update the object itself
|
||||
((TopicInfoImpl)page).setCreatedAt(newCreated);
|
||||
((TopicInfoImpl)page).setModifiedAt(newModified);
|
||||
if(thing instanceof TopicInfo)
|
||||
{
|
||||
((TopicInfoImpl)thing).setCreatedAt(newCreated);
|
||||
((TopicInfoImpl)thing).setModifiedAt(newModified);
|
||||
}
|
||||
if(thing instanceof PostInfo)
|
||||
{
|
||||
((PostInfoImpl)thing).setCreatedAt(newCreated);
|
||||
((PostInfoImpl)thing).setModifiedAt(newModified);
|
||||
}
|
||||
}
|
||||
|
||||
private static void createTestSites() throws Exception
|
||||
|
Reference in New Issue
Block a user