mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Tagging Service: Complete JS and Java APIs
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9689 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,6 +28,7 @@ import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -40,6 +41,7 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.action.executer.TransformActionExecuter;
|
||||
import org.alfresco.repo.content.transform.magick.ImageTransformationOptions;
|
||||
import org.alfresco.repo.search.QueryParameterDefImpl;
|
||||
import org.alfresco.repo.tagging.script.TagScope;
|
||||
import org.alfresco.repo.thumbnail.CreateThumbnailActionExecuter;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDetails;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
|
||||
@@ -2004,7 +2006,7 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
/**
|
||||
* Get the all the thumbnails for a given node's content property.
|
||||
*
|
||||
* @return ScriptThumbnail list of thumbnails, empty if none available
|
||||
* @return Scriptable list of thumbnails, empty if none available
|
||||
*/
|
||||
public ScriptThumbnail[] getThumbnails()
|
||||
{
|
||||
@@ -2026,6 +2028,14 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
// ------------------------------------------------------------------------------
|
||||
// Tag methods
|
||||
|
||||
/**
|
||||
* Clear the node's tags
|
||||
*/
|
||||
public void clearTags()
|
||||
{
|
||||
this.services.getTaggingService().clearTags(this.nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tag to the node
|
||||
*
|
||||
@@ -2036,6 +2046,16 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
this.services.getTaggingService().addTag(this.nodeRef, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the tags to the node
|
||||
*
|
||||
* @param tags array of tag names
|
||||
*/
|
||||
public void addTags(String[] tags)
|
||||
{
|
||||
this.services.getTaggingService().addTags(this.nodeRef, Arrays.asList(tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a tag from the node
|
||||
*
|
||||
@@ -2046,6 +2066,16 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
this.services.getTaggingService().removeTag(this.nodeRef, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the tags from the node
|
||||
*
|
||||
* @param tags array of tag names
|
||||
*/
|
||||
public void removeTags(String[] tags)
|
||||
{
|
||||
this.services.getTaggingService().removeTags(this.nodeRef, Arrays.asList(tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the tags applied to this node
|
||||
*
|
||||
@@ -2057,6 +2087,17 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
return (String[])tags.toArray(new String[tags.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tags applied to this node. This overwirtes the list of tags currently applied to the
|
||||
* node.
|
||||
*
|
||||
* @param tags array of tags
|
||||
*/
|
||||
public void setTags(String[] tags)
|
||||
{
|
||||
this.services.getTaggingService().setTags(this.nodeRef, Arrays.asList(tags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this node is a tag scope or not
|
||||
*
|
||||
@@ -2090,6 +2131,43 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
return this.services.getTaggingService().isTagScope(this.nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the 'nearest' tag scope to this node by travesing up the parent hierarchy untill one is found.
|
||||
* <p>
|
||||
* If none is found, null is returned.
|
||||
*
|
||||
* @return TagScope the 'nearest' tag scope
|
||||
*/
|
||||
public TagScope getTagScope()
|
||||
{
|
||||
TagScope tagScope = null;
|
||||
org.alfresco.service.cmr.tagging.TagScope tagScopeImpl = this.services.getTaggingService().findTagScope(this.nodeRef);
|
||||
if (tagScopeImpl != null)
|
||||
{
|
||||
tagScope = new TagScope(tagScopeImpl);
|
||||
}
|
||||
return tagScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all (deep) children of this node that have the tag specified.
|
||||
*
|
||||
* @param tag tag name
|
||||
* @return ScriptNode[] nodes that are deep children of the node with the tag
|
||||
*/
|
||||
public ScriptNode[] childrenByTags(String tag)
|
||||
{
|
||||
List<NodeRef> nodeRefs = this.services.getTaggingService().findTaggedNodes(this.nodeRef.getStoreRef(), tag, this.nodeRef);
|
||||
ScriptNode[] nodes = new ScriptNode[nodeRefs.size()];
|
||||
int index = 0;
|
||||
for (NodeRef node : nodeRefs)
|
||||
{
|
||||
nodes[index] = new ScriptNode(node, this.services, this.scope);
|
||||
index ++;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Helper methods
|
||||
|
||||
|
@@ -26,6 +26,7 @@ package org.alfresco.repo.jscript;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -354,6 +355,36 @@ public final class Search extends BaseScopableProcessorExtension
|
||||
return Context.getCurrentContext().newArray(getScope(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searchs the store for all nodes with the given tag applied.
|
||||
*
|
||||
* @param store store ref string, default used if null provided
|
||||
* @param tag tag name
|
||||
* @return ScriptNode[] nodes with tag applied
|
||||
*/
|
||||
public ScriptNode[] tagSearch(String store, String tag)
|
||||
{
|
||||
StoreRef searchStoreRef = null;
|
||||
if (store != null)
|
||||
{
|
||||
searchStoreRef = new StoreRef(store);
|
||||
}
|
||||
else
|
||||
{
|
||||
searchStoreRef = this.storeRef;
|
||||
}
|
||||
|
||||
List<NodeRef> nodeRefs = this.services.getTaggingService().findTaggedNodes(searchStoreRef, tag);
|
||||
ScriptNode[] nodes = new ScriptNode[nodeRefs.size()];
|
||||
int index = 0;
|
||||
for (NodeRef node : nodeRefs)
|
||||
{
|
||||
nodes[index] = new ScriptNode(node, this.services, getScope());
|
||||
index ++;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
|
Reference in New Issue
Block a user