From 43757d8cb693ddb42dfe3a1ee8eef63c6767a540 Mon Sep 17 00:00:00 2001 From: Neil McErlean Date: Wed, 29 Jun 2011 14:51:17 +0000 Subject: [PATCH] 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 --- .../alfresco/repo/forum/CommentService.java | 4 +- .../repo/forum/CommentServiceImpl.java | 43 ++++++++++++------- .../repo/forum/ForumPostBehaviours.java | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/source/java/org/alfresco/repo/forum/CommentService.java b/source/java/org/alfresco/repo/forum/CommentService.java index 73e8b6c0e4..a673e911bf 100644 --- a/source/java/org/alfresco/repo/forum/CommentService.java +++ b/source/java/org/alfresco/repo/forum/CommentService.java @@ -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 null, 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 null * @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 diff --git a/source/java/org/alfresco/repo/forum/CommentServiceImpl.java b/source/java/org/alfresco/repo/forum/CommentServiceImpl.java index 78a1a67ca9..491cd1247f 100644 --- a/source/java/org/alfresco/repo/forum/CommentServiceImpl.java +++ b/source/java/org/alfresco/repo/forum/CommentServiceImpl.java @@ -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; + } + } } } diff --git a/source/java/org/alfresco/repo/forum/ForumPostBehaviours.java b/source/java/org/alfresco/repo/forum/ForumPostBehaviours.java index b95ff12e35..10d8179d05 100644 --- a/source/java/org/alfresco/repo/forum/ForumPostBehaviours.java +++ b/source/java/org/alfresco/repo/forum/ForumPostBehaviours.java @@ -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) {