mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added "has-tag" action evaluator.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18548 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -212,6 +212,12 @@
|
|||||||
</property>
|
</property>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<bean id="has-tag" class="org.alfresco.repo.action.evaluator.HasTagEvaluator" parent="action-condition-evaluator">
|
||||||
|
<property name="nodeService" ref="nodeService" />
|
||||||
|
<property name="taggingService" ref="taggingService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
|
||||||
<bean id="has-version-history" class="org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator" parent="action-condition-evaluator">
|
<bean id="has-version-history" class="org.alfresco.repo.action.evaluator.HasVersionHistoryEvaluator" parent="action-condition-evaluator">
|
||||||
<property name="publicCondition">
|
<property name="publicCondition">
|
||||||
<value>false</value>
|
<value>false</value>
|
||||||
|
@@ -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.title=Items with specific text value in property
|
||||||
compare-text-property.description=Compare a text property of the metadata, aspect or type
|
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
|
# Actions
|
||||||
|
|
||||||
add-features.title=Add aspect to item
|
add-features.title=Add aspect to item
|
||||||
|
@@ -49,6 +49,7 @@ public class HasAspectEvaluatorTest extends BaseSpringTest
|
|||||||
|
|
||||||
private final static String ID = GUID.generate();
|
private final static String ID = GUID.generate();
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
protected void onSetUpInTransaction() throws Exception
|
protected void onSetUpInTransaction() throws Exception
|
||||||
{
|
{
|
||||||
|
@@ -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<ParameterDefinition> paramList)
|
||||||
|
{
|
||||||
|
paramList.add(new ParameterDefinitionImpl(PARAM_TAG, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TAG)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -347,6 +347,15 @@ public class TaggingServiceImpl implements TaggingService,
|
|||||||
return result;
|
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<String> 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)
|
* @see org.alfresco.service.cmr.tagging.TaggingService#addTag(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@@ -263,6 +263,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
List<String> tags = this.taggingService.getTags(this.document);
|
List<String> tags = this.taggingService.getTags(this.document);
|
||||||
assertNotNull(tags);
|
assertNotNull(tags);
|
||||||
assertTrue(tags.isEmpty());
|
assertTrue(tags.isEmpty());
|
||||||
|
assertFalse(taggingService.hasTag(document, TAG_1));
|
||||||
|
|
||||||
assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_1));
|
assertTrue(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_1));
|
||||||
this.taggingService.addTag(this.document, TAG_1);
|
this.taggingService.addTag(this.document, TAG_1);
|
||||||
@@ -271,6 +272,7 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertNotNull(tags);
|
assertNotNull(tags);
|
||||||
assertEquals(1, tags.size());
|
assertEquals(1, tags.size());
|
||||||
assertTrue(tags.contains(TAG_1));
|
assertTrue(tags.contains(TAG_1));
|
||||||
|
assertTrue(taggingService.hasTag(document, TAG_1));
|
||||||
|
|
||||||
assertFalse(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_2));
|
assertFalse(this.taggingService.isTag(TaggingServiceImplTest.storeRef, TAG_2));
|
||||||
this.taggingService.addTag(this.document, TAG_2);
|
this.taggingService.addTag(this.document, TAG_2);
|
||||||
@@ -280,14 +282,18 @@ public class TaggingServiceImplTest extends BaseAlfrescoSpringTest
|
|||||||
assertNotNull(tags);
|
assertNotNull(tags);
|
||||||
assertEquals(2, tags.size());
|
assertEquals(2, tags.size());
|
||||||
assertTrue(tags.contains(TAG_1));
|
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);
|
this.taggingService.removeTag(this.document, TAG_1);
|
||||||
tags = this.taggingService.getTags(this.document);
|
tags = this.taggingService.getTags(this.document);
|
||||||
assertNotNull(tags);
|
assertNotNull(tags);
|
||||||
assertEquals(1, tags.size());
|
assertEquals(1, tags.size());
|
||||||
assertFalse(tags.contains(TAG_1));
|
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<String> setTags = new ArrayList<String>(2);
|
List<String> setTags = new ArrayList<String>(2);
|
||||||
setTags.add(TAG_3);
|
setTags.add(TAG_3);
|
||||||
|
@@ -77,6 +77,15 @@ public interface TaggingService
|
|||||||
*/
|
*/
|
||||||
void deleteTag(StoreRef storeRef, String tag);
|
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.
|
* Add a tag to a node. Creating the tag if it does not already exist.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user