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="taggingService" ref="TaggingService"/>
|
||||||
<property name="fileFolderService" ref="FileFolderService"/>
|
<property name="fileFolderService" ref="FileFolderService"/>
|
||||||
<property name="transactionService" ref="transactionService" />
|
<property name="transactionService" ref="transactionService" />
|
||||||
<property name="cannedQueryRegistry" ref="wikiCannedQueryRegistry" />
|
<property name="cannedQueryRegistry" ref="discussionCannedQueryRegistry" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@@ -25,7 +25,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.ForumModel;
|
import org.alfresco.model.ForumModel;
|
||||||
import org.alfresco.query.CannedQueryFactory;
|
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.PostInfo;
|
||||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
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.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
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.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.site.SiteService;
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
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.namespace.QName;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
@@ -430,72 +426,6 @@ public class DiscussionServiceImpl implements DiscussionService
|
|||||||
nodeService.deleteNode(post.getNodeRef());
|
nodeService.deleteNode(post.getNodeRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public PostInfo getPrimaryPost(TopicInfo topic) {
|
public PostInfo getPrimaryPost(TopicInfo topic) {
|
||||||
@@ -539,15 +469,23 @@ public class DiscussionServiceImpl implements DiscussionService
|
|||||||
@Override
|
@Override
|
||||||
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
|
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
|
||||||
PagingRequest paging) {
|
PagingRequest paging) {
|
||||||
// TODO
|
// Do the listing
|
||||||
return new EmptyPagingResults<TopicInfo>();
|
CannedQueryResults<NodeBackedEntity> nodes =
|
||||||
|
listEntries(nodeRef, ForumModel.TYPE_TOPIC, null, paging);
|
||||||
|
|
||||||
|
// Wrap and return
|
||||||
|
return wrap(nodes, nodeRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PagingResults<PostInfo> listPosts(TopicInfo topic, PagingRequest paging)
|
public PagingResults<PostInfo> listPosts(TopicInfo topic, PagingRequest paging)
|
||||||
{
|
{
|
||||||
// TODO
|
// Do the listing
|
||||||
return new EmptyPagingResults<PostInfo>();
|
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
|
// TODO Auto-generated method stub
|
||||||
return null;
|
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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -227,6 +227,9 @@ public class DiscussionServiceImplTest
|
|||||||
// Create two topics, one node and one site based
|
// Create two topics, one node and one site based
|
||||||
siteTopic = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "Site Title");
|
siteTopic = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "Site Title");
|
||||||
nodeTopic = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "Node Title");
|
nodeTopic = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "Node Title");
|
||||||
|
|
||||||
|
testNodesToTidy.add(siteTopic.getNodeRef());
|
||||||
|
testNodesToTidy.add(nodeTopic.getNodeRef());
|
||||||
|
|
||||||
|
|
||||||
// Check these actions in turn
|
// Check these actions in turn
|
||||||
@@ -288,7 +291,7 @@ public class DiscussionServiceImplTest
|
|||||||
|
|
||||||
// Topic will now have one post listed
|
// Topic will now have one post listed
|
||||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||||
//assertEquals(1, posts.getPage().size()); // TODO Fix
|
assertEquals(1, posts.getPage().size());
|
||||||
|
|
||||||
|
|
||||||
// Add a reply
|
// Add a reply
|
||||||
@@ -335,99 +338,287 @@ public class DiscussionServiceImplTest
|
|||||||
|
|
||||||
// Check the overall count now
|
// Check the overall count now
|
||||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
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
|
@Test public void createUpdateDeleteEntries() throws Exception
|
||||||
{
|
{
|
||||||
WikiPageInfo page;
|
TopicInfo siteTopic;
|
||||||
|
TopicInfo nodeTopic;
|
||||||
|
PostInfo post;
|
||||||
|
PostInfo reply;
|
||||||
|
|
||||||
// Run as the test user instead
|
// Run as the test user instead
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
|
AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
|
||||||
|
|
||||||
|
|
||||||
// Create a page
|
// Create two topics
|
||||||
page = DISCUSSION_SERVICE.createWikiPage(
|
siteTopic = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "Site Title");
|
||||||
DISCUSSION_SITE.getShortName(), "Title", "This Is Some Content"
|
nodeTopic = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "Node Title");
|
||||||
);
|
testNodesToTidy.add(siteTopic.getNodeRef());
|
||||||
testNodesToTidy.add(page.getNodeRef());
|
testNodesToTidy.add(nodeTopic.getNodeRef());
|
||||||
|
|
||||||
|
|
||||||
// Check it
|
// Check them
|
||||||
assertEquals("Title", page.getSystemName());
|
assertEquals("Site Title", siteTopic.getTitle());
|
||||||
assertEquals("Title", page.getTitle());
|
assertEquals(TEST_USER, siteTopic.getCreator());
|
||||||
assertEquals("This Is Some Content", page.getContents());
|
assertEquals(0, siteTopic.getTags().size());
|
||||||
assertEquals(TEST_USER, page.getCreator());
|
|
||||||
assertEquals(0, page.getTags().size());
|
assertEquals("Node Title", nodeTopic.getTitle());
|
||||||
|
assertEquals(TEST_USER, nodeTopic.getCreator());
|
||||||
|
assertEquals(0, nodeTopic.getTags().size());
|
||||||
|
|
||||||
|
|
||||||
// Change it
|
// Change them
|
||||||
page.setTitle("New Title");
|
siteTopic.setTitle("Site Changed");
|
||||||
page.setContents("This is new content");
|
nodeTopic.setTitle("Node Changed");
|
||||||
|
|
||||||
page = DISCUSSION_SERVICE.updateWikiPage(page);
|
siteTopic = DISCUSSION_SERVICE.updateTopic(siteTopic);
|
||||||
assertEquals("New_Title", page.getSystemName()); // Name has underscores
|
nodeTopic = DISCUSSION_SERVICE.updateTopic(nodeTopic);
|
||||||
assertEquals("New Title", page.getTitle());
|
|
||||||
|
|
||||||
|
|
||||||
// Fetch, and check
|
// Fetch, and check
|
||||||
page = DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName());
|
siteTopic = DISCUSSION_SERVICE.getTopic(DISCUSSION_SITE.getShortName(), siteTopic.getSystemName());
|
||||||
assertEquals("New_Title", page.getSystemName()); // Name has underscores
|
nodeTopic = DISCUSSION_SERVICE.getTopic(FORUM_NODE, nodeTopic.getSystemName());
|
||||||
assertEquals("New Title", page.getTitle());
|
|
||||||
assertEquals("This is new content", page.getContents());
|
assertEquals("Site Changed", siteTopic.getTitle());
|
||||||
assertEquals(TEST_USER, page.getCreator());
|
assertEquals(TEST_USER, siteTopic.getCreator());
|
||||||
assertEquals(0, page.getTags().size());
|
assertEquals(0, siteTopic.getTags().size());
|
||||||
|
|
||||||
|
assertEquals("Node Changed", nodeTopic.getTitle());
|
||||||
|
assertEquals(TEST_USER, nodeTopic.getCreator());
|
||||||
|
assertEquals(0, nodeTopic.getTags().size());
|
||||||
|
|
||||||
|
|
||||||
// Delete it
|
// For each, create and edit some posts
|
||||||
DISCUSSION_SERVICE.deleteWikiPage(page);
|
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);
|
||||||
|
|
||||||
|
String replyContents = "Reply Contents";
|
||||||
|
reply = DISCUSSION_SERVICE.createReply(post, replyContents);
|
||||||
|
|
||||||
|
|
||||||
|
// Check them
|
||||||
|
assertEquals(topic.getTitle(), post.getTitle());
|
||||||
|
assertEquals(contents, post.getContents());
|
||||||
|
|
||||||
|
assertEquals(null, reply.getTitle());
|
||||||
|
assertEquals(replyContents, reply.getContents());
|
||||||
|
|
||||||
|
|
||||||
|
// Fetch and re-check
|
||||||
|
post = DISCUSSION_SERVICE.getPost(topic, post.getSystemName());
|
||||||
|
reply = DISCUSSION_SERVICE.getPost(topic, reply.getSystemName());
|
||||||
|
|
||||||
|
assertEquals(topic.getTitle(), post.getTitle());
|
||||||
|
assertEquals(contents, post.getContents());
|
||||||
|
|
||||||
|
assertEquals(null, reply.getTitle());
|
||||||
|
assertEquals(replyContents, reply.getContents());
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
// Check it went
|
// Delete the topics
|
||||||
assertEquals(null, DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName()));
|
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;
|
||||||
|
|
||||||
|
|
||||||
// Create a new node with spaces in title
|
// To start with, there will be no topics
|
||||||
page = DISCUSSION_SERVICE.createWikiPage(
|
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10));
|
||||||
DISCUSSION_SITE.getShortName(), "Title Space", "This Is Some Content"
|
assertEquals(0, topics.getPage().size());
|
||||||
);
|
|
||||||
testNodesToTidy.add(page.getNodeRef());
|
|
||||||
|
|
||||||
// Check it
|
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10));
|
||||||
assertEquals("Title_Space", page.getSystemName());
|
assertEquals(0, topics.getPage().size());
|
||||||
assertEquals("Title Space", page.getTitle());
|
|
||||||
assertEquals("This Is Some Content", page.getContents());
|
|
||||||
assertEquals(TEST_USER, page.getCreator());
|
|
||||||
assertEquals(0, page.getTags().size());
|
|
||||||
|
|
||||||
|
|
||||||
// Edit it without renaming
|
// Create several
|
||||||
page.setContents("Changed contents");
|
TopicInfo siteT1 = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "ST1");
|
||||||
page = DISCUSSION_SERVICE.updateWikiPage(page);
|
TopicInfo siteT2 = DISCUSSION_SERVICE.createTopic(DISCUSSION_SITE.getShortName(), "ST2");
|
||||||
|
TopicInfo nodeT1 = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "NT1");
|
||||||
// Check
|
TopicInfo nodeT2 = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "NT2");
|
||||||
page = DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName());
|
TopicInfo nodeT3 = DISCUSSION_SERVICE.createTopic(FORUM_NODE, "NT3");
|
||||||
assertEquals("Title_Space", page.getSystemName());
|
testNodesToTidy.add(siteT1.getNodeRef());
|
||||||
assertEquals("Title Space", page.getTitle());
|
testNodesToTidy.add(siteT2.getNodeRef());
|
||||||
assertEquals("Changed contents", page.getContents());
|
testNodesToTidy.add(nodeT1.getNodeRef());
|
||||||
assertEquals(TEST_USER, page.getCreator());
|
testNodesToTidy.add(nodeT2.getNodeRef());
|
||||||
assertEquals(0, page.getTags().size());
|
testNodesToTidy.add(nodeT3.getNodeRef());
|
||||||
|
|
||||||
|
|
||||||
// Now edit with renaming
|
// Check now, will order by creation date
|
||||||
page.setTitle("Alternate Title");
|
topics = DISCUSSION_SERVICE.listTopics(DISCUSSION_SITE.getShortName(), new PagingRequest(10));
|
||||||
page = DISCUSSION_SERVICE.updateWikiPage(page);
|
assertEquals(2, topics.getPage().size());
|
||||||
|
assertEquals("ST1", topics.getPage().get(0).getTitle());
|
||||||
|
assertEquals("ST2", topics.getPage().get(1).getTitle());
|
||||||
|
|
||||||
// Check
|
topics = DISCUSSION_SERVICE.listTopics(FORUM_NODE, new PagingRequest(10));
|
||||||
page = DISCUSSION_SERVICE.getWikiPage(DISCUSSION_SITE.getShortName(), page.getSystemName());
|
assertEquals(3, topics.getPage().size());
|
||||||
assertEquals("Alternate_Title", page.getSystemName());
|
assertEquals("NT1", topics.getPage().get(0).getTitle());
|
||||||
assertEquals("Alternate Title", page.getTitle());
|
assertEquals("NT2", topics.getPage().get(1).getTitle());
|
||||||
assertEquals("Changed contents", page.getContents());
|
assertEquals("NT3", topics.getPage().get(2).getTitle());
|
||||||
assertEquals(TEST_USER, page.getCreator());
|
|
||||||
assertEquals(0, page.getTags().size());
|
|
||||||
|
// 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
|
* 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
|
* 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 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);
|
final Date newModified = new Date(modified.getTime() - modifiedDaysAgo*ONE_DAY_MS);
|
||||||
|
|
||||||
// Update the created date
|
// Update the created date
|
||||||
@@ -879,10 +1087,18 @@ public class DiscussionServiceImplTest
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, false, true);
|
}, false, true);
|
||||||
|
|
||||||
// Update the object itself
|
// Update the object itself
|
||||||
((TopicInfoImpl)page).setCreatedAt(newCreated);
|
if(thing instanceof TopicInfo)
|
||||||
((TopicInfoImpl)page).setModifiedAt(newModified);
|
{
|
||||||
|
((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
|
private static void createTestSites() throws Exception
|
||||||
|
Reference in New Issue
Block a user