mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-1144 & RM-1145 - changes to file to action - post review changes
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@61188 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Date parameter processor.
|
||||
@@ -41,26 +42,18 @@ public class DateParameterProcessor extends ParameterProcessor implements Parame
|
||||
private static final String SHORT = "short";
|
||||
private static final String LONG = "long";
|
||||
private static final String NUMBER = "number";
|
||||
|
||||
|
||||
private static final String SEP = ".";
|
||||
|
||||
private static final String[] ALL_FIELDS_FOR_SUBSTITUTION_QUERY = {
|
||||
DAY,
|
||||
DAY + SEP + SHORT,
|
||||
DAY + SEP + LONG,
|
||||
DAY + SEP + NUMBER,
|
||||
WEEK,
|
||||
WEEK + SEP + SHORT,
|
||||
WEEK + SEP + LONG,
|
||||
WEEK + SEP + NUMBER,
|
||||
MONTH,
|
||||
MONTH + SEP + SHORT,
|
||||
MONTH + SEP + LONG,
|
||||
MONTH + SEP + NUMBER,
|
||||
YEAR,
|
||||
YEAR + SEP + SHORT,
|
||||
YEAR + SEP + LONG,
|
||||
YEAR + SEP + NUMBER
|
||||
|
||||
private static final String[] ALL_FIELDS_FOR_SUBSTITUTION_QUERY = {
|
||||
DAY + SEP + SHORT,
|
||||
DAY + SEP + LONG,
|
||||
DAY + SEP + NUMBER,
|
||||
MONTH + SEP + SHORT,
|
||||
MONTH + SEP + LONG,
|
||||
MONTH + SEP + NUMBER,
|
||||
YEAR + SEP + SHORT,
|
||||
YEAR + SEP + LONG
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -201,7 +194,7 @@ public class DateParameterProcessor extends ParameterProcessor implements Parame
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
String namePrefix = this.getName() + ".";
|
||||
if(this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
if(StringUtils.isBlank(substitutionFragment) || this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
suggestions.add(namePrefix + field);
|
||||
|
@@ -30,11 +30,10 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItem;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Parameter processor component
|
||||
*
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
@@ -43,27 +42,27 @@ public class ParameterProcessorComponent implements ParameterSubstitutionSuggest
|
||||
/** regex used to parse parameters */
|
||||
private static final String REG_EX_OLD = "\\$\\{([^\\$\\{]+)\\}";
|
||||
private static final String REG_EX = "\\{([^\\{]+)\\}";
|
||||
|
||||
|
||||
/** registry of parameter processors */
|
||||
private Map<String, ParameterProcessor> processors = new HashMap<String, ParameterProcessor>(5);
|
||||
private List<ParameterSubstitutionSuggester> subtitutionSuggesterProcessors = new ArrayList<ParameterSubstitutionSuggester>(5);
|
||||
|
||||
|
||||
/**
|
||||
* Register parameter processor
|
||||
*
|
||||
*
|
||||
* @param processor
|
||||
*/
|
||||
public void register(ParameterProcessor processor)
|
||||
{
|
||||
this.processors.put(processor.getName(), processor);
|
||||
if(processor instanceof ParameterSubstitutionSuggester)
|
||||
if(processor instanceof ParameterSubstitutionSuggester)
|
||||
{
|
||||
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param ruleItem
|
||||
* @param ruleItemDefinition
|
||||
* @param actionedUponNodeRef
|
||||
@@ -72,21 +71,21 @@ public class ParameterProcessorComponent implements ParameterSubstitutionSuggest
|
||||
{
|
||||
for (Map.Entry<String, Serializable> entry : ruleItem.getParameterValues().entrySet())
|
||||
{
|
||||
String parameterName = entry.getKey();
|
||||
String parameterName = entry.getKey();
|
||||
Object parameterValue = entry.getValue();
|
||||
|
||||
|
||||
// only sub string property values
|
||||
if (parameterValue != null && parameterValue instanceof String)
|
||||
{
|
||||
// set the updated parameter value
|
||||
ruleItem.setParameterValue(parameterName, process((String)parameterValue, actionedUponNodeRef));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the value for substitution within the context of the provided node.
|
||||
*
|
||||
*
|
||||
* @param value value
|
||||
* @param nodeRef node reference
|
||||
* @return String resulting value
|
||||
@@ -95,18 +94,18 @@ public class ParameterProcessorComponent implements ParameterSubstitutionSuggest
|
||||
{
|
||||
return process(process(value, nodeRef, REG_EX_OLD), nodeRef, REG_EX);
|
||||
}
|
||||
|
||||
|
||||
public String process(String value, NodeRef nodeRef, String regExp)
|
||||
{
|
||||
// match the substitution pattern
|
||||
Pattern patt = Pattern.compile(regExp);
|
||||
Matcher m = patt.matcher(value);
|
||||
StringBuffer sb = new StringBuffer(value.length());
|
||||
|
||||
while (m.find())
|
||||
|
||||
while (m.find())
|
||||
{
|
||||
String text = m.group(1);
|
||||
|
||||
String text = m.group(1);
|
||||
|
||||
// lookup parameter processor to use
|
||||
ParameterProcessor processor = lookupProcessor(text);
|
||||
if (processor == null)
|
||||
@@ -114,47 +113,44 @@ public class ParameterProcessorComponent implements ParameterSubstitutionSuggest
|
||||
throw new AlfrescoRuntimeException("A parameter processor has not been found for the substitution string " + text);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
// process each substitution value
|
||||
text = processor.process(text, nodeRef);
|
||||
}
|
||||
|
||||
|
||||
// append new value
|
||||
m.appendReplacement(sb, Matcher.quoteReplacement(text));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
}
|
||||
m.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a list of substitution suggestions for the passed string fragment.
|
||||
*
|
||||
*
|
||||
* @param subtitutionFragment Text fragment to search on.
|
||||
* @return A list of substitutions that match the substitution fragment.
|
||||
*/
|
||||
public List<String> getSubstitutionSuggestions(final String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
if (StringUtils.isNotBlank(substitutionFragment))
|
||||
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
|
||||
{
|
||||
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
|
||||
{
|
||||
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
|
||||
}
|
||||
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Look up parameter processor
|
||||
*
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private ParameterProcessor lookupProcessor(String value)
|
||||
{
|
||||
ParameterProcessor result = null;
|
||||
|
||||
|
||||
if (value != null && value.isEmpty() == false)
|
||||
{
|
||||
String[] values = value.split("\\.", 2);
|
||||
@@ -164,7 +160,7 @@ public class ParameterProcessorComponent implements ParameterSubstitutionSuggest
|
||||
result = processors.get(values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.substitutionsuggestions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -31,13 +32,14 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
/**
|
||||
* Implementation for Java backed webscript to get substitution suggestions
|
||||
* given a text fragment (e.g. date.month for 'mon').
|
||||
*
|
||||
*
|
||||
* @author Mark Hibbins
|
||||
* @since 2.2
|
||||
*/
|
||||
public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
|
||||
{
|
||||
private final static String FRAGMENT_PARAMETER = "fragment";
|
||||
private final static String PATH_PARAMETER = "path";
|
||||
|
||||
private final static String SUBSTITUTIONS_MODEL_KEY = "substitutions";
|
||||
|
||||
@@ -57,11 +59,25 @@ public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
String fragment = req.getParameter(FRAGMENT_PARAMETER);
|
||||
List<String> substitutionSuggestions = this.parameterProcessorComponent.getSubstitutionSuggestions(fragment);
|
||||
String path = req.getParameter(PATH_PARAMETER);
|
||||
|
||||
List<String> substitutionSuggestions = new ArrayList<String>();
|
||||
|
||||
substitutionSuggestions.addAll(getSubPathSuggestions(path, fragment));
|
||||
substitutionSuggestions.addAll(this.parameterProcessorComponent.getSubstitutionSuggestions(fragment));
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put(SUBSTITUTIONS_MODEL_KEY, substitutionSuggestions);
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
private List<String> getSubPathSuggestions(final String path, final String fragment) {
|
||||
List<String> pathSuggestions = new ArrayList<String>();
|
||||
if(path != null)
|
||||
{
|
||||
// TODO - populate path suggestions
|
||||
}
|
||||
return pathSuggestions;
|
||||
}
|
||||
}
|
@@ -34,7 +34,7 @@ public class DateParameterProcessorTest
|
||||
{
|
||||
|
||||
private DateParameterProcessor dateParameterProcessor;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
@@ -46,80 +46,55 @@ public class DateParameterProcessorTest
|
||||
public void testGetSubstitutionSuggestions_All_01()
|
||||
{
|
||||
List<String> suggestions = this.dateParameterProcessor.getSubstitutionSuggestions("date");
|
||||
assertTrue(suggestions.contains("date.day"));
|
||||
assertTrue(suggestions.contains("date.day.short"));
|
||||
assertTrue(suggestions.contains("date.day.long"));
|
||||
assertTrue(suggestions.contains("date.day.number"));
|
||||
assertTrue(suggestions.contains("date.week"));
|
||||
assertTrue(suggestions.contains("date.week.short"));
|
||||
assertTrue(suggestions.contains("date.week.long"));
|
||||
assertTrue(suggestions.contains("date.week.number"));
|
||||
assertTrue(suggestions.contains("date.month"));
|
||||
assertTrue(suggestions.contains("date.month.short"));
|
||||
assertTrue(suggestions.contains("date.month.long"));
|
||||
assertTrue(suggestions.contains("date.month.number"));
|
||||
assertTrue(suggestions.contains("date.year"));
|
||||
assertTrue(suggestions.contains("date.year.short"));
|
||||
assertTrue(suggestions.contains("date.year.long"));
|
||||
assertTrue(suggestions.contains("date.year.number"));
|
||||
assertEquals(16, suggestions.size());
|
||||
assertEquals(8, suggestions.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubstitutionSuggestions_All_02()
|
||||
{
|
||||
List<String> suggestions = this.dateParameterProcessor.getSubstitutionSuggestions("dat");
|
||||
assertTrue(suggestions.contains("date.day"));
|
||||
assertTrue(suggestions.contains("date.day.short"));
|
||||
assertTrue(suggestions.contains("date.day.long"));
|
||||
assertTrue(suggestions.contains("date.day.number"));
|
||||
assertTrue(suggestions.contains("date.week"));
|
||||
assertTrue(suggestions.contains("date.week.short"));
|
||||
assertTrue(suggestions.contains("date.week.long"));
|
||||
assertTrue(suggestions.contains("date.week.number"));
|
||||
assertTrue(suggestions.contains("date.month"));
|
||||
assertTrue(suggestions.contains("date.month.short"));
|
||||
assertTrue(suggestions.contains("date.month.long"));
|
||||
assertTrue(suggestions.contains("date.month.number"));
|
||||
assertTrue(suggestions.contains("date.year"));
|
||||
assertTrue(suggestions.contains("date.year.short"));
|
||||
assertTrue(suggestions.contains("date.year.long"));
|
||||
assertTrue(suggestions.contains("date.year.number"));
|
||||
assertEquals(16, suggestions.size());
|
||||
assertEquals(8, suggestions.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubstitutionSuggestions_All_03()
|
||||
{
|
||||
List<String> suggestions = this.dateParameterProcessor.getSubstitutionSuggestions("at");
|
||||
assertTrue(suggestions.contains("date.day"));
|
||||
assertTrue(suggestions.contains("date.day.short"));
|
||||
assertTrue(suggestions.contains("date.day.long"));
|
||||
assertTrue(suggestions.contains("date.day.number"));
|
||||
assertTrue(suggestions.contains("date.week"));
|
||||
assertTrue(suggestions.contains("date.week.short"));
|
||||
assertTrue(suggestions.contains("date.week.long"));
|
||||
assertTrue(suggestions.contains("date.week.number"));
|
||||
assertTrue(suggestions.contains("date.month"));
|
||||
assertTrue(suggestions.contains("date.month.short"));
|
||||
assertTrue(suggestions.contains("date.month.long"));
|
||||
assertTrue(suggestions.contains("date.month.number"));
|
||||
assertTrue(suggestions.contains("date.year"));
|
||||
assertTrue(suggestions.contains("date.year.short"));
|
||||
assertTrue(suggestions.contains("date.year.long"));
|
||||
assertTrue(suggestions.contains("date.year.number"));
|
||||
assertEquals(16, suggestions.size());
|
||||
assertEquals(8, suggestions.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubstitutionSuggestions_Partial_01()
|
||||
{
|
||||
List<String> suggestions = this.dateParameterProcessor.getSubstitutionSuggestions("ay");
|
||||
assertTrue(suggestions.contains("date.day"));
|
||||
assertTrue(suggestions.contains("date.day.short"));
|
||||
assertTrue(suggestions.contains("date.day.long"));
|
||||
assertTrue(suggestions.contains("date.day.number"));
|
||||
assertEquals(4, suggestions.size());
|
||||
assertEquals(3, suggestions.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,13 +102,11 @@ public class DateParameterProcessorTest
|
||||
{
|
||||
List<String> suggestions = this.dateParameterProcessor.getSubstitutionSuggestions("on");
|
||||
assertTrue(suggestions.contains("date.day.long"));
|
||||
assertTrue(suggestions.contains("date.week.long"));
|
||||
assertTrue(suggestions.contains("date.month"));
|
||||
assertTrue(suggestions.contains("date.month.short"));
|
||||
assertTrue(suggestions.contains("date.month.long"));
|
||||
assertTrue(suggestions.contains("date.month.number"));
|
||||
assertTrue(suggestions.contains("date.year.long"));
|
||||
assertEquals(7, suggestions.size());
|
||||
assertEquals(5, suggestions.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -84,7 +84,6 @@ public class SubstitutionSuggestionsRestApiTest extends BaseRMWebScriptTestCase
|
||||
{
|
||||
return Arrays.asList(new String[]
|
||||
{
|
||||
"date.month",
|
||||
"date.month.number",
|
||||
"date.month.long",
|
||||
"date.month.short"
|
||||
|
Reference in New Issue
Block a user