mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-1144 & RM-1145 - changes to file to action
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@61046 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -15,6 +15,7 @@ import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.search.CategoryService;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -32,14 +33,14 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
/** action parameters */
|
||||
public static final String PARAM_DESTINATION_RECORD_FOLDER = "destinationRecordFolder";
|
||||
public static final String PARAM_PATH = "path";
|
||||
public static final String PARAM_CREATE_RECORD_FOLDER = "createRecordFolder";
|
||||
public static final String PARAM_CREATE_RECORD_PATH = "createRecordPath";
|
||||
|
||||
/** file folder service */
|
||||
private FileFolderService fileFolderService;
|
||||
|
||||
/** file plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
|
||||
/**
|
||||
* @param fileFolderService file folder service
|
||||
*/
|
||||
@@ -63,7 +64,7 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
|
||||
{
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_PATH)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_CREATE_RECORD_FOLDER, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_CREATE_RECORD_FOLDER)));
|
||||
paramList.add(new ParameterDefinitionImpl(PARAM_CREATE_RECORD_PATH, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_CREATE_RECORD_PATH)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +142,7 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
|
||||
// look for the creation strategy
|
||||
boolean create = false;
|
||||
Boolean createValue = (Boolean)action.getParameterValue(PARAM_CREATE_RECORD_FOLDER);
|
||||
Boolean createValue = (Boolean)action.getParameterValue(PARAM_CREATE_RECORD_PATH);
|
||||
if (createValue != null)
|
||||
{
|
||||
create = createValue.booleanValue();
|
||||
@@ -155,7 +156,7 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
if (create == true)
|
||||
{
|
||||
// get the parent into which we are going to create the new record folder
|
||||
NodeRef parent = resolveParent(context, pathValues);
|
||||
NodeRef parent = resolveParent(context, pathValues, create);
|
||||
if (parent == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to create new record folder, because destination parent could not be found.");
|
||||
@@ -187,12 +188,43 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
* @return
|
||||
*/
|
||||
private NodeRef resolvePath(final NodeRef context, final String[] pathValues)
|
||||
{
|
||||
return resolvePath(context, pathValues, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param pathValues
|
||||
* @param create Create any missing path elements
|
||||
* @return
|
||||
*/
|
||||
private NodeRef resolvePath(final NodeRef context, final String[] pathValues, boolean create)
|
||||
{
|
||||
NodeRef result = null;
|
||||
FileInfo fileInfo = null;
|
||||
try
|
||||
{
|
||||
fileInfo = fileFolderService.resolveNamePath(context, new ArrayList<String>(Arrays.asList(pathValues)), false);
|
||||
List<String> pathValueList = new ArrayList<String>(Arrays.asList(pathValues));
|
||||
fileInfo = fileFolderService.resolveNamePath(context, pathValueList, false);
|
||||
if((fileInfo == null) && create)
|
||||
{
|
||||
NodeRef parent = this.filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
|
||||
for(int i = 1; i <= pathValueList.size(); i++)
|
||||
{
|
||||
List<String> partialPathValueList = pathValueList.subList(0, i);
|
||||
fileInfo = fileFolderService.resolveNamePath(context, partialPathValueList, false);
|
||||
if(fileInfo == null)
|
||||
{
|
||||
parent = this.filePlanService.createRecordCategory(parent, partialPathValueList.get(partialPathValueList.size() - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
parent = fileInfo.getNodeRef();
|
||||
}
|
||||
}
|
||||
result = parent;
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
@@ -212,6 +244,18 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
* @return
|
||||
*/
|
||||
private NodeRef resolveParent(NodeRef context, String[] pathValues)
|
||||
{
|
||||
return resolveParent(context, pathValues, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param pathValues
|
||||
* @param create Create any missing path elements
|
||||
* @return
|
||||
*/
|
||||
private NodeRef resolveParent(NodeRef context, String[] pathValues, boolean create)
|
||||
{
|
||||
NodeRef result = null;
|
||||
|
||||
@@ -229,7 +273,7 @@ public class FileToAction extends RMActionExecuterAbstractBase
|
||||
else
|
||||
{
|
||||
pathValues = (String[])ArrayUtils.remove(pathValues, pathValues.length-1);
|
||||
result = resolvePath(context, pathValues);
|
||||
result = resolvePath(context, pathValues, create);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -19,7 +19,9 @@
|
||||
package org.alfresco.repo.action.parameter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -30,7 +32,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DateParameterProcessor extends ParameterProcessor
|
||||
public class DateParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
|
||||
{
|
||||
private static final String DAY = "day";
|
||||
private static final String WEEK = "week";
|
||||
@@ -39,6 +41,27 @@ public class DateParameterProcessor extends ParameterProcessor
|
||||
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
|
||||
};
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
@@ -172,4 +195,28 @@ public class DateParameterProcessor extends ParameterProcessor
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubstitutionSuggestions(String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
String namePrefix = this.getName() + ".";
|
||||
if(this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
suggestions.add(namePrefix + field);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
String prefixFieldName = namePrefix + field;
|
||||
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
suggestions.add(namePrefix + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,9 @@
|
||||
package org.alfresco.repo.action.parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -28,6 +30,7 @@ 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
|
||||
@@ -35,13 +38,15 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ParameterProcessorComponent
|
||||
public class ParameterProcessorComponent implements ParameterSubstitutionSuggester
|
||||
{
|
||||
/** regex used to parse parameters */
|
||||
private static final String REG_EX = "\\$\\{([^\\$\\{]+)\\}";
|
||||
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
|
||||
@@ -51,6 +56,10 @@ public class ParameterProcessorComponent
|
||||
public void register(ParameterProcessor processor)
|
||||
{
|
||||
this.processors.put(processor.getName(), processor);
|
||||
if(processor instanceof ParameterSubstitutionSuggester)
|
||||
{
|
||||
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,9 +92,14 @@ public class ParameterProcessorComponent
|
||||
* @return String resulting value
|
||||
*/
|
||||
public String process(String value, NodeRef nodeRef)
|
||||
{
|
||||
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(REG_EX);
|
||||
Pattern patt = Pattern.compile(regExp);
|
||||
Matcher m = patt.matcher(value);
|
||||
StringBuffer sb = new StringBuffer(value.length());
|
||||
|
||||
@@ -112,6 +126,25 @@ public class ParameterProcessorComponent
|
||||
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)
|
||||
{
|
||||
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up parameter processor
|
||||
*
|
||||
|
Reference in New Issue
Block a user