RM-591: A records manager can define a rule that creates folders based on a creation strategy

* RM actions can be configured to allow parmater level substitution
 * Paramater processor component added .. resposibile for processing parameters of an RM action and selecting the correct processor
 * Parameter processor framework added .. new processors can be sprung in using the usual pattern
 * 'node' processor added .. allows simple property value substitution based on the actioned upon node
 * 'date' processor added .. allows simple date value substituation
 * 'message' processor added .. allows message bundle value substitution
 * an example substitution parameter could be .. "/${message.my-company.name}/invoices/${date.month.short}"
 * fileTo action is configured to allow parameter substitution .. with the relative path and auto create features as well it is possible to define a rule that creates records folders based on a simple creation strategy .. for example always file into a record folder for this month



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@47262 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2013-02-28 07:21:26 +00:00
parent c626585c1a
commit 81806ae2f9
16 changed files with 770 additions and 126 deletions

View File

@@ -47,6 +47,8 @@ public class FileToActionTest extends BaseRMTestCase
private static final String PATH_BAD = "monkey/rmfolder";
private static final String PATH_CREATE = "rmcontainer/newrmfolder";
private static final String PATH_SUB1 = "rmcontainer/${node.name}";
protected ActionService dmActionService;
@Override
@@ -70,24 +72,7 @@ public class FileToActionTest extends BaseRMTestCase
public void testFileToNodeRef()
{
doTestInTransaction(new Test<Void>()
{
public Void run()
{
// create record from document
recordService.createRecord(filePlan, dmDocument);
// check things have gone according to plan
assertTrue(recordService.isRecord(dmDocument));
assertFalse(recordService.isFiled(dmDocument));
// is the unfiled container the primary parent of the filed record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(filePlanService.getUnfiledContainer(filePlan), parent);
return null;
}
}, dmCollaborator);
initRecord();
doTestInTransaction(new Test<Void>()
{
@@ -118,14 +103,13 @@ public class FileToActionTest extends BaseRMTestCase
return null;
}
}, rmAdminName);
}, rmAdminName);
}
public void testFileToPath()
private void initRecord()
{
doTestInTransaction(new Test<Void>()
{
{
public Void run()
{
// create record from document
@@ -142,6 +126,11 @@ public class FileToActionTest extends BaseRMTestCase
return null;
}
}, dmCollaborator);
}
public void testFileToPath()
{
initRecord();
doTestInTransaction(new Test<Void>()
{
@@ -169,24 +158,7 @@ public class FileToActionTest extends BaseRMTestCase
public void testFileToPath2()
{
doTestInTransaction(new Test<Void>()
{
public Void run()
{
// create record from document
recordService.createRecord(filePlan, dmDocument);
// check things have gone according to plan
assertTrue(recordService.isRecord(dmDocument));
assertFalse(recordService.isFiled(dmDocument));
// is the unfiled container the primary parent of the filed record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(filePlanService.getUnfiledContainer(filePlan), parent);
return null;
}
}, dmCollaborator);
initRecord();
doTestInTransaction(new Test<Void>()
{
@@ -214,38 +186,36 @@ public class FileToActionTest extends BaseRMTestCase
public void testCreate() throws Exception
{
doTestInTransaction(new Test<Void>()
{
public Void run()
{
// create record from document
recordService.createRecord(filePlan, dmDocument);
// check things have gone according to plan
assertTrue(recordService.isRecord(dmDocument));
assertFalse(recordService.isFiled(dmDocument));
// is the unfiled container the primary parent of the filed record
NodeRef parent = nodeService.getPrimaryParent(dmDocument).getParentRef();
assertEquals(filePlanService.getUnfiledContainer(filePlan), parent);
return null;
}
}, dmCollaborator);
initRecord();
createRecord(PATH_CREATE, "newrmfolder");
}
public void testCreateSub() throws Exception
{
initRecord();
createRecord(PATH_SUB1, "collabDocument.txt", "rmcontainer/collabDocument.txt");
}
private void createRecord(String path, String name)
{
createRecord(path, name, path);
}
private void createRecord(final String path, final String name, final String resolvedPath)
{
doTestInTransaction(new Test<Void>()
{
public Void run() throws Exception
{
String[] pathValues = StringUtils.tokenizeToStringArray(PATH_CREATE, "/");
String[] pathValues = StringUtils.tokenizeToStringArray(resolvedPath, "/");
// show the folder doesn' exist to begin with
// show the folder doesn't exist to begin with
FileInfo createdRecordFolder = fileFolderService.resolveNamePath(filePlan, new ArrayList<String>(Arrays.asList(pathValues)), false);
assertNull(createdRecordFolder);
// set parameters
Map<String, Serializable> params = new HashMap<String, Serializable>(1);
params.put(FileToAction.PARAM_PATH, PATH_CREATE);
params.put(FileToAction.PARAM_PATH, path);
params.put(FileToAction.PARAM_CREATE_RECORD_FOLDER, true);
// execute file-to action
@@ -254,7 +224,7 @@ public class FileToActionTest extends BaseRMTestCase
// show the folder has now been created
createdRecordFolder = fileFolderService.resolveNamePath(filePlan, new ArrayList<String>(Arrays.asList(pathValues)), false);
assertNotNull(createdRecordFolder);
assertEquals("newrmfolder", createdRecordFolder.getName());
assertEquals(name, createdRecordFolder.getName());
NodeRef createdRecordFolderNodeRef = createdRecordFolder.getNodeRef();
// check things have gone according to plan
@@ -268,7 +238,6 @@ public class FileToActionTest extends BaseRMTestCase
return null;
}
}, rmAdminName);
}
public void failureTests() throws Exception

View File

@@ -21,6 +21,8 @@ package org.alfresco.module.org_alfresco_module_rm.test.service;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.module.org_alfresco_module_rm.test.util.TestActionPropertySubs;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.security.PermissionService;
@@ -142,4 +144,29 @@ public class ExtendedActionServiceTest extends BaseRMTestCase
return result;
}
public void testActionPropertySubstitution() throws Exception
{
doTestInTransaction(new Test<Void>()
{
public Void run()
{
Action action = dmActionService.createAction(TestActionPropertySubs.NAME);
action.setParameterValue("longMonth", "${date.month.long}");
action.setParameterValue("shortMonth", "${date.month}");
action.setParameterValue("year", "${date.year}");
action.setParameterValue("name", "${node.cm:name}");
action.setParameterValue("company", "${message.test.company}");
action.setParameterValue("combo", "${date.year}/${date.month.short}/${node.cm:name}-${message.test.company}.txt");
dmActionService.executeAction(action, rmFolder);
return null;
}
});
}
}

View File

@@ -34,7 +34,7 @@ public class TestActionParams extends RMActionExecuterAbstractBase
Object dateValue = action.getParameterValue(PARAM_DATE);
if ((dateValue instanceof java.util.Date) == false)
{
throw new AlfrescoRuntimeException("Param we not a Date as expected.");
throw new AlfrescoRuntimeException("Param was not a Date as expected.");
}
}
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (C) 2005-2011 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.module.org_alfresco_module_rm.test.util;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.surf.util.I18NUtil;
public class TestActionPropertySubs extends RMActionExecuterAbstractBase
{
public static final String NAME = "testActionPropertySubs";
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl("shortMonth", DataTypeDefinition.TEXT, false, ""));
paramList.add(new ParameterDefinitionImpl("longMonth", DataTypeDefinition.TEXT, false, ""));
paramList.add(new ParameterDefinitionImpl("year", DataTypeDefinition.TEXT, false, ""));
paramList.add(new ParameterDefinitionImpl("name", DataTypeDefinition.TEXT, false, ""));
paramList.add(new ParameterDefinitionImpl("company", DataTypeDefinition.TEXT, false, ""));
paramList.add(new ParameterDefinitionImpl("combo", DataTypeDefinition.TEXT, false, ""));
}
@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
Calendar myToday = Calendar.getInstance();
String shortMonth = myToday.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
String longMonth = myToday.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
String year = Integer.toString(myToday.get(Calendar.YEAR));
String name = (String)nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);
String company = I18NUtil.getMessage("test.company");
assertEquals(shortMonth, (String)action.getParameterValue("shortMonth"));
assertEquals(longMonth, (String)action.getParameterValue("longMonth"));
assertEquals(year, (String)action.getParameterValue("year"));
assertEquals(name, (String)action.getParameterValue("name"));
assertEquals(company, (String)action.getParameterValue("company"));
assertEquals(year + "/" + shortMonth + "/" + name + "-" + company +".txt", (String)action.getParameterValue("combo"));
}
private void assertEquals(String expected, String actual)
{
if (expected.equals(actual) == false)
{
throw new AlfrescoRuntimeException("Expected value " + expected + " does not match actual value " + actual);
}
}
}