diff --git a/config/alfresco/action-services-context.xml b/config/alfresco/action-services-context.xml index 7895119e3e..f43df485a0 100644 --- a/config/alfresco/action-services-context.xml +++ b/config/alfresco/action-services-context.xml @@ -212,6 +212,12 @@ + + + + + + false diff --git a/config/alfresco/messages/action-config.properties b/config/alfresco/messages/action-config.properties index b9b828cfa1..8fdbf0cd38 100644 --- a/config/alfresco/messages/action-config.properties +++ b/config/alfresco/messages/action-config.properties @@ -40,6 +40,9 @@ compare-integer-property.description=Compare an integer property of the metadata compare-text-property.title=Items with specific text value in property compare-text-property.description=Compare a text property of the metadata, aspect or type +has-tag.title=Has a tag +has-tag.description=Has a tag been applied to a node. +has-tag.tag.display-label=Tag # Actions add-features.title=Add aspect to item diff --git a/source/java/org/alfresco/repo/action/evaluator/HasAspectEvaluatorTest.java b/source/java/org/alfresco/repo/action/evaluator/HasAspectEvaluatorTest.java index 2059ac2a8a..1a009cf0ea 100644 --- a/source/java/org/alfresco/repo/action/evaluator/HasAspectEvaluatorTest.java +++ b/source/java/org/alfresco/repo/action/evaluator/HasAspectEvaluatorTest.java @@ -49,6 +49,7 @@ public class HasAspectEvaluatorTest extends BaseSpringTest private final static String ID = GUID.generate(); + @SuppressWarnings("deprecation") @Override protected void onSetUpInTransaction() throws Exception { diff --git a/source/java/org/alfresco/repo/action/evaluator/HasTagEvaluator.java b/source/java/org/alfresco/repo/action/evaluator/HasTagEvaluator.java new file mode 100644 index 0000000000..9927006ca7 --- /dev/null +++ b/source/java/org/alfresco/repo/action/evaluator/HasTagEvaluator.java @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.action.evaluator; + +import java.util.List; + +import org.alfresco.repo.action.ParameterDefinitionImpl; +import org.alfresco.service.cmr.action.ActionCondition; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.dictionary.DataTypeDefinition; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.tagging.TaggingService; +import org.alfresco.service.namespace.QName; + +/** + * Has tag evaluator + * + * @author Roy Wetherall + */ +public class HasTagEvaluator extends ActionConditionEvaluatorAbstractBase +{ + /** + * Evaluator constants + */ + public static final String NAME = "has-tag"; + public static final String PARAM_TAG = "tag"; + + /** The node service */ + private NodeService nodeService; + + /** The tag service */ + private TaggingService taggingService; + + /** + * Set node service + * + * @param nodeService the node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * Set tagging service + * + * @param taggingService the tagging service + */ + public void setTaggingService(TaggingService taggingService) + { + this.taggingService = taggingService; + } + + /** + * @see org.alfresco.repo.action.evaluator.ActionConditionEvaluatorAbstractBase#evaluateImpl(org.alfresco.service.cmr.action.ActionCondition, org.alfresco.service.cmr.repository.NodeRef) + */ + public boolean evaluateImpl(ActionCondition ruleCondition, NodeRef actionedUponNodeRef) + { + boolean result = false; + + if (this.nodeService.exists(actionedUponNodeRef) == true) + { + String tag = (String)ruleCondition.getParameterValue(PARAM_TAG); + result = taggingService.hasTag(actionedUponNodeRef, tag); + } + + return result; + } + + /** + * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List) + */ + @Override + protected void addParameterDefinitions(List paramList) + { + paramList.add(new ParameterDefinitionImpl(PARAM_TAG, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TAG))); + } + +} diff --git a/source/java/org/alfresco/repo/action/evaluator/HasTagEvaluatorTest.java b/source/java/org/alfresco/repo/action/evaluator/HasTagEvaluatorTest.java new file mode 100644 index 0000000000..9624c4f131 --- /dev/null +++ b/source/java/org/alfresco/repo/action/evaluator/HasTagEvaluatorTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.action.evaluator; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.ActionConditionImpl; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.tagging.TaggingServiceImplTest; +import org.alfresco.service.cmr.action.ActionCondition; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.repository.StoreRef; +import org.alfresco.service.cmr.tagging.TaggingService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; +import org.alfresco.util.BaseSpringTest; +import org.alfresco.util.GUID; + +/** + * Has tag evaluator unit test + * + * @author Roy Wetherall + */ +public class HasTagEvaluatorTest extends BaseSpringTest +{ + private NodeService nodeService; + private TaggingService taggingService; + private StoreRef testStoreRef; + private NodeRef rootNodeRef; + private NodeRef nodeRef; + private HasTagEvaluator evaluator; + + private final static String ID = GUID.generate(); + + @SuppressWarnings("deprecation") + @Override + protected void onSetUpInTransaction() throws Exception + { + this.nodeService = (NodeService)applicationContext.getBean("nodeService"); + this.taggingService = (TaggingService)applicationContext.getBean("taggingService"); + + // Create the store and get the root node + this.testStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"); + this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef); + + // Create the node used for tests + this.nodeRef = this.nodeService.createNode( + this.rootNodeRef, + ContentModel.ASSOC_CHILDREN, + QName.createQName("{test}testnode"), + ContentModel.TYPE_CONTENT).getChildRef(); + + this.evaluator = (HasTagEvaluator)applicationContext.getBean(HasTagEvaluator.NAME); + AuthenticationUtil.setFullyAuthenticatedUser("admin"); + } + + public void testPass() + { + taggingService.addTag(nodeRef, "testTag"); + ActionCondition condition = new ActionConditionImpl(ID, HasTagEvaluator.NAME, null); + condition.setParameterValue(HasTagEvaluator.PARAM_TAG, "testTag"); + boolean value = this.evaluator.evaluate(condition, this.nodeRef); + assertTrue("Tag should have been set", value); + } + + public void testFail() + { + ActionCondition condition = new ActionConditionImpl(ID, HasTagEvaluator.NAME, null); + condition.setParameterValue(HasTagEvaluator.PARAM_TAG, "testTag"); + boolean value = this.evaluator.evaluate(condition, this.nodeRef); + assertFalse(value); + } +} diff --git a/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java b/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java index 8fa49f07bb..023f87b9ac 100644 --- a/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java +++ b/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java @@ -347,6 +347,15 @@ public class TaggingServiceImpl implements TaggingService, return result; } + /** + * @see org.alfresco.service.cmr.tagging.TaggingService#hasTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) + */ + public boolean hasTag(NodeRef nodeRef, String tag) + { + List tags = getTags(nodeRef); + return (tags.contains(tag.toLowerCase())); + } + /** * @see org.alfresco.service.cmr.tagging.TaggingService#addTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String) */ diff --git a/source/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java b/source/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java index 9a5e60022e..77513bf97c 100644 --- a/source/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java +++ b/source/java/org/alfresco/repo/tagging/TaggingServiceImplTest.java @@ -263,6 +263,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest List tags = this.taggingService.getTags(this.document); assertNotNull(tags); assertTrue(tags.isEmpty()); + assertFalse(taggingService.hasTag(document, TAG_1)); assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_1)); this.taggingService.addTag(this.document, TAG_1); @@ -271,6 +272,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest assertNotNull(tags); assertEquals(1, tags.size()); assertTrue(tags.contains(TAG_1)); + assertTrue(taggingService.hasTag(document, TAG_1)); assertFalse(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_2)); this.taggingService.addTag(this.document, TAG_2); @@ -280,14 +282,18 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest assertNotNull(tags); assertEquals(2, tags.size()); assertTrue(tags.contains(TAG_1)); - assertTrue(tags.contains(TAG_2)); + assertTrue(tags.contains(TAG_2)); + assertTrue(taggingService.hasTag(document, TAG_1)); + assertTrue(taggingService.hasTag(document, TAG_2)); this.taggingService.removeTag(this.document, TAG_1); tags = this.taggingService.getTags(this.document); assertNotNull(tags); assertEquals(1, tags.size()); assertFalse(tags.contains(TAG_1)); - assertTrue(tags.contains(TAG_2)); + assertFalse(taggingService.hasTag(document, TAG_1)); + assertTrue(tags.contains(TAG_2)); + assertTrue(taggingService.hasTag(document, TAG_2)); List setTags = new ArrayList(2); setTags.add(TAG_3); diff --git a/source/java/org/alfresco/service/cmr/tagging/TaggingService.java b/source/java/org/alfresco/service/cmr/tagging/TaggingService.java index 65fea19568..378e082462 100644 --- a/source/java/org/alfresco/service/cmr/tagging/TaggingService.java +++ b/source/java/org/alfresco/service/cmr/tagging/TaggingService.java @@ -77,6 +77,15 @@ public interface TaggingService */ void deleteTag(StoreRef storeRef, String tag); + /** + * Indicates whether a node has the specified tag or not. + * + * @param nodeRef node reference + * @param tag tag name + * @return boolean true if the node has the tag, false otherwise + */ + boolean hasTag(NodeRef nodeRef, String tag); + /** * Add a tag to a node. Creating the tag if it does not already exist. *