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 b507be0558..23c2b40faf 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.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.identifier.IdentifierService; import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; @@ -57,9 +59,9 @@ import org.alfresco.service.namespace.QName; public class RecordsManagementContainerType extends BaseBehaviourBean implements NodeServicePolicies.OnCreateChildAssociationPolicy { - /** behaviour name */ - private static final String BEHAVIOUR_NAME = "onCreateContainerType"; - + /** behaviour name */ + private static final String BEHAVIOUR_NAME = "onCreateContainerType"; + /** identifier service */ protected IdentifierService identifierService; @@ -95,25 +97,25 @@ public class RecordsManagementContainerType extends BaseBehaviourBean { this.recordFolderService = recordFolderService; } - + /** * Disable the behaviours for this transaction - * + * * @since 2.3 */ public void disable() { - getBehaviour(BEHAVIOUR_NAME).disable(); + getBehaviour(BEHAVIOUR_NAME).disable(); } - + /** * Enable behaviours for this transaction - * + * * @since 2.3 */ public void enable() { - getBehaviour(BEHAVIOUR_NAME).enable(); + getBehaviour(BEHAVIOUR_NAME).enable(); } /** @@ -122,7 +124,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean @Behaviour ( kind = BehaviourKind.ASSOCIATION, - // Execute on first event to make all type conversions and set all the properties before transaction ends and response is returned + // Execute on first event to make all type conversions and set all the properties before transaction ends and response is returned notificationFrequency = NotificationFrequency.EVERY_EVENT, name = BEHAVIOUR_NAME ) @@ -171,6 +173,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean if (!nodeService.hasAspect(child, ASPECT_RECORD)) { recordService.makeRecord(child); + appendIdentifierToName(nodeService, child); } } } @@ -210,7 +213,7 @@ public class RecordsManagementContainerType extends BaseBehaviourBean * Converted the child node to a fileplan component * The conversion is needed here to be able to generate the identifier * If there is no conversion rule for the created type nothing happens and the current type is returned - * + * * @param childAssocRef reference to the new association * @return the new type of the child node */ 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 21b2393885..d96d6227b7 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,11 +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; @@ -429,7 +428,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); } } } @@ -828,7 +827,7 @@ public class RecordServiceImpl extends BaseBehaviourBean // make the document a record makeRecord(nodeRef); - renameRecord(nodeRef); + appendIdentifierToName(nodeService, nodeRef); if (latestVersionRecord != null) { @@ -1037,7 +1036,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); @@ -1172,7 +1171,7 @@ public class RecordServiceImpl extends BaseBehaviourBean { // make record makeRecord(record); - renameRecord(record); + appendIdentifierToName(nodeService, record); } return record; @@ -1223,7 +1222,7 @@ public class RecordServiceImpl extends BaseBehaviourBean if (TYPE_NON_ELECTRONIC_DOCUMENT.equals(nodeService.getType(document))) { - renameRecord(document); + appendIdentifierToName(nodeService, document); } } finally @@ -1792,34 +1791,7 @@ public class RecordServiceImpl extends BaseBehaviourBean { if (!nodeService.hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN) && !nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE)) { - renameRecord(nodeRef); - } - } - - 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); - - LOGGER.debug("Rename " + name + " to " + recordName); + appendIdentifierToName(nodeService, nodeRef); } } } \ No newline at end of file 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); + } + } +}