From b85d6cf3782a0fb46e8fd1c53dc9a087b1281cf2 Mon Sep 17 00:00:00 2001 From: Sara Aspery Date: Fri, 10 May 2019 15:26:17 +0100 Subject: [PATCH] RM-6792 Oliver strings and fix closed folder and tests --- .../messages/actions.properties | 2 +- .../action/dm/CreateRecordAction.java | 56 ++++++++++++------- .../record/RecordServiceImpl.java | 10 +++- .../legacy/action/CreateRecordActionTest.java | 7 +++ .../test/util/BaseRMTestCase.java | 4 +- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties index c1e8bce28e..e2d43aa52b 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/messages/actions.properties @@ -48,7 +48,7 @@ isRecordType.description=Records have a specified record type # # Declare As Record create-record.title=Declare as Record -create-record.description=Declares file as a record +create-record.description=Declares file as a record and optionally files it create-record.file-plan.display-label=File Plan create-record.hide-record.display-label=Hide Record create-record.path.display-label=Destination Record Folder Path 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 9cf67a954d..bd60827fcc 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 @@ -60,7 +60,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase implements RecordsManagementModel { /** Logger */ - private static Log logger = LogFactory.getLog(CreateRecordAction.class); + private static final Log LOGGER = LogFactory.getLog(CreateRecordAction.class); /** Action name */ public static final String NAME = "create-record"; @@ -125,9 +125,9 @@ 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) + if (pathParameter != null && !pathParameter.isEmpty()) { - destinationRecordFolder = resolvePath(action, filePlan, pathParameter); + destinationRecordFolder = resolvePath(filePlan, pathParameter); } // indicate whether the record should be hidden or not (default not) @@ -162,37 +162,49 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase params.add(new ParameterDefinitionImpl(PARAM_HIDE_RECORD, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_HIDE_RECORD))); } - /* Helper method to get the target record folder node reference from the action path parameter */ - private NodeRef resolvePath(final Action action, NodeRef filePlan, final String pathParameter) + /** + * Helper method to get the target record folder node reference from the action path parameter + * + * @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) { NodeRef destinationFolder; if (filePlan == null) { - filePlan = getDefaultFilePlan(action); + filePlan = getDefaultFilePlan(); } final String[] pathElementsArray = StringUtils.tokenizeToStringArray(pathParameter, "/", false, true); if ((pathElementsArray != null) && (pathElementsArray.length > 0)) { - destinationFolder = resolvePath(action, filePlan, Arrays.asList(pathElementsArray)); + destinationFolder = resolvePath(filePlan, Arrays.asList(pathElementsArray)); // destination must be a record folder QName nodeType = nodeService.getType(destinationFolder); if (!nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER)) { - throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path is not a record folder."); + throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is not a record folder."); } } else { - throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path could not be resolved."); + throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be found."); } return destinationFolder; } - /* Helper method to recursively get the next path element node reference from the action path parameter */ - private NodeRef resolvePath(Action action, NodeRef parent, List pathElements) + /** + * Helper method to recursively get the next path element node reference from the action path parameter + * + * @param parent The parent of the path elements + * @param pathElements The path elements still to be resolved + * @return The NodeRef of the resolved path element + */ + private NodeRef resolvePath(NodeRef parent, List pathElements) { NodeRef nodeRef; String childName = pathElements.get(0); @@ -201,7 +213,7 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase if (nodeRef == null) { - throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path could not be resolved."); + throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path could not be resolved."); } else { @@ -210,33 +222,37 @@ public class CreateRecordAction extends AuditableActionExecuterAbstractBase nodeType.equals(RecordsManagementModel.TYPE_TRANSFER_CONTAINER) || nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER)) { - throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the destination path is invalid."); + throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the destination path is invalid."); } } if (pathElements.size() > 1) { - nodeRef = resolvePath(action, nodeRef, pathElements.subList(1, pathElements.size())); + nodeRef = resolvePath(nodeRef, pathElements.subList(1, pathElements.size())); } return nodeRef; } - /* Helper method to get the default RM filePlan */ - private NodeRef getDefaultFilePlan(final Action action) + /** + * Helper method to get the default RM filePlan + * + * @return The NodeRef of the default RM filePlan + */ + private NodeRef getDefaultFilePlan() { - NodeRef filePlan = authenticationUtil.runAs(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork() + NodeRef filePlan = authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork() { @Override public NodeRef doWork() { return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); } - }, authenticationUtil.getAdminUserName()); + }); // if the file plan is still null, raise an exception if (filePlan == null) { - logger.debug("Unable to execute " + action.getActionDefinitionName() + " action, because the path fileplan could not be determined. Make sure at least one file plan has been created."); - throw new AlfrescoRuntimeException("Unable to execute " + action.getActionDefinitionName() + " action, because the path fileplan could not be determined."); + LOGGER.debug("Unable to execute " + NAME + " action, because the fileplan path could not be determined. Make sure at least one file plan has been created."); + throw new AlfrescoRuntimeException("Unable to execute " + NAME + " action, because the fileplan path could not be determined."); } return filePlan; } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index 91255cd918..dfbebbf810 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -911,18 +911,22 @@ public class RecordServiceImpl extends BaseBehaviourBean { throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found."); } - } - // if optional location supplied, check that it is a folder + // if optional location supplied, check that it is a valid record folder else { - // first look to see if the destination record folder has been specified QName nodeType = nodeService.getType(newRecordContainer); if(!(nodeType.equals(RecordsManagementModel.TYPE_RECORD_FOLDER) || nodeType.equals(RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER))) { throw new AlfrescoRuntimeException("Unable to create record, because container is not a valid type for new record."); } + + Boolean isClosed = (Boolean) nodeService.getProperty(newRecordContainer, PROP_IS_CLOSED); + if (isClosed != null && isClosed) + { + throw new AlfrescoRuntimeException("Unable to create record, because container is closed."); + } } // get the documents readers and writers 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 fab575f6c2..9bb0a18d0d 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 @@ -53,6 +53,13 @@ public class CreateRecordActionTest extends BaseRMTestCase return true; } + /** + * Test create record action + * + * Given a collaboration site document + * When the create record action is executed for that document + * Then a record is created for it + */ public void testCreateRecordAction() { doTestInTransaction(new Test() 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 00b3b4b400..09667ed0f9 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 @@ -274,6 +274,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected SiteInfo collaborationSite; protected NodeRef documentLibrary; protected NodeRef dmFolder; + protected NodeRef dmFolder1; protected NodeRef dmDocument; protected NodeRef dmDocument1; @@ -781,7 +782,8 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase // create a folder and documents dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef(); dmDocument = fileFolderService.create(dmFolder, NAME_DM_DOCUMENT, ContentModel.TYPE_CONTENT).getNodeRef(); - dmDocument1 = fileFolderService.create(dmFolder, NAME_DM_DOCUMENT1, ContentModel.TYPE_CONTENT).getNodeRef(); + dmFolder1 = fileFolderService.create(documentLibrary, "collabFolder1", ContentModel.TYPE_FOLDER).getNodeRef(); + dmDocument1 = fileFolderService.create(dmFolder1, NAME_DM_DOCUMENT1, ContentModel.TYPE_CONTENT).getNodeRef(); dmConsumer = GUID.generate(); dmConsumerNodeRef = createPerson(dmConsumer);