diff --git a/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java b/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java index e71b89d9f2..c8fa5b47fc 100644 --- a/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java +++ b/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java @@ -762,7 +762,7 @@ public class TaggingServiceImpl implements TaggingService, if (this.nodeService.exists(nodeRef) == true) { List tagScopeNodeRefs = new ArrayList(3); - getTagScopes(nodeRef, tagScopeNodeRefs); + getTagScopes(nodeRef, tagScopeNodeRefs, true); if (tagScopeNodeRefs.size() != 0) { tagScope = new TagScopeImpl(tagScopeNodeRefs.get(0), getTagDetails(tagScopeNodeRefs.get(0))); @@ -816,20 +816,35 @@ public class TaggingServiceImpl implements TaggingService, return result; } - + /** - * Traverses up the node's primary parent placing all tag scope's in a list. + * Traverses up the node's primary parent placing ALL found tag scope's in a list. *

- * If none are found then the list is empty. * * @param nodeRef node reference * @param tagScopes list of tag scopes */ private void getTagScopes(NodeRef nodeRef, List tagScopes) + { + getTagScopes(nodeRef, tagScopes, false); + } + + /** + * Traverses up the node's primary parent placing found tag scope's in a list. + *

+ * If none are found then the list is empty. + * + * @param nodeRef node reference + * @param tagScopes list of tag scopes + * @param firstOnly true => only return first tag scope that is found + */ + private void getTagScopes(NodeRef nodeRef, List tagScopes, boolean firstOnly) { if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGSCOPE) == true) { tagScopes.add(nodeRef); + if (firstOnly) + return; } ChildAssociationRef assoc = this.nodeService.getPrimaryParent(nodeRef); @@ -838,8 +853,8 @@ public class TaggingServiceImpl implements TaggingService, NodeRef parent = assoc.getParentRef(); if (parent != null) { - getTagScopes(parent, tagScopes); - } + getTagScopes(parent, tagScopes, firstOnly); + } } }