RM-1144, Added max suggestions config, custom properties inclusion and made ui tests more robust

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@63260 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Hibbins
2014-02-25 19:22:40 +00:00
parent 68341737ba
commit 5549dc0925
9 changed files with 363 additions and 83 deletions

View File

@@ -61,6 +61,8 @@ public class DateParameterProcessor extends ParameterProcessor implements Parame
YEAR + SEP + WEEK
};
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@@ -194,6 +196,19 @@ public class DateParameterProcessor extends ParameterProcessor implements Parame
return style;
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
{
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
}
/* (non-Javadoc)
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
*/
@Override
public List<String> getSubstitutionSuggestions(String substitutionFragment)
{
@@ -203,6 +218,10 @@ public class DateParameterProcessor extends ParameterProcessor implements Parame
{
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
suggestions.add(namePrefix + field);
if(suggestions.size() >= maximumNumberSuggestions)
{
break;
}
}
}
else
@@ -212,6 +231,10 @@ public class DateParameterProcessor extends ParameterProcessor implements Parame
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
{
suggestions.add(namePrefix + field);
if(suggestions.size() >= maximumNumberSuggestions)
{
break;
}
}
}
}

View File

@@ -20,12 +20,15 @@ package org.alfresco.repo.action.parameter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
@@ -56,6 +59,8 @@ public class NodeParameterProcessor extends ParameterProcessor implements Parame
DataTypeDefinition.MLTEXT
};
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
/** Node service */
private NodeService nodeService;
@@ -65,6 +70,12 @@ public class NodeParameterProcessor extends ParameterProcessor implements Parame
/** Dictionary service */
private DictionaryService dictionaryService;
/** Records management admin service */
private RecordsManagementAdminService recordsManagementAdminService;
/** List of definitions (aspects and types) to use for substitution suggestions */
private List<QName> suggestionDefinitions = null;
/**
* @param nodeService node service
*/
@@ -89,6 +100,14 @@ public class NodeParameterProcessor extends ParameterProcessor implements Parame
this.dictionaryService = dictionaryService;
}
/**
* @param recordsManagementAdminService Records management admin service
*/
public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
{
this.recordsManagementAdminService = recordsManagementAdminService;
}
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@@ -133,6 +152,30 @@ public class NodeParameterProcessor extends ParameterProcessor implements Parame
return result;
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
{
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
}
/**
* Add suggestion definition to the list used to get properties suggestions from.
*
* @param definition Type or aspect
*/
public void addSuggestionDefinition(QName definition)
{
if(this.suggestionDefinitions == null)
{
this.suggestionDefinitions = Collections.synchronizedList(new ArrayList<QName>());
}
this.suggestionDefinitions.add(definition);
}
/**
* Get a list of node substitution suggestions for the specified fragment.
*
@@ -144,39 +187,108 @@ public class NodeParameterProcessor extends ParameterProcessor implements Parame
@Override
public List<String> getSubstitutionSuggestions(String substitutionFragment)
{
Set<String> suggestionSet = Collections.synchronizedSet(new HashSet<String>());
if(this.suggestionDefinitions != null)
{
for(QName definition : this.suggestionDefinitions)
{
if(getSubstitutionSuggestions(definition, substitutionFragment.toLowerCase(), suggestionSet))
{
break;
}
}
}
List<String> suggestions = new ArrayList<String>();
getSubstitutionSuggestions(RecordsManagementModel.ASPECT_RECORD, substitutionFragment.toLowerCase(), suggestions);
suggestions.addAll(suggestionSet);
Collections.sort(suggestions);
return suggestions;
}
/**
* Get a list of node substitution suggestions for the given aspect specified fragment. Calls itself recursively for
* associated aspects.
* Get a list of node substitution suggestions for the given definition and specified fragment.
*
* @param aspect Aspect to get properties of and the call this method for associated aspects
* @param definitionName Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private void getSubstitutionSuggestions(QName aspect, String substitutionFragment, List<String> suggestions)
private boolean getSubstitutionSuggestions(QName definitionName, String substitutionFragment, Set<String> suggestions)
{
AspectDefinition recordAspect = this.dictionaryService.getAspect(aspect);
Map<QName, PropertyDefinition> properties = recordAspect.getProperties();
for(QName key : properties.keySet())
boolean gotMaximumSuggestions = false;
ClassDefinition definition = this.dictionaryService.getAspect(definitionName);
if(definition == null)
{
PropertyDefinition propertyDefinition = properties.get(key);
QName type = propertyDefinition.getDataType().getName();
if(ArrayUtils.contains(supportedDataTypes, type))
definition = this.dictionaryService.getType(definitionName);
}
if(definition != null)
{
gotMaximumSuggestions = getSubstitutionSuggestionsForDefinition(definition, substitutionFragment, suggestions);
}
if(recordsManagementAdminService.isCustomisable(definitionName) && !gotMaximumSuggestions)
{
gotMaximumSuggestions = processPropertyDefinitions(recordsManagementAdminService.getCustomPropertyDefinitions(definitionName), substitutionFragment, suggestions);
}
return gotMaximumSuggestions;
}
/**
* Get a list of node substitution suggestions for the given definition and specified fragment. Calls itself recursively for
* associated aspects.
*
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean getSubstitutionSuggestionsForDefinition(ClassDefinition definition, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = processPropertyDefinitions(definition.getProperties(), substitutionFragment, suggestions);
if(!gotMaximumSuggestions)
{
for(QName defaultAspect : definition.getDefaultAspectNames())
{
String suggestion = "node." + key.getPrefixString();
if(suggestion.toLowerCase().contains(substitutionFragment))
gotMaximumSuggestions = getSubstitutionSuggestions(defaultAspect, substitutionFragment, suggestions);
if(gotMaximumSuggestions)
{
suggestions.add(suggestion);
break;
}
}
}
for(QName defaultAspect : recordAspect.getDefaultAspectNames())
return gotMaximumSuggestions;
}
/**
* Process the supplied map of property definitions and add the ones that match the supplied fragment to the list of suggestions.
*
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
* @param substitutionFragment Substitution fragment to search for
* @param suggestions The current list of suggestions to which we will add newly found suggestions
*/
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions)
{
boolean gotMaximumSuggestions = false;
if(properties != null)
{
getSubstitutionSuggestions(defaultAspect, substitutionFragment, suggestions);
for(QName key : properties.keySet())
{
PropertyDefinition propertyDefinition = properties.get(key);
QName type = propertyDefinition.getDataType().getName();
if(ArrayUtils.contains(supportedDataTypes, type))
{
String suggestion = getName() + "." + key.getPrefixString();
if(suggestion.toLowerCase().contains(substitutionFragment))
{
if(suggestions.size() < this.maximumNumberSuggestions)
{
suggestions.add(suggestion);
}
else
{
gotMaximumSuggestions = true;
break;
}
}
}
}
}
return gotMaximumSuggestions;
}
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.action.parameter;
import java.util.List;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
/**
* Record metadata bootstrap bean.
* <p>
* This method of bootstrapping record metadata aspects into the RecordService deprecates the
* previous practice of extending rma:recordMetaData.
*
* @author Mark Hibbins
* @since 2.2
*/
public class NodeParameterSuggesterBootstrap
{
/** namespace service */
private NamespaceService namespaceService;
/** map of record metadata aspects against file plan type */
private List<String> nodeParameterProcessorAspectsNames;
/** node parameter processor */
private NodeParameterProcessor nodeParameterProcessor;
/**
* @param recordMetadataAspects map of record metadata aspects against file plan types
*/
public void setNodeParameterProcessorAspects(List<String> nodeParameterProcessorAspectsNames)
{
this.nodeParameterProcessorAspectsNames = nodeParameterProcessorAspectsNames;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param nodeParameterProcessor Node parameter processor
*/
public void setNodeParameterProcessor(NodeParameterProcessor nodeParameterProcessor)
{
this.nodeParameterProcessor = nodeParameterProcessor;
}
/**
* Init method
*/
public void init()
{
ParameterCheck.mandatory("namespaceService", namespaceService);
if (nodeParameterProcessorAspectsNames != null)
{
for (String name : nodeParameterProcessorAspectsNames)
{
// convert to qname and save it
QName aspect = QName.createQName(name, namespaceService);
// register with node parameter processor
this.nodeParameterProcessor.addSuggestionDefinition(aspect);
}
}
}
}

View File

@@ -22,5 +22,7 @@ import java.util.List;
public interface ParameterSubstitutionSuggester
{
final static int DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS = 10;
public List<String> getSubstitutionSuggestions(final String substitutionFragment);
}

View File

@@ -60,8 +60,11 @@ public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
private final static String CREATE_CAPABILITY = "Create";
private final static String VIEW_CAPABILITY = "ViewRecords";
private final static int PATH_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH = 0;
private final static int PATH_SUBSTITUTION_MAXIMUM_NUMBER_RESULTS = 10;
private final static int DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH = 0;
private final static int DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS = 10;
private int pathSubstitutionMaximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS;
private int substitutionMinimumFragmentSize = DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH;
private ParameterProcessorComponent parameterProcessorComponent;
private NodeService nodeService;
@@ -104,6 +107,26 @@ public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
this.capabilityService = capabilityService;
}
/**
* Set the minimum fragment size to process for suggestion processing
*
* @param maximumNumberSuggestions
*/
public void setSubstitutionMinimumFragmentSize(int substitutionMinimumFragmentSize)
{
this.substitutionMinimumFragmentSize = Math.max(substitutionMinimumFragmentSize, DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH);
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setPathSubstitutionMaximumNumberSuggestions(int pathSubstitutionMaximumNumberSuggestions)
{
this.pathSubstitutionMaximumNumberSuggestions = (pathSubstitutionMaximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS: pathSubstitutionMaximumNumberSuggestions);
}
/**
* Return a list of substitutions for the given fragment.
*
@@ -119,8 +142,11 @@ public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
List<String> substitutionSuggestions = new ArrayList<String>();
substitutionSuggestions.addAll(getSubPathSuggestions(req, path, fragment));
substitutionSuggestions.addAll(this.parameterProcessorComponent.getSubstitutionSuggestions(fragment));
if((fragment != null) && (fragment.length() >= this.substitutionMinimumFragmentSize))
{
substitutionSuggestions.addAll(getSubPathSuggestions(req, path, fragment));
substitutionSuggestions.addAll(this.parameterProcessorComponent.getSubstitutionSuggestions(fragment));
}
Map<String, Object> model = new HashMap<String, Object>();
model.put(SUBSTITUTIONS_MODEL_KEY, substitutionSuggestions);
@@ -137,7 +163,7 @@ public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
*/
private List<String> getSubPathSuggestions(WebScriptRequest req, final String path, final String fragment) {
List<String> pathSuggestions = new ArrayList<String>();
if((path != null) && path.startsWith("/") && (fragment != null) && (fragment.length() >= PATH_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH))
if((path != null) && path.startsWith("/") && (fragment != null))
{
String[] pathFragments = path.split("/");
@@ -177,7 +203,7 @@ public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
if((fragment.isEmpty() || fileName.toLowerCase().startsWith(lowerCaseFragment)) && isNodeRefAppropriateForPathSuggestion(childNodeRef))
{
pathSuggestions.add("/" + fileName);
if(pathSuggestions.size() >= PATH_SUBSTITUTION_MAXIMUM_NUMBER_RESULTS)
if(pathSuggestions.size() >= pathSubstitutionMaximumNumberSuggestions)
{
break;
}