Fix for failing testcase DiscussionServiceTest.testDeleteTopLevelPost

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28695 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2011-06-29 14:51:17 +00:00
parent 049f9a7575
commit 43757d8cb6
3 changed files with 29 additions and 20 deletions

View File

@@ -38,12 +38,10 @@ public interface CommentService
* {@link ForumModel#ASPECT_DISCUSSABLE fm:discussable} aspect.
*
* @param descendantNodeRef The nodeRef which descends from the f:discussable node.
* @param expectedNodeType if not <tt>null</tt>, this is an assertion by calling code that the descendantNodeRef
* is of the specified type.
* @return the fm:discussable ancestor if there is one, else <tt>null</tt>
* @throws AlfrescoRuntimeException if the specified expectedNodeType is not correct.
*/
NodeRef getDiscussableAncestor(NodeRef descendantNodeRef, QName expectedNodeType);
NodeRef getDiscussableAncestor(NodeRef descendantNodeRef);
/**
* This method retrieves the {@link ForumModel#TYPE_TOPIC fm:topic} NodeRef which holds the Share comments for

View File

@@ -49,27 +49,38 @@ public class CommentServiceImpl implements CommentService
}
@Override
public NodeRef getDiscussableAncestor(NodeRef descendantNodeRef, QName expectedNodeType)
public NodeRef getDiscussableAncestor(NodeRef descendantNodeRef)
{
final QName actualNodeType = nodeService.getType(descendantNodeRef);
if (expectedNodeType != null && !actualNodeType.equals(expectedNodeType))
{
StringBuilder msg = new StringBuilder();
msg.append("Node ").append(descendantNodeRef)
.append(" is of type ").append(actualNodeType)
.append(", not ").append(expectedNodeType);
throw new AlfrescoRuntimeException(msg.toString());
}
// For "Share comments" i.e. fm:post nodes created via the Share commenting UI, the containment structure is as follows:
// fm:discussable
// - fm:forum
// - fm:topic
// - fm:post
// For other fm:post nodes the ancestor structure may be slightly different. (cf. Share discussions, which don't have 'forum')
//
// In order to ensure that we only return the discussable ancestor relevant to Share comments, we'll climb the
// containment tree in a controlled manner.
// We could navigate up looking for the first fm:discussable ancestor, but that might not find the correct node - it could,
// for example, find a parent folder which was discussable.
NodeRef result = null;
for (ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(descendantNodeRef);
parentAssoc != null && parentAssoc.getParentRef() != null;
parentAssoc = nodeService.getPrimaryParent(parentAssoc.getParentRef()))
if (nodeService.getType(descendantNodeRef).equals(ForumModel.TYPE_POST))
{
if (nodeService.hasAspect(parentAssoc.getParentRef(), ForumModel.ASPECT_DISCUSSABLE))
NodeRef topicNode = nodeService.getPrimaryParent(descendantNodeRef).getParentRef();
if (nodeService.getType(topicNode).equals(ForumModel.TYPE_TOPIC))
{
result = parentAssoc.getParentRef();
break;
NodeRef forumNode = nodeService.getPrimaryParent(topicNode).getParentRef();
if (nodeService.getType(forumNode).equals(ForumModel.TYPE_FORUM))
{
NodeRef discussableNode = nodeService.getPrimaryParent(forumNode).getParentRef();
if (nodeService.hasAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE))
{
result = discussableNode;
}
}
}
}

View File

@@ -196,7 +196,7 @@ public class ForumPostBehaviours implements NodeServicePolicies.OnCreateNodePoli
{
// We have a new or a deleted comment under a discussable node.
// We need to find the fm:commentsCount ancestor to this comment node and adjust its commentCount
NodeRef discussableAncestor = commentService.getDiscussableAncestor(fmPostNode, ForumModel.TYPE_POST);
NodeRef discussableAncestor = commentService.getDiscussableAncestor(fmPostNode);
if (discussableAncestor != null)
{