Added various action parameter contraint implementations.

These include type, aspect, property, mimetype, email templates and scripts.  Constraint results unit tested.

TODO - still need to go through all the actions and link each constraint to the appropraite properties.



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18692 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-02-18 04:51:04 +00:00
parent 32391cd26c
commit 9c665eb78d
12 changed files with 549 additions and 77 deletions

View File

@@ -147,10 +147,40 @@
<property name="actionService" ref="actionService"/>
</bean>
<bean id="compare-operations" class="org.alfresco.repo.action.constraint.EnumParameterConstraint" parent="action-constraint">
<bean id="ac-compare-operations" class="org.alfresco.repo.action.constraint.EnumParameterConstraint" parent="action-constraint">
<property name="enumClassName" value="org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation" />
</bean>
<bean id="ac-mimetypes" class="org.alfresco.repo.action.constraint.MimetypeParameterConstraint" parent="action-constraint">
<property name="mimetypeMap" ref="mimetypeService"/>
</bean>
<bean id="ac-types" class="org.alfresco.repo.action.constraint.TypeParameterConstraint" parent="action-constraint">
<property name="dictionaryService" ref="dictionaryService"/>
</bean>
<bean id="ac-aspects" class="org.alfresco.repo.action.constraint.AspectParameterConstraint" parent="action-constraint">
<property name="dictionaryService" ref="dictionaryService"/>
</bean>
<bean id="ac-properties" class="org.alfresco.repo.action.constraint.PropertyParameterConstraint" parent="action-constraint">
<property name="dictionaryService" ref="dictionaryService"/>
</bean>
<bean id="ac-email-templates" class="org.alfresco.repo.action.constraint.FolderContentsParameterConstraint" parent="action-constraint">
<property name="dictionaryService" ref="dictionaryService"/>
<property name="searchService" ref="searchService"/>
<property name="nodeService" ref="nodeService"/>
<property name="searchPath" value="/app:company_home/app:dictionary/app:email_templates"/>
</bean>
<bean id="ac-scripts" class="org.alfresco.repo.action.constraint.FolderContentsParameterConstraint" parent="action-constraint">
<property name="dictionaryService" ref="dictionaryService"/>
<property name="searchService" ref="searchService"/>
<property name="nodeService" ref="nodeService"/>
<property name="searchPath" value="/app:company_home/app:dictionary/app:scripts"/>
</bean>
<!-- Action Conditions -->
<bean id="action-condition-evaluator" abstract="true" init-method="init">

View File

@@ -1,12 +1,12 @@
# Action constraints
compare-operations.equals=Equals
compare-operations.contains=Contains
compare-operations.begins=Begins With
compare-operations.ends=Ends With
compare-operations.greater_than=Greater Than
compare-operations.greater_than_equal=Greater Than Or Equal To
compare-operations.less_than=Less Than
compare-operations.less_than_equal=Less Than Or Equal To
# Action parameter constraints
ac-compare-operations.equals=Equals
ac-compare-operations.contains=Contains
ac-compare-operations.begins=Begins With
ac-compare-operations.ends=Ends With
ac-compare-operations.greater_than=Greater Than
ac-compare-operations.greater_than_equal=Greater Than Or Equal To
ac-compare-operations.less_than=Less Than
ac-compare-operations.less_than_equal=Less Than Or Equal To
# Action conditions

View File

@@ -39,7 +39,7 @@ import org.alfresco.util.BaseSpringTest;
*/
public class ActionParameterConstraintTest extends BaseSpringTest
{
private static final String COMPARE_OP = "compare-operations";
private static final String COMPARE_OP = "ac-compare-operations";
private ActionService actionService;
@@ -84,4 +84,29 @@ public class ActionParameterConstraintTest extends BaseSpringTest
System.out.println(entry.getKey() + " - " + entry.getValue());
}
}
public void testConstraints()
{
testConstraint("ac-aspects");
testConstraint("ac-types");
testConstraint("ac-properties");
testConstraint("ac-mimetypes");
testConstraint("ac-email-templates");
testConstraint("ac-scripts");
}
private void testConstraint(String name)
{
ParameterConstraint constraint = actionService.getParameterConstraint(name);
assertNotNull(constraint);
assertEquals(name, constraint.getName());
Map<String, String> values = constraint.getAllowableValues();
assertTrue(values.size()>0);
System.out.println("== " + name + " ==\n");
for (Map.Entry<String, String> entry : values.entrySet())
{
System.out.println(entry.getKey() + " - " + entry.getValue());
}
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2009-2009 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 received 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.constraint;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.QName;
/**
* Type parameter constraint
*
* @author Roy Wetherall
*/
public class AspectParameterConstraint extends BaseParameterConstraint
{
/** Name constant */
public static final String NAME = "ac-aspects";
private DictionaryService dictionaryService;
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
protected Map<String, String> getAllowableValuesImpl()
{
Collection<QName> aspects = dictionaryService.getAllAspects();
Map<String, String> result = new HashMap<String, String>(aspects.size());
for (QName aspect : aspects)
{
AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
if (aspectDef != null && aspectDef.getTitle() != null)
{
result.put(aspect.toPrefixString(), aspectDef.getTitle());
}
}
return result;
}
}

View File

@@ -25,9 +25,12 @@
package org.alfresco.repo.action.constraint;
import java.util.Map;
import org.alfresco.repo.action.RuntimeActionService;
import org.alfresco.service.cmr.action.ParameterConstraint;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Base implementation of a parameter constraint
@@ -43,6 +46,9 @@ public abstract class BaseParameterConstraint implements ParameterConstraint,
/** Runtime action service */
protected RuntimeActionService actionService;
/** Map of allowable values */
protected Map<String, String> allowableValues;
/**
* Init method
*/
@@ -76,4 +82,60 @@ public abstract class BaseParameterConstraint implements ParameterConstraint,
{
this.name = name;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
public Map<String, String> getAllowableValues()
{
if (this.allowableValues == null)
{
this.allowableValues = getAllowableValuesImpl();
}
return this.allowableValues;
}
/**
* Gets the list of allowable values, calculating them every time it is called.
*
* @return Map<String, String> map of allowable values
*/
protected abstract Map<String, String> getAllowableValuesImpl();
/**
* Get the I18N display label for a particular key
*
* @param key
* @return String I18N value
*/
protected String getI18NLabel(String key)
{
String result = key.toString();
StringBuffer longKey = new StringBuffer(name).
append(".").
append(key.toString().toLowerCase());
String i18n = I18NUtil.getMessage(longKey.toString());
if (i18n != null)
{
result = i18n;
}
return result;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getValueDisplayLabel(java.io.Serializable)
*/
public String getValueDisplayLabel(String value)
{
return getAllowableValues().get(value);
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#isValidValue(java.io.Serializable)
*/
public boolean isValidValue(String value)
{
return getAllowableValues().containsKey(value);
}
}

View File

@@ -29,7 +29,6 @@ import java.util.HashMap;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Enumerated type parameter constraint
@@ -44,9 +43,6 @@ public class EnumParameterConstraint extends BaseParameterConstraint
/** Enum clss */
private Class<?> enumClass;
/** Map of allowable values */
private Map<String, String> allowableValues;
/**
* Set the enum class name
*
@@ -60,27 +56,24 @@ public class EnumParameterConstraint extends BaseParameterConstraint
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
public Map<String, String> getAllowableValues()
protected Map<String, String> getAllowableValuesImpl()
{
if (this.allowableValues == null)
// Get the enum class
Class<?> enumClass = getEnumClass();
Object[] enumValues = enumClass.getEnumConstants();
Map<String, String> allowableValues = new HashMap<String, String>(enumValues.length);
for (Object enumValue : enumValues)
{
// Get the enum class
Class<?> enumClass = getEnumClass();
// Look up the I18N value
String displayLabel = getI18NLabel(enumValue.toString());
Object[] enumValues = enumClass.getEnumConstants();
this.allowableValues = new HashMap<String, String>(enumValues.length);
for (Object enumValue : enumValues)
{
// Look up the I18N value
String displayLabel = getI18NLabel(enumClass.getName(), enumValue);
// Add to the map of allowed values
this.allowableValues.put(enumValue.toString(), displayLabel);
}
// Add to the map of allowed values
allowableValues.put(enumValue.toString(), displayLabel);
}
return this.allowableValues;
return allowableValues;
}
/**
@@ -116,41 +109,4 @@ public class EnumParameterConstraint extends BaseParameterConstraint
}
return this.enumClass;
}
/**
* Get the I18N display label for a particular enum value
*
* @param enumClassName
* @param enumValue
* @return
*/
private String getI18NLabel(String enumClassName, Object enumValue)
{
String result = enumValue.toString();
StringBuffer key = new StringBuffer(name).
append(".").
append(enumValue.toString().toLowerCase());
String i18n = I18NUtil.getMessage(key.toString());
if (i18n != null)
{
result = i18n;
}
return result;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getValueDisplayLabel(java.io.Serializable)
*/
public String getValueDisplayLabel(String value)
{
return getAllowableValues().get(value);
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#isValidValue(java.io.Serializable)
*/
public boolean isValidValue(String value)
{
return getAllowableValues().containsKey(value);
}
}

View File

@@ -0,0 +1,121 @@
/*
* Copyright (C) 2009-2009 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 received 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.constraint;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
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.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
/**
* Folder contents parameter constraint
*
* @author Roy Wetherall
*/
public class FolderContentsParameterConstraint extends BaseParameterConstraint
{
private NodeService nodeService;
private SearchService searchService;
private DictionaryService dictionaryService;
private String searchPath;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSearchService(SearchService searchService)
{
this.searchService = searchService;
}
public void setSearchPath(String searchPath)
{
this.searchPath = searchPath;
}
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
protected Map<String, String> getAllowableValuesImpl()
{
ResultSet resultSet = searchService.query(
StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
SearchService.LANGUAGE_LUCENE,
"PATH:\"" + searchPath + "\"");
NodeRef rootFolder = null;
if (resultSet.length() == 0)
{
throw new AlfrescoRuntimeException("The path '" + searchPath + "' did not return any results.");
}
else
{
rootFolder = resultSet.getNodeRef(0);
}
Map<String, String> result = new HashMap<String, String>(23);
buildMap(result, rootFolder);
return result;
}
private void buildMap(Map<String, String> result, NodeRef folderNodeRef)
{
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(folderNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
for (ChildAssociationRef assoc : assocs)
{
NodeRef nodeRef = assoc.getChildRef();
QName className = nodeService.getType(nodeRef);
if (dictionaryService.isSubClass(className, ContentModel.TYPE_CONTENT) == true)
{
result.put(nodeRef.toString(),
(String)nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE));
}
else if (dictionaryService.isSubClass(className, ContentModel.TYPE_FOLDER) == true)
{
buildMap(result, nodeRef);
}
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2009-2009 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 received 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.constraint;
import java.util.Map;
import org.alfresco.repo.content.MimetypeMap;
/**
* Mimetype parameter constraint
*
* @author Roy Wetherall
*/
public class MimetypeParameterConstraint extends BaseParameterConstraint
{
/** Name constant */
public static final String NAME = "ac-mimetypes";
/** Mimetype map */
private MimetypeMap mimetypeMap;
/**
* Sets the mimetype map
*
* @param mimetypeMap
*/
public void setMimetypeMap(MimetypeMap mimetypeMap)
{
this.mimetypeMap = mimetypeMap;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
protected Map<String, String> getAllowableValuesImpl()
{
return mimetypeMap.getDisplaysByMimetype();
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2009-2009 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 received 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.constraint;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
/**
* Type parameter constraint
*
* @author Roy Wetherall
*/
public class PropertyParameterConstraint extends BaseParameterConstraint
{
/** Name constant */
public static final String NAME = "ac-properties";
private DictionaryService dictionaryService;
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
protected Map<String, String> getAllowableValuesImpl()
{
Collection<QName> properties = dictionaryService.getAllProperties(null);
Map<String, String> result = new HashMap<String, String>(properties.size());
for (QName property : properties)
{
PropertyDefinition propertyDef = dictionaryService.getProperty(property);
if (propertyDef != null && propertyDef.getTitle() != null)
{
result.put(property.toPrefixString(), propertyDef.getTitle());
}
}
return result;
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (C) 2009-2009 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 received 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.constraint;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.namespace.QName;
/**
* Type parameter constraint
*
* @author Roy Wetherall
*/
public class TypeParameterConstraint extends BaseParameterConstraint
{
/** Name constant */
public static final String NAME = "ac-types";
private DictionaryService dictionaryService;
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.service.cmr.action.ParameterConstraint#getAllowableValues()
*/
protected Map<String, String> getAllowableValuesImpl()
{
Collection<QName> types = dictionaryService.getAllTypes();
Map<String, String> result = new HashMap<String, String>(types.size());
for (QName type : types)
{
TypeDefinition typeDef = dictionaryService.getType(type);
if (typeDef != null && typeDef.getTitle() != null)
{
result.put(type.toPrefixString(), typeDef.getTitle());
}
}
return result;
}
}

View File

@@ -34,7 +34,6 @@ import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.evaluator.compare.ComparePropertyValueOperation;
import org.alfresco.repo.action.evaluator.compare.ContentPropertyName;
import org.alfresco.repo.action.evaluator.compare.PropertyValueComparator;
import org.alfresco.repo.node.integrity.IntegrityChecker;
import org.alfresco.service.cmr.action.ActionCondition;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.action.ParameterDefinition;
@@ -42,7 +41,6 @@ import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -164,7 +162,7 @@ public class ComparePropertyValueEvaluator extends ActionConditionEvaluatorAbstr
paramList.add(new ParameterDefinitionImpl(PARAM_PROPERTY, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_PROPERTY)));
paramList.add(new ParameterDefinitionImpl(PARAM_CONTENT_PROPERTY, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_CONTENT_PROPERTY)));
paramList.add(new ParameterDefinitionImpl(PARAM_VALUE, DataTypeDefinition.ANY, true, getParamDisplayLabel(PARAM_VALUE)));
paramList.add(new ParameterDefinitionImpl(PARAM_OPERATION, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_OPERATION), false, "compare-operations"));
paramList.add(new ParameterDefinitionImpl(PARAM_OPERATION, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_OPERATION), false, "ac-compare-operations"));
}
/**

View File

@@ -86,7 +86,7 @@ public class HasAspectEvaluator extends ActionConditionEvaluatorAbstractBase
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASPECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASPECT), false, "ac-aspects"));
}
}