mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9153 Start on unit tests for the new Discussions Service
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29715 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -298,18 +298,31 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
throw new IllegalArgumentException("Can't create posts for a topic that was never persisted!");
|
||||
}
|
||||
|
||||
// Are we going to be the primary post?
|
||||
boolean isPrimary = false;
|
||||
if(getPrimaryPost(topic) == null)
|
||||
{
|
||||
isPrimary = true;
|
||||
}
|
||||
|
||||
// Decide on the name. If this is the first post in a topic,
|
||||
// it should share the topic's name, otherwise needs a new one
|
||||
String name = generateName();
|
||||
if(getPrimaryPost(topic) == null)
|
||||
if(isPrimary)
|
||||
{
|
||||
name = topic.getSystemName();
|
||||
}
|
||||
|
||||
// Get the properties for the node
|
||||
// Create the properties for the node
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>();
|
||||
props.put(ContentModel.PROP_NAME, name);
|
||||
props.put(ContentModel.PROP_TITLE, topic.getTitle());
|
||||
|
||||
// Do we want a title? By default, primary posts share a title
|
||||
// with the topic, but replies are title-free
|
||||
if(isPrimary)
|
||||
{
|
||||
props.put(ContentModel.PROP_TITLE, topic.getTitle());
|
||||
}
|
||||
|
||||
// Build the node
|
||||
NodeRef nodeRef = nodeService.createNode(
|
||||
@@ -329,6 +342,31 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
// Build it that way, so creator and created date come through
|
||||
return buildPost(nodeRef, topic, name, contents);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PostInfo createReply(PostInfo parentPost, String contents)
|
||||
{
|
||||
// Sanity check what we were given
|
||||
if(parentPost.getNodeRef() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Can't reply to a post that was never persisted");
|
||||
}
|
||||
if(parentPost.getTopic() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Can't reply to a post with no attached topic");
|
||||
}
|
||||
|
||||
// Have the post created
|
||||
PostInfo reply = createPost(parentPost.getTopic(), contents);
|
||||
|
||||
// Now make it a reply
|
||||
nodeService.createAssociation(
|
||||
reply.getNodeRef(), parentPost.getNodeRef(), ContentModel.ASSOC_REFERENCES
|
||||
);
|
||||
|
||||
// All done
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -467,7 +505,7 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
PostInfo post = getPost(topic, topic.getSystemName());
|
||||
if(post != null)
|
||||
{
|
||||
return null;
|
||||
return post;
|
||||
}
|
||||
|
||||
// Cater for the explorer case, we want the first child
|
||||
@@ -484,6 +522,35 @@ public class DiscussionServiceImpl implements DiscussionService
|
||||
return buildPost(postNodeRef, topic, postName, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PagingResults<TopicInfo> listTopics(String siteShortName,
|
||||
PagingRequest paging) {
|
||||
NodeRef container = getSiteWikiContainer(siteShortName, false);
|
||||
if(container == null)
|
||||
{
|
||||
// No topics
|
||||
return new EmptyPagingResults<TopicInfo>();
|
||||
}
|
||||
|
||||
// We can now fetch by parent nodeRef
|
||||
return listTopics(container, paging);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<TopicInfo> listTopics(NodeRef nodeRef,
|
||||
PagingRequest paging) {
|
||||
// TODO
|
||||
return new EmptyPagingResults<TopicInfo>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<PostInfo> listPosts(TopicInfo topic, PagingRequest paging)
|
||||
{
|
||||
// TODO
|
||||
return new EmptyPagingResults<PostInfo>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PagingResults<PostInfo> listPostReplies(PostInfo primaryPost,
|
||||
|
@@ -33,13 +33,28 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
public interface DiscussionService {
|
||||
/**
|
||||
* Creates a new {@link PostInfo} in the given topic,
|
||||
* specified contents
|
||||
* with the specified contents.
|
||||
* Normally only one post is created this way on a topic,
|
||||
* and the remainder of the posts are created as
|
||||
* replies to the {@link #getPrimaryPost(TopicInfo)}
|
||||
* primary post.
|
||||
*
|
||||
* @return The newly created {@link PostInfo}
|
||||
*/
|
||||
@NotAuditable
|
||||
PostInfo createPost(TopicInfo topic, String contents);
|
||||
|
||||
/**
|
||||
* Creates a new {@link PostInfo} which is a reply to
|
||||
* the specified other post, with the given contents.
|
||||
* The link between the parent post and the reply is
|
||||
* created as part of this.
|
||||
*
|
||||
* @return The newly created {@link PostInfo}
|
||||
*/
|
||||
@NotAuditable
|
||||
PostInfo createReply(PostInfo parentPost, String contents);
|
||||
|
||||
/**
|
||||
* Creates a new {@link TopicInfo} in the given site
|
||||
*/
|
||||
@@ -113,6 +128,24 @@ public interface DiscussionService {
|
||||
TopicInfo getTopic(NodeRef parentNodeRef, String topicName);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all topics in a site
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<TopicInfo> listTopics(String siteShortName, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all topics attached to the specified Node
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<TopicInfo> listTopics(NodeRef nodeRef, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all posts in a topic, ordered by creation date
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<PostInfo> listPosts(TopicInfo topic, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all replies on a Topic
|
||||
*/
|
||||
@@ -126,13 +159,13 @@ public interface DiscussionService {
|
||||
PagingResults<PostInfo> listPostReplies(PostInfo primaryPost, int levels, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all posts in a site
|
||||
* Retrieves all posts in a site, across all topics
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<PostInfo> listPosts(String siteShortName, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all posts attached to the specified Node
|
||||
* Retrieves all posts attached to the specified Node, across all topics
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<PostInfo> listPosts(NodeRef nodeRef, PagingRequest paging);
|
||||
|
Reference in New Issue
Block a user