diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java index 64ac696ae0..ba688e52a2 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/NonElectronicRecordType.java @@ -27,6 +27,8 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; +import static org.alfresco.module.org_alfresco_module_rm.record.RecordUtils.appendIdentifierToName; + import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; @@ -88,6 +90,7 @@ public class NonElectronicRecordType extends BaseBehaviourBean implements NodeSe if (!nodeService.hasAspect(child, ASPECT_RECORD)) { recordService.makeRecord(child); + appendIdentifierToName(nodeService, child); } } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java index 504acd4d86..bd77ce4dde 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordsManagementContainerType.java @@ -27,6 +27,8 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.type; +import static org.alfresco.module.org_alfresco_module_rm.record.RecordUtils.appendIdentifierToName; + import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; @@ -198,6 +200,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean if (!nodeService.hasAspect(child, ASPECT_RECORD)) { recordService.makeRecord(child); + appendIdentifierToName(nodeService, child); } } } 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 78182e89bf..d5e9e2ac2e 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 @@ -27,10 +27,10 @@ package org.alfresco.module.org_alfresco_module_rm.record; +import static org.alfresco.module.org_alfresco_module_rm.record.RecordUtils.appendIdentifierToName; import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.FIRST_EVENT; import static org.alfresco.repo.policy.Behaviour.NotificationFrequency.TRANSACTION_COMMIT; import static org.alfresco.repo.policy.annotation.BehaviourKind.ASSOCIATION; -import static org.apache.commons.lang.StringUtils.isNotBlank; import java.io.Serializable; import java.util.ArrayList; @@ -422,7 +422,7 @@ public class RecordServiceImpl extends BaseBehaviourBean ContentData contentData = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT); if (ContentData.hasContent(contentData) && contentData.getSize() > 0) { - renameRecord(nodeRef); + appendIdentifierToName(nodeService, nodeRef); } } } @@ -831,7 +831,7 @@ public class RecordServiceImpl extends BaseBehaviourBean // make the document a record makeRecord(nodeRef); - renameRecord(nodeRef); + appendIdentifierToName(nodeService, nodeRef); if (latestVersionRecord != null) { @@ -927,7 +927,7 @@ public class RecordServiceImpl extends BaseBehaviourBean // make record makeRecord(record); - renameRecord(record); + appendIdentifierToName(nodeService, record); // remove added copy assocs List recordAssocs = nodeService.getTargetAssocs(record, ContentModel.ASSOC_ORIGINAL); @@ -1062,7 +1062,7 @@ public class RecordServiceImpl extends BaseBehaviourBean { // make record makeRecord(record); - renameRecord(record); + appendIdentifierToName(nodeService, record); } return record; @@ -1113,7 +1113,7 @@ public class RecordServiceImpl extends BaseBehaviourBean if (TYPE_NON_ELECTRONIC_DOCUMENT.equals(nodeService.getType(document))) { - renameRecord(document); + appendIdentifierToName(nodeService, document); } } finally @@ -1714,42 +1714,7 @@ public class RecordServiceImpl extends BaseBehaviourBean { if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN) && !nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) { - renameRecord(nodeRef); - } - } - - /** - * Appends the record identifier to the name of the record - * - * @param nodeRef The node reference of the record. - */ - private void renameRecord(NodeRef nodeRef) - { - // get the record id - String recordId = (String) nodeService.getProperty(nodeRef, PROP_IDENTIFIER); - - if (isNotBlank(recordId)) - { - // get the record name - String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); - - // rename the record - int dotIndex = name.lastIndexOf('.'); - String prefix = name; - String postfix = ""; - if (dotIndex > 0) - { - prefix = name.substring(0, dotIndex); - postfix = name.substring(dotIndex); - } - String recordName = prefix + " (" + recordId + ")" + postfix; - - nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, recordName); - - if (logger.isDebugEnabled()) - { - logger.debug("Rename " + name + " to " + recordName); - } + appendIdentifierToName(nodeService, nodeRef); } } } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordUtils.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordUtils.java new file mode 100644 index 0000000000..9cf6fbad05 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordUtils.java @@ -0,0 +1,82 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * 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 . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.record; + +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.PROP_IDENTIFIER; +import static org.alfresco.util.ParameterCheck.mandatory; +import static org.apache.commons.lang.StringUtils.isNotBlank; + +import org.alfresco.model.ContentModel; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; + +/** + * Util class for records + * + * @author Tuna Aksoy + * @since 2.4 + */ +public class RecordUtils +{ + private RecordUtils() + { + // Will not be called + } + + /** + * Appends the record identifier to the name of the record + * + * @param nodeRef The node reference of the record. + */ + public static void appendIdentifierToName(NodeService nodeService, NodeRef nodeRef) + { + mandatory("nodeService", nodeService); + mandatory("nodeRef", nodeRef); + + // get the record id + String recordId = (String) nodeService.getProperty(nodeRef, PROP_IDENTIFIER); + + if (isNotBlank(recordId)) + { + // get the record name + String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); + + // rename the record + int dotIndex = name.lastIndexOf('.'); + String prefix = name; + String postfix = ""; + if (dotIndex > 0) + { + prefix = name.substring(0, dotIndex); + postfix = name.substring(dotIndex); + } + String recordName = prefix + " (" + recordId + ")" + postfix; + + nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, recordName); + } + } +}