Merged V3.2 to HEAD

18383: ETHREEOH-4028:  Tags added to the documents are not dispalyed in Tags pane

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18388 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2010-02-01 11:02:45 +00:00
parent 8a7a241181
commit 089c5932ee

View File

@@ -39,6 +39,8 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy;
import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency; import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
@@ -96,6 +98,10 @@ public class TaggingServiceImpl implements TaggingService,
/** Tag Details Delimiter */ /** Tag Details Delimiter */
private static final String TAG_DETAILS_DELIMITER = "|"; private static final String TAG_DETAILS_DELIMITER = "|";
/** Policy behaviour */
private JavaBehaviour updateTagBehaviour;
private JavaBehaviour createTagBehaviour;
/** /**
* Set the cateogry service * Set the cateogry service
*/ */
@@ -162,6 +168,18 @@ public class TaggingServiceImpl implements TaggingService,
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
ContentModel.ASPECT_TAGGABLE, ContentModel.ASPECT_TAGGABLE,
new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT)); new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.FIRST_EVENT));
// Update tag behaviour
createTagBehaviour = new JavaBehaviour(this, "createTags", NotificationFrequency.FIRST_EVENT);
this.policyComponent.bindClassBehaviour(
OnCreateNodePolicy.QNAME,
ContentModel.ASPECT_TAGGABLE,
createTagBehaviour);
updateTagBehaviour = new JavaBehaviour(this, "updateTags", NotificationFrequency.EVERY_EVENT);
this.policyComponent.bindClassBehaviour(
OnUpdatePropertiesPolicy.QNAME,
ContentModel.TYPE_CONTENT,
updateTagBehaviour);
} }
/** /**
@@ -191,6 +209,70 @@ public class TaggingServiceImpl implements TaggingService,
} }
} }
public void createTags(ChildAssociationRef childAssocRef)
{
NodeRef nodeRef = childAssocRef.getChildRef();
Map<QName, Serializable> before = new HashMap<QName, Serializable>(0);
Map<QName, Serializable> after = nodeService.getProperties(nodeRef);
updateTags(nodeRef, before, after);
}
/**
* Update tag policy behaviour
*/
@SuppressWarnings("unchecked")
public void updateTags(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
List<NodeRef> beforeNodeRefs = (List<NodeRef>)before.get(ContentModel.PROP_TAGS);
List<NodeRef> afterNodeRefs = (List<NodeRef>)after.get(ContentModel.PROP_TAGS);
if (beforeNodeRefs == null && afterNodeRefs != null)
{
// Queue all the after's for addition to the tag scopes
for (NodeRef afterNodeRef : afterNodeRefs)
{
String tagName = getTagName(afterNodeRef);
queueTagUpdate(nodeRef, tagName, true);
}
}
else if (afterNodeRefs == null && beforeNodeRefs != null)
{
// Queue all the before's for removal to the tag scope
for (NodeRef beforeNodeRef : beforeNodeRefs)
{
String tagName = getTagName(beforeNodeRef);
queueTagUpdate(nodeRef, tagName, false);
}
}
else if (afterNodeRefs != null && beforeNodeRefs != null)
{
for (NodeRef beforeNodeRef : beforeNodeRefs)
{
if (afterNodeRefs.contains(beforeNodeRef) == true)
{
// remove the node ref from the after list
afterNodeRefs.remove(beforeNodeRef);
}
else
{
String tagName = getTagName(beforeNodeRef);
queueTagUpdate(nodeRef, tagName, false);
}
}
for (NodeRef afterNodeRef : afterNodeRefs)
{
String tagName = getTagName(afterNodeRef);
queueTagUpdate(nodeRef, tagName, true);
}
}
}
private String getTagName(NodeRef nodeRef)
{
return (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
}
/** /**
* @see org.alfresco.service.cmr.tagging.TaggingService#isTag(java.lang.String) * @see org.alfresco.service.cmr.tagging.TaggingService#isTag(java.lang.String)
*/ */
@@ -271,40 +353,50 @@ public class TaggingServiceImpl implements TaggingService,
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void addTag(final NodeRef nodeRef, final String tagName) public void addTag(final NodeRef nodeRef, final String tagName)
{ {
// Lower the case of the tag updateTagBehaviour.disable();
String tag = tagName.toLowerCase(); createTagBehaviour.disable();
try
// Get the tag node reference
NodeRef newTagNodeRef = getTagNodeRef(nodeRef.getStoreRef(), tag);
if (newTagNodeRef == null)
{ {
// Create the new tag // Lower the case of the tag
newTagNodeRef = categoryService.createRootCategory(nodeRef.getStoreRef(), ContentModel.ASPECT_TAGGABLE, tag); String tag = tagName.toLowerCase();
}
// Get the tag node reference
List<NodeRef> tagNodeRefs = new ArrayList<NodeRef>(5); NodeRef newTagNodeRef = getTagNodeRef(nodeRef.getStoreRef(), tag);
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == false) if (newTagNodeRef == null)
{
// Add the aspect
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TAGGABLE, null);
}
else
{
// Get the current tags
List<NodeRef> currentTagNodes = (List<NodeRef>)nodeService.getProperty(nodeRef, ContentModel.PROP_TAGS);
if (currentTagNodes != null)
{ {
tagNodeRefs = currentTagNodes; // Create the new tag
newTagNodeRef = categoryService.createRootCategory(nodeRef.getStoreRef(), ContentModel.ASPECT_TAGGABLE, tag);
}
List<NodeRef> tagNodeRefs = new ArrayList<NodeRef>(5);
if (nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == false)
{
// Add the aspect
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TAGGABLE, null);
}
else
{
// Get the current tags
List<NodeRef> currentTagNodes = (List<NodeRef>)nodeService.getProperty(nodeRef, ContentModel.PROP_TAGS);
if (currentTagNodes != null)
{
tagNodeRefs = currentTagNodes;
}
}
// Add the new tag (assuming it's not already been added
if (tagNodeRefs.contains(newTagNodeRef) == false)
{
tagNodeRefs.add(newTagNodeRef);
nodeService.setProperty(nodeRef, ContentModel.PROP_TAGS, (Serializable)tagNodeRefs);
queueTagUpdate(nodeRef, tag, true);
} }
} }
finally
// Add the new tag (assuming it's not already been added
if (tagNodeRefs.contains(newTagNodeRef) == false)
{ {
tagNodeRefs.add(newTagNodeRef); updateTagBehaviour.enable();
nodeService.setProperty(nodeRef, ContentModel.PROP_TAGS, (Serializable)tagNodeRefs); createTagBehaviour.enable();
queueTagUpdate(nodeRef, tag, true); }
}
} }
/** /**
@@ -347,28 +439,38 @@ public class TaggingServiceImpl implements TaggingService,
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void removeTag(NodeRef nodeRef, String tag) public void removeTag(NodeRef nodeRef, String tag)
{ {
// Lower the case of the tag updateTagBehaviour.disable();
tag = tag.toLowerCase(); createTagBehaviour.disable();
try
// Check for the taggable aspect {
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == true) // Lower the case of the tag
{ tag = tag.toLowerCase();
// Get the tag node reference
NodeRef newTagNodeRef = getTagNodeRef(nodeRef.getStoreRef(), tag); // Check for the taggable aspect
if (newTagNodeRef != null) if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == true)
{ {
// Get the current tags // Get the tag node reference
List<NodeRef> currentTagNodes = (List<NodeRef>)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TAGS); NodeRef newTagNodeRef = getTagNodeRef(nodeRef.getStoreRef(), tag);
if (currentTagNodes != null && if (newTagNodeRef != null)
currentTagNodes.size() != 0 &&
currentTagNodes.contains(newTagNodeRef) == true)
{ {
currentTagNodes.remove(newTagNodeRef); // Get the current tags
this.nodeService.setProperty(nodeRef, ContentModel.PROP_TAGS, (Serializable)currentTagNodes); List<NodeRef> currentTagNodes = (List<NodeRef>)this.nodeService.getProperty(nodeRef, ContentModel.PROP_TAGS);
queueTagUpdate(nodeRef, tag, false); if (currentTagNodes != null &&
currentTagNodes.size() != 0 &&
currentTagNodes.contains(newTagNodeRef) == true)
{
currentTagNodes.remove(newTagNodeRef);
this.nodeService.setProperty(nodeRef, ContentModel.PROP_TAGS, (Serializable)currentTagNodes);
queueTagUpdate(nodeRef, tag, false);
}
} }
} }
} }
finally
{
updateTagBehaviour.enable();
createTagBehaviour.enable();
}
} }
/** /**
@@ -412,56 +514,66 @@ public class TaggingServiceImpl implements TaggingService,
* @see org.alfresco.service.cmr.tagging.TaggingService#setTags(org.alfresco.service.cmr.repository.NodeRef, java.util.List) * @see org.alfresco.service.cmr.tagging.TaggingService#setTags(org.alfresco.service.cmr.repository.NodeRef, java.util.List)
*/ */
public void setTags(NodeRef nodeRef, List<String> tags) public void setTags(NodeRef nodeRef, List<String> tags)
{ {
List<NodeRef> tagNodeRefs = new ArrayList<NodeRef>(tags.size()); updateTagBehaviour.disable();
if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == false) createTagBehaviour.disable();
try
{ {
// Add the aspect List<NodeRef> tagNodeRefs = new ArrayList<NodeRef>(tags.size());
this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TAGGABLE, null); if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGGABLE) == false)
}
// Get the current list of tags
List<String> oldTags = getTags(nodeRef);
for (String tag : tags)
{
// Lower the case of the tag
tag = tag.toLowerCase();
// Get the tag node reference
NodeRef newTagNodeRef = getTagNodeRef(nodeRef.getStoreRef(), tag);
if (newTagNodeRef == null)
{ {
// Create the new tag // Add the aspect
newTagNodeRef = this.categoryService.createRootCategory(nodeRef.getStoreRef(), ContentModel.ASPECT_TAGGABLE, tag); this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_TAGGABLE, null);
} }
if (tagNodeRefs.contains(newTagNodeRef) == false) // Get the current list of tags
{ List<String> oldTags = getTags(nodeRef);
// Add to the list
tagNodeRefs.add(newTagNodeRef); for (String tag : tags)
{
// Lower the case of the tag
tag = tag.toLowerCase();
// Trigger scope update // Get the tag node reference
if (oldTags.contains(tag) == false) NodeRef newTagNodeRef = getTagNodeRef(nodeRef.getStoreRef(), tag);
if (newTagNodeRef == null)
{ {
queueTagUpdate(nodeRef, tag, true); // Create the new tag
} newTagNodeRef = this.categoryService.createRootCategory(nodeRef.getStoreRef(), ContentModel.ASPECT_TAGGABLE, tag);
else }
{
// Remove the tag from the old list if (tagNodeRefs.contains(newTagNodeRef) == false)
oldTags.remove(tag); {
// Add to the list
tagNodeRefs.add(newTagNodeRef);
// Trigger scope update
if (oldTags.contains(tag) == false)
{
queueTagUpdate(nodeRef, tag, true);
}
else
{
// Remove the tag from the old list
oldTags.remove(tag);
}
} }
} }
// Remove the old tags from the tag scope
for (String oldTag : oldTags)
{
queueTagUpdate(nodeRef, oldTag, false);
}
// Update category property
this.nodeService.setProperty(nodeRef, ContentModel.PROP_TAGS, (Serializable)tagNodeRefs);
} }
finally
// Remove the old tags from the tag scope
for (String oldTag : oldTags)
{ {
queueTagUpdate(nodeRef, oldTag, false); updateTagBehaviour.enable();
createTagBehaviour.enable();
} }
// Update category property
this.nodeService.setProperty(nodeRef, ContentModel.PROP_TAGS, (Serializable)tagNodeRefs);
} }
/** /**
@@ -722,6 +834,7 @@ public class TaggingServiceImpl implements TaggingService,
* @param updates * @param updates
* @param async indicates whether the action is execute asynchronously * @param async indicates whether the action is execute asynchronously
*/ */
@SuppressWarnings("unchecked")
private void updateTagScope(NodeRef nodeRef, Map<String, Boolean> updates, boolean async) private void updateTagScope(NodeRef nodeRef, Map<String, Boolean> updates, boolean async)
{ {
// The map must be serializable // The map must be serializable
@@ -820,7 +933,6 @@ public class TaggingServiceImpl implements TaggingService,
/** /**
* @see org.alfresco.repo.transaction.TransactionListener#flush() * @see org.alfresco.repo.transaction.TransactionListener#flush()
*/ */
@SuppressWarnings("deprecation")
public void flush() public void flush()
{ {
} }