Fixed a problem NickB discovered with Explorer-entered comments.

This will probably be a fix for ALF-9506 as well, but I can't test that currently.
Fix was to tweak the behaviour registered to fm:post onUpdateProperties to *not* throw exceptions when the content model doesn't look like a 'share comment'.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29642 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Neil McErlean
2011-08-09 20:23:40 +00:00
parent abe692b682
commit 62cfc60ce9

View File

@@ -120,8 +120,8 @@ public class ForumPostBehaviours implements NodeServicePolicies.OnCreateNodePoli
log.debug("Triggering a comment recount..."); log.debug("Triggering a comment recount...");
} }
final int realCommentTotal = calculateCommentTotalByNodeCounting(commentsRollupNode); final Integer realCommentTotal = calculateCommentTotalByNodeCounting(commentsRollupNode);
if (realCommentTotal != -1) if (realCommentTotal != null && realCommentTotal != -1)
{ {
nodeService.setProperty(commentsRollupNode, ForumModel.PROP_COMMENT_COUNT, realCommentTotal); nodeService.setProperty(commentsRollupNode, ForumModel.PROP_COMMENT_COUNT, realCommentTotal);
} }
@@ -130,17 +130,18 @@ public class ForumPostBehaviours implements NodeServicePolicies.OnCreateNodePoli
} }
/** /**
* Calculate the comment total for the specified node.
* *
* @param discussableNode discussable node. * @param discussableNode discussable node.
* @return * @return the recount value or <tt>null</tt> if it is not possible to calculate the total.
*/ */
private int calculateCommentTotalByNodeCounting(NodeRef discussableNode) private Integer calculateCommentTotalByNodeCounting(NodeRef discussableNode)
{ {
if ( !nodeService.hasAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE)) // This method only counts "Share comments" and not Explorer comments or other fm:post nodes.
{ Integer result = null;
throw new IllegalArgumentException("Node did not have " + ForumModel.ASPECT_DISCUSSABLE + " aspect.");
}
if (nodeService.hasAspect(discussableNode, ForumModel.ASPECT_DISCUSSABLE))
{
NodeRef topicNode = commentService.getShareCommentsTopic(discussableNode); NodeRef topicNode = commentService.getShareCommentsTopic(discussableNode);
if (log.isDebugEnabled()) if (log.isDebugEnabled())
@@ -154,24 +155,23 @@ public class ForumPostBehaviours implements NodeServicePolicies.OnCreateNodePoli
log.debug(msg.toString()); log.debug(msg.toString());
} }
if (topicNode == null) // We'll ignore discussable nodes which do not have an fm:topic in the correct
// location - as used by "Share comments" - as opposed to e.g. Explorer client discussion fm:posts.
if (topicNode != null)
{ {
throw new NullPointerException("Topic node was null");
}
// Can't ask the commentService for a count, as it will give us -1.
// Need to recalculate by hand. // Need to recalculate by hand.
//TODO This could be replaced with a GetChildrenCannedQuery. //TODO This could be replaced with a GetChildrenCannedQuery.
// Look for fm:post nodes only. // Look for fm:post nodes only.
Set<QName> childNodeTypeQNames = new HashSet<QName>(1); Set<QName> childNodeTypeQNames = new HashSet<QName>();
childNodeTypeQNames.add(ForumModel.TYPE_POST); childNodeTypeQNames.add(ForumModel.TYPE_POST);
// We'll use the raw, small 'n' nodeService as the big 'N' NodeService's interceptors would limit results. // We'll use the raw, small 'n' nodeService as the big 'N' NodeService's interceptors would limit results.
List<ChildAssociationRef> fmPostChildren = rawNodeService.getChildAssocs(topicNode, childNodeTypeQNames); List<ChildAssociationRef> fmPostChildren = rawNodeService.getChildAssocs(topicNode, childNodeTypeQNames);
final int commentTotal = fmPostChildren.size(); result = new Integer(fmPostChildren.size());
}
return commentTotal; }
return result;
} }
@Override @Override
@@ -195,15 +195,17 @@ public class ForumPostBehaviours implements NodeServicePolicies.OnCreateNodePoli
private void adjustCommentCount(NodeRef fmPostNode, boolean incrementing) private void adjustCommentCount(NodeRef fmPostNode, boolean incrementing)
{ {
// We have a new or a deleted comment under a discussable node. // 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 // We need to find the fm:commentsCount ancestor to this comment node (if there is one) and adjust its commentCount
NodeRef discussableAncestor = commentService.getDiscussableAncestor(fmPostNode); NodeRef discussableAncestor = commentService.getDiscussableAncestor(fmPostNode);
if (discussableAncestor != null) if (discussableAncestor != null)
{ {
if (discussableNodeRequiresFullRecount(discussableAncestor)) if (discussableNodeRequiresFullRecount(discussableAncestor))
{ {
int recount = calculateCommentTotalByNodeCounting(discussableAncestor); Integer recount = calculateCommentTotalByNodeCounting(discussableAncestor);
if (recount != null)
{
nodeService.addAspect(discussableAncestor, ForumModel.ASPECT_COMMENTS_ROLLUP, null); nodeService.addAspect(discussableAncestor, ForumModel.ASPECT_COMMENTS_ROLLUP, null);
int newCountValue = recount; int newCountValue = recount;
// If the node is being deleted then the above node-count will include the to-be-deleted node. // If the node is being deleted then the above node-count will include the to-be-deleted node.
@@ -220,6 +222,8 @@ public class ForumPostBehaviours implements NodeServicePolicies.OnCreateNodePoli
nodeService.setProperty(discussableAncestor, ForumModel.PROP_COMMENT_COUNT, newCountValue); nodeService.setProperty(discussableAncestor, ForumModel.PROP_COMMENT_COUNT, newCountValue);
} }
}
else else
{ {
Integer existingCommentCount = (Integer) nodeService.getProperty(discussableAncestor, ForumModel.PROP_COMMENT_COUNT); Integer existingCommentCount = (Integer) nodeService.getProperty(discussableAncestor, ForumModel.PROP_COMMENT_COUNT);