diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java index db798cf113..244132d031 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java @@ -87,8 +87,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest private final static String DESTINATION_PATH_NOT_RECORD_FOLDER_EXC = "Unable to execute create-record action, because the destination path is not a record folder."; private final static String CLOSED_RECORD_FOLDER_EXC = "You can't add new items to a closed record folder."; private final static String HOLD_NAME = "holdName"; - private final static String RECORD_FOLDER_NAME_ENCODED = "Folder%20With%20Spaces%20In%20Name"; - private final static String RECORD_FOLDER_NAME_DECODED = "Folder With Spaces In Name"; + private final static String RECORD_FOLDER_NAME_WITH_SPACE = "Folder With Spaces In Name"; private UserModel userFillingPermission, userReadOnlyPermission; private SiteModel publicSite; @@ -167,7 +166,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE); closedRecordFolder = createFolder(recordCategory.getId(), getRandomName("closedRecordFolder")); closeFolder(closedRecordFolder.getId()); - recordFolderWithSpacesInName = createFolder(recordCategory.getId(), RECORD_FOLDER_NAME_DECODED); + recordFolderWithSpacesInName = createFolder(recordCategory.getId(), RECORD_FOLDER_NAME_WITH_SPACE); STEP("Create rm users with different permissions on the record category"); userFillingPermission = roleService.createCollaboratorWithRMRoleAndPermission(publicSite, recordCategory, ROLE_RM_POWER_USER, PERMISSION_FILING); @@ -227,17 +226,17 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest /** * Given I am calling the "declare as record" action - * And I provide a valid encoded record folder name in the location parameter + * And I provide a valid record folder name in the location parameter * When I execute the action * Then the document is declared as a record * And is filed to the record folder specified */ @Test - public void declareAndFileToValidEncodedLocationUsingActionsAPI() throws Exception + public void declareAndFileToValidLocationWithSpacesUsingActionsAPI() throws Exception { STEP("Declare document as record with an encoded location parameter value"); getRestAPIFactory().getActionsAPI(userFillingPermission).declareAndFile(testFile, - Utility.buildPath(recordCategory.getName(), RECORD_FOLDER_NAME_ENCODED)); + Utility.buildPath(recordCategory.getName(), RECORD_FOLDER_NAME_WITH_SPACE)); STEP("Verify the declared record is placed in the record folder"); assertTrue(isMatchingRecordInRecordFolder(testFile, recordFolderWithSpacesInName), "Record should be filed to record folder"); diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java index f668e41e28..5e2a86ab73 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java @@ -27,8 +27,6 @@ package org.alfresco.module.org_alfresco_module_rm.action.dm; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import java.util.Arrays; import java.util.List; @@ -127,10 +125,6 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase // resolve destination record folder if path supplied NodeRef destinationRecordFolder = null; String pathParameter = (String) action.getParameterValue(PARAM_PATH); - if (pathParameter != null && !pathParameter.isEmpty()) - { - destinationRecordFolder = resolvePath(filePlan, pathParameter); - } // indicate whether the record should be hidden or not (default not) boolean hideRecord = false; @@ -140,6 +134,11 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase hideRecord = hideRecordValue.booleanValue(); } + if (pathParameter != null && !pathParameter.isEmpty()) + { + destinationRecordFolder = resolvePath(filePlan, pathParameter); + } + synchronized (this) { // create record from existing document @@ -167,14 +166,12 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase /** * Helper method to get the target record folder node reference from the action path parameter * - * @param filePlan The filePlan containing the path + * @param filePlan The filePlan containing the path * @param pathParameter The path * @return The NodeRef of the resolved path */ private NodeRef resolvePath(NodeRef filePlan, final String pathParameter) { - String decodedPathParameter = decode(pathParameter); - NodeRef destinationFolder; if (filePlan == null) @@ -182,7 +179,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase filePlan = getDefaultFilePlan(); } - final String[] pathElementsArray = StringUtils.tokenizeToStringArray(decodedPathParameter, "/", false, true); + final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true); if ((pathElementsArray != null) && (pathElementsArray.length > 0)) { destinationFolder = resolvePath(filePlan, Arrays.asList(pathElementsArray)); @@ -263,24 +260,4 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase } return filePlan; } - - /** - * Helper method to decode path string - * - * @param pathParameter The path string to be decoded - * @return The decoded path string - */ - private String decode(String pathParameter) - { - String decodedPathParameter; - try - { - decodedPathParameter = URLDecoder.decode(pathParameter, "UTF-8"); - } - catch (UnsupportedEncodingException ex) - { - throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be decoded."); - } - return decodedPathParameter; - } } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/CreateRecordActionTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/CreateRecordActionTest.java index 9bb0a18d0d..64df34a536 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/CreateRecordActionTest.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/legacy/action/CreateRecordActionTest.java @@ -117,4 +117,34 @@ public class CreateRecordActionTest extends BaseRMTestCase }, ADMIN_USER); } + + public void testCreateRecordActionWithLocationWithSpaces() + { + doTestInTransaction(new Test() + { + public Void run() + { + assertFalse(recordService.isRecord(dmDocument1)); + + Action action = actionService.createAction(CreateRecordAction.NAME); + action.setParameterValue(CreateRecordAction.PARAM_HIDE_RECORD, false); + action.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan); + action.setParameterValue(CreateRecordAction.PARAM_PATH, "rm Container/rm Folder"); + actionService.executeAction(action, dmDocument1); + + return null; + } + + public void test(Void result) throws Exception + { + assertTrue(recordService.isRecord(dmDocument1)); + assertTrue(recordService.isFiled(dmDocument1)); + + // is the record folder the primary parent of the filed record + NodeRef parent = nodeService.getPrimaryParent(dmDocument1).getParentRef(); + assertEquals(rm_Folder, parent); + } + }, + ADMIN_USER); + } } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 09667ed0f9..21e69a773a 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -54,7 +54,6 @@ import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderServi import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; import org.alfresco.module.org_alfresco_module_rm.report.ReportService; import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; -import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService; @@ -62,7 +61,6 @@ import org.alfresco.module.org_alfresco_module_rm.vital.VitalRecordService; import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authority.AuthorityDAO; import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.site.SiteServiceImpl; import org.alfresco.repo.transaction.RetryingTransactionHelper; @@ -186,8 +184,10 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected NodeRef folder; protected NodeRef filePlan; protected NodeRef rmContainer; + protected NodeRef rm_Container; protected DispositionSchedule dispositionSchedule; protected NodeRef rmFolder; + protected NodeRef rm_Folder; protected NodeRef unfiledContainer; protected String collabSiteId; protected NodeRef holdsContainer; @@ -586,12 +586,18 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase rmContainer = filePlanService.createRecordCategory(filePlan, "rmContainer"); assertNotNull("Could not create rm container", rmContainer); + rm_Container = filePlanService.createRecordCategory(filePlan, "rm Container"); + assertNotNull("Could not create rm container", rm_Container); + // Create disposition schedule dispositionSchedule = utils.createBasicDispositionSchedule(rmContainer); // Create RM folder rmFolder = recordFolderService.createRecordFolder(rmContainer, "rmFolder"); assertNotNull("Could not create rm folder", rmFolder); + + rm_Folder = recordFolderService.createRecordFolder(rm_Container, "rm Folder"); + assertNotNull("Could not create rm folder", rm_Folder); } }