4
votes

I'm trying to get all tags (nodeRefs and names) from alfresco using CMIS.

The Alfresco version is 3.4.

Before googling a lot, I don't find any good query to do this? Any advice?

1
Do you want to get the Tags on a given Node, or do you want to get the Nodes which represent specific Tags? - Gagravarr
Thanks for your answer Gagravarr. I will try to clarify the question. I need to show all the tags on a Node (folder) recursively, because in my integration I have to make a form for uploading files and the user wants to add existing tags to the document in this moment. - Pymoo
Does it have to just be the tags used by that folder+children, or would the tags used on the Site containing the folder be OK? (Only Alfresco already maintains the list of the latter for you) - Gagravarr
I need all the tags for all the Site (including the current folder). What's the best query to do this? It's possible to access via opencmis? Thanks a lot Gagravarr. - Pymoo
All the tags for a site is an easy query to make, just not one available via CMIS. You'll need to use the normal Alfresco APIs to get it. (I'll try to make an answer out of it later, if no-one beats me to it) - Gagravarr

1 Answers

3
votes

I can't find a huge amount of detail written up on the Alfresco wiki on how the Tagging Service works, so if someone fancies taking this and updating the wiki that might be helpful!

There are three key parts to tagging:

  • Tag nodes themselves
  • Tagged nodes
  • Tag Scopes

Tag Nodes live under a special node workspace://SpacesStore/tag:tag-root which is in /cm:categoryRoot/cm:taggable. Tag Nodes are of type cm:category and the cm:name is the tag

Next, you'll want to apply a tag to a node. If it's a new tag, it needs creating in the tag root first. If this is the first tag on a node, add the cm:taggable aspect. Get the noderef of the tag node, then add that to the multi-valued cm:taggable property on the node. (The tagging service will do all of this for you if you call addTag(NodeRef,String)

Finally, various nodes up the primary parent hierarchy of the node you just tagged may be defined as a Tag Scope (eg the Site Node). With this, the nodes with the cm:tagscope aspect have the cm:tagScopeSummary property updated. cm:tagScopeSummary holds the list of tags used by the children of the node, along with the number of times the tag is used. This lets you work out what the most popular tags are for that bit of the tree, as well as working out what tags are used, and when a tag is no longer used by the tree. Again, the TaggingService updates all of that for you.

AFAIK, the various tag properties (cm:taggable and cm:tagScopeSummary) are not exposed via CMIS. You'd need to use one of the normal Alfresco APIs, either from the Public API, or something like script/org/alfresco/collaboration/tagQuery.get which will let you get the list of tags applied to a node. I'd suggest you ensure that the node you query from is a tag scope, so it's nice and quick. The Site is always a tag scope, so that's a good place to start.