mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Tagging Service: Add, remove and get tags added to JS ScriptNode
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9639 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -2023,6 +2023,72 @@ public class ScriptNode implements Serializable, Scopeable
|
||||
return (ScriptThumbnail[])result.toArray(new ScriptThumbnail[result.size()]);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Tag methods
|
||||
|
||||
/**
|
||||
* Adds a tag to the node
|
||||
*
|
||||
* @param tag tag name
|
||||
*/
|
||||
public void addTag(String tag)
|
||||
{
|
||||
this.services.getTaggingService().addTag(this.nodeRef, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a tag from the node
|
||||
*
|
||||
* @param tag tag name
|
||||
*/
|
||||
public void removeTag(String tag)
|
||||
{
|
||||
this.services.getTaggingService().removeTag(this.nodeRef, tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the tags applied to this node
|
||||
*
|
||||
* @return String[] array containing all the tag applied to this node
|
||||
*/
|
||||
public String[] getTags()
|
||||
{
|
||||
List<String> tags = this.services.getTaggingService().getTags(this.nodeRef);
|
||||
return (String[])tags.toArray(new String[tags.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this node is a tag scope or not
|
||||
*
|
||||
* @param value true if this node is a tag scope, false otherwise
|
||||
*/
|
||||
public void setIsTagScope(boolean value)
|
||||
{
|
||||
boolean currentValue = this.services.getTaggingService().isTagScope(this.nodeRef);
|
||||
if (currentValue != value)
|
||||
{
|
||||
if (value == true)
|
||||
{
|
||||
// Add the tag scope
|
||||
this.services.getTaggingService().addTagScope(this.nodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove the tag scope
|
||||
this.services.getTaggingService().removeTagScope(this.nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this node is a tag scope
|
||||
*
|
||||
* @return boolean true if this node is a tag scope, false otherwise
|
||||
*/
|
||||
public boolean getIsTagScope()
|
||||
{
|
||||
return this.services.getTaggingService().isTagScope(this.nodeRef);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Helper methods
|
||||
|
@@ -413,7 +413,7 @@ public class LuceneCategoryServiceImpl implements CategoryService
|
||||
|
||||
LuceneIndexerAndSearcher lias = (LuceneIndexerAndSearcher) indexerAndSearcher;
|
||||
String field = "@" + catProperty;
|
||||
SearchService searchService = lias.getSearcher(storeRef, true);
|
||||
SearchService searchService = lias.getSearcher(storeRef, false);
|
||||
if (searchService instanceof LuceneSearcher)
|
||||
{
|
||||
LuceneSearcher luceneSearcher = (LuceneSearcher)searchService;
|
||||
|
@@ -57,6 +57,7 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.OwnableService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
import org.alfresco.service.cmr.view.ExporterService;
|
||||
@@ -433,4 +434,12 @@ public class ServiceDescriptorRegistry
|
||||
{
|
||||
return (ThumbnailService)getService(THUMBNAIL_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.ServiceRegistry#getTaggingService()
|
||||
*/
|
||||
public TaggingService getTaggingService()
|
||||
{
|
||||
return (TaggingService)getService(TAGGING_SERVICE);
|
||||
}
|
||||
}
|
||||
|
@@ -152,6 +152,21 @@ public class TaggingServiceImpl implements TaggingService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#deleteTag(org.alfresco.service.cmr.repository.StoreRef, java.lang.String)
|
||||
*/
|
||||
public void deleteTag(StoreRef storeRef, String tag)
|
||||
{
|
||||
// Lower the case of the tag
|
||||
tag = tag.toLowerCase();
|
||||
|
||||
NodeRef tagNodeRef = getTagNodeRef(storeRef, tag);
|
||||
if (tagNodeRef != null)
|
||||
{
|
||||
this.categoryService.deleteCategory(tagNodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags()
|
||||
*/
|
||||
@@ -167,6 +182,15 @@ public class TaggingServiceImpl implements TaggingService
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#getTags(org.alfresco.service.cmr.repository.StoreRef, java.lang.String)
|
||||
*/
|
||||
public List<String> getTags(StoreRef storeRef, String filter)
|
||||
{
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#addTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
@@ -298,6 +322,14 @@ public class TaggingServiceImpl implements TaggingService
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#isTagScope(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public boolean isTagScope(NodeRef nodeRef)
|
||||
{
|
||||
return this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_TAGSCOPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#addTagScope(org.alfresco.service.cmr.repository.NodeRef)
|
||||
@@ -421,26 +453,33 @@ public class TaggingServiceImpl implements TaggingService
|
||||
// Lower the case of the tag
|
||||
tag = tag.toLowerCase();
|
||||
|
||||
//
|
||||
// "+PATH:\"/cm:taggable/cm:" + ISOed(tag) + "/member\""
|
||||
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(java.lang.String, org.alfresco.service.cmr.tagging.TagScope)
|
||||
* @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public List<NodeRef> findTaggedNodes(String tag, TagScope tagScope)
|
||||
public List<NodeRef> findTaggedNodes(String tag, NodeRef nodeRef)
|
||||
{
|
||||
// Lower the case of the tag
|
||||
tag = tag.toLowerCase();
|
||||
|
||||
//
|
||||
// "+PATH:\"/cm:taggable/cm:" + ISOed(tag) + "/member\" +PATH:\"" + pathOfTheNode + "//*\""
|
||||
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that takes an input stream and converts it into a list of tag details
|
||||
*
|
||||
* @param is
|
||||
* @return
|
||||
* @param is input stream
|
||||
* @return List<TagDetails> list of tag details
|
||||
*/
|
||||
/*package*/ static List<TagDetails> readTagDetails(InputStream is)
|
||||
{
|
||||
@@ -460,7 +499,6 @@ public class TaggingServiceImpl implements TaggingService
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
|
||||
throw new AlfrescoRuntimeException("Unable to read tag details", exception);
|
||||
}
|
||||
|
||||
@@ -468,9 +506,10 @@ public class TaggingServiceImpl implements TaggingService
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to convert a list of tag details into a string.
|
||||
*
|
||||
* @param tagDetails
|
||||
* @param os
|
||||
* @param tagDetails list of tag details
|
||||
* @return String string of tag details
|
||||
*/
|
||||
/*package*/ static String tagDetailsToString(List<TagDetails> tagDetails)
|
||||
{
|
||||
|
@@ -32,11 +32,14 @@ import java.util.Map;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.jscript.ClasspathScriptLocation;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.ScriptLocation;
|
||||
import org.alfresco.service.cmr.repository.ScriptService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.tagging.TagDetails;
|
||||
@@ -56,6 +59,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
||||
{
|
||||
/** Services */
|
||||
private TaggingService taggingService;
|
||||
private ScriptService scriptService;
|
||||
|
||||
private static StoreRef storeRef;
|
||||
private static NodeRef rootNode;
|
||||
@@ -85,6 +89,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
||||
this.authenticationService = (AuthenticationService) this.applicationContext.getBean("authenticationService");
|
||||
this.actionService = (ActionService)this.applicationContext.getBean("actionService");
|
||||
this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
|
||||
this.scriptService = (ScriptService)this.applicationContext.getBean("scriptService");
|
||||
|
||||
if (init == false)
|
||||
{
|
||||
@@ -196,7 +201,28 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
||||
assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_1));
|
||||
assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, UPPER_TAG));
|
||||
assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, LOWER_TAG));
|
||||
tx.commit();
|
||||
|
||||
// Remove a tag
|
||||
this.taggingService.deleteTag(TaggingServiceImplTest.storeRef, UPPER_TAG);
|
||||
|
||||
tx.commit();
|
||||
tx = this.transactionService.getUserTransaction();
|
||||
tx.begin();
|
||||
|
||||
// Get all the tags
|
||||
tags = this.taggingService.getTags(TaggingServiceImplTest.storeRef);
|
||||
assertNotNull(tags);
|
||||
assertEquals(1, tags.size());
|
||||
assertTrue(tags.contains(TAG_1));
|
||||
assertFalse(tags.contains(LOWER_TAG));
|
||||
|
||||
// Check isTag method
|
||||
assertFalse(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_2));
|
||||
assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_1));
|
||||
assertFalse(this.taggingService.isTag(TaggingServiceImplTest.storeRef, UPPER_TAG));
|
||||
assertFalse(this.taggingService.isTag(TaggingServiceImplTest.storeRef, LOWER_TAG));
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
public void testAddRemoveTag()
|
||||
@@ -233,6 +259,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
||||
}
|
||||
|
||||
public void testTagScopeFindAddRemove()
|
||||
throws Exception
|
||||
{
|
||||
// Get scopes for node without
|
||||
TagScope tagScope = this.taggingService.findTagScope(this.subDocument);
|
||||
@@ -340,8 +367,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
||||
assertEquals(2, ts1.getTags().size());
|
||||
assertEquals(2, ts2.getTags().size());
|
||||
|
||||
tx.commit();
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
|
||||
private void addTag(NodeRef nodeRef, String tag, int tagCount, NodeRef tagScopeNodeRef)
|
||||
@@ -489,4 +515,18 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// == Test the JavaScript API ==
|
||||
|
||||
public void testJSAPI() throws Exception
|
||||
{
|
||||
Map model = new HashMap<String, Object>(0);
|
||||
model.put("folder", this.folder);
|
||||
model.put("subFolder", this.subFolder);
|
||||
model.put("document", this.document);
|
||||
model.put("subDocument", this.subDocument);
|
||||
|
||||
ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/tagging/script/test_taggingService.js");
|
||||
this.scriptService.executeScript(location, model);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,24 @@
|
||||
function testAddRemoveTag()
|
||||
{
|
||||
var tags = document.tags;
|
||||
test.assertNotNull(tags);
|
||||
test.assertEquals(0, tags.length);
|
||||
|
||||
document.addTag("mouse");
|
||||
document.addTag("snake");
|
||||
document.addTag("snail");
|
||||
|
||||
tags = document.tags;
|
||||
test.assertNotNull(tags);
|
||||
test.assertEquals(3, tags.length);
|
||||
|
||||
document.removeTag("cat");
|
||||
document.removeTag("snake");
|
||||
|
||||
tags = document.tags;
|
||||
test.assertNotNull(tags);
|
||||
test.assertEquals(2, tags.length);
|
||||
}
|
||||
|
||||
// Execute test's
|
||||
testAddRemoveTag();
|
Reference in New Issue
Block a user