From 098be4c2da9abc3c9cc70a71cc71c8e5c54777ce Mon Sep 17 00:00:00 2001 From: Ross Gale Date: Wed, 13 Nov 2019 15:52:29 +0000 Subject: [PATCH] Initial patch code to apply disposition fix to records --- .../patch/rm-patch-v24-context.xml | 14 +- .../query/rm-common-SqlMap.xml | 35 ++++- .../org_alfresco_module_rm/version.properties | 2 +- .../v24/RMv24DispositionInheritancePatch.java | 120 ++++++++++++++++++ .../query/NodeRefEntity.java | 77 +++++++++++ .../query/RecordsManagementQueryDAO.java | 11 ++ .../query/RecordsManagementQueryDAOImpl.java | 23 ++++ 7 files changed, 277 insertions(+), 5 deletions(-) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v24/RMv24DispositionInheritancePatch.java create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/NodeRefEntity.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v24-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v24-context.xml index e3e843041e..682a3a0331 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v24-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v24-context.xml @@ -14,5 +14,17 @@ - + + + + + + + + + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml index e3f1c1a89d..2845b537fa 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml @@ -7,8 +7,15 @@ - - select count(*) from @@ -19,5 +26,27 @@ prop.string_value = ? - + + + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties index cf2c7c2600..8cce8ad3ce 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties @@ -1,3 +1,3 @@ # RM Schema number -version.rm.schema=2501 +version.rm.schema=2502 diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v24/RMv24DispositionInheritancePatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v24/RMv24DispositionInheritancePatch.java new file mode 100644 index 0000000000..dffff5a9a4 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v24/RMv24DispositionInheritancePatch.java @@ -0,0 +1,120 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.patch.v24; + +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_DISPOSITION_LIFECYCLE; + +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule; +import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; +import org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch; +import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO; +import org.alfresco.module.org_alfresco_module_rm.record.RecordService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * RM v2.4 patch that ensures that file plan root containers do not inherited rules, because this is no longer enforced + * in the service code anymore. + *

+ * See https://issues.alfresco.com/jira/browse/RM-3154 + * + * @author Roy Wetherall + * @since 2.4 + */ +public class RMv24DispositionInheritancePatch extends AbstractModulePatch +{ + private static Log logger = LogFactory.getLog(RMv24DispositionInheritancePatch.class); + + private DispositionService dispositionService; + + private RecordService recordService; + + private NodeService nodeService; + + private RecordsManagementQueryDAO recordsManagementQueryDAO; + + public void setDispositionService(DispositionService dispositionService) + { + this.dispositionService = dispositionService; + } + + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + public void setRecordService(RecordService recordService) + { + this.recordService = recordService; + } + + public void setRecordsManagementQueryDAO(RecordsManagementQueryDAO recordsManagementQueryDAO) + { + this.recordsManagementQueryDAO = recordsManagementQueryDAO; + } + + /** + * @see AbstractModulePatch#applyInternal() + *

+ * Checks for records added to a disposition schedule pre MNT-19967 and applys disposition step and properties + */ + @Override + public void applyInternal() + { + logger.info("***********************recordsManagementQueryDAO.getNodeRefs()***************************"); + logger.info(recordsManagementQueryDAO.getRecordFoldersWithSchedules()); + logger.info("***********************RMv24DispositionInheritancePatch***************************"); + + + List folders = recordsManagementQueryDAO.getRecordFoldersWithSchedules(); + logger.info("folders: " + folders); + for (NodeRef folder : folders) + { + DispositionSchedule schedule = dispositionService.getDispositionSchedule(folder); + logger.info("schedule: " + schedule); + if (schedule.isRecordLevelDisposition()) + { + List records = recordService.getRecords(folder); + logger.info("records: " + records); + for (NodeRef record : records) + { + if (!nodeService.hasAspect(record, ASPECT_DISPOSITION_LIFECYCLE)) + { + logger.info("updating record: " + record); + dispositionService.updateNextDispositionAction(record); + } + } + } + } + } +} + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/NodeRefEntity.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/NodeRefEntity.java new file mode 100644 index 0000000000..e61e526763 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/NodeRefEntity.java @@ -0,0 +1,77 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2019 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.query; + +/** + * NodeRef Entity - used by {@link RecordsManagementQueryDAOImpl}. + * + * @author Tom Page + * @since 2.5.0.4 + */ +public class NodeRefEntity +{ + private String protocol; + private String identifier; + private String uuid; + + /** + * Default constructor. + */ + public NodeRefEntity() + { + } + + public String getProtocol() + { + return protocol; + } + + public void setProtocol(String protocol) + { + this.protocol = protocol; + } + + public String getIdentifier() + { + return identifier; + } + + public void setIdentifier(String identifier) + { + this.identifier = identifier; + } + + public String getUuid() + { + return uuid; + } + + public void setUuid(String uuid) + { + this.uuid = uuid; + } +} diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java index c0743f604d..f68ce3723a 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAO.java @@ -27,6 +27,10 @@ package org.alfresco.module.org_alfresco_module_rm.query; +import java.util.List; + +import org.alfresco.service.cmr.repository.NodeRef; + /** * Records management query DAO * @@ -46,4 +50,11 @@ public interface RecordsManagementQueryDAO * @return int count */ int getCountRmaIdentifier(String identifierValue); + + /** + * Returns a list of nodeRef for all record folders in the system + * that have the property recordSearchHasDispositionSchedule:true + * @return List of nodeRefs + */ + public List getRecordFoldersWithSchedules(); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java index 68742ee271..0432e13612 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/query/RecordsManagementQueryDAOImpl.java @@ -27,11 +27,14 @@ package org.alfresco.module.org_alfresco_module_rm.query; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.repo.domain.qname.QNameDAO; +import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.mybatis.spring.SqlSessionTemplate; @@ -45,6 +48,7 @@ import org.mybatis.spring.SqlSessionTemplate; public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO, RecordsManagementModel { private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier"; + private static final String SCHEDULED_FOLDERS = "alfresco.query.rm.select_RecordFoldersWithSchedules"; /** SQL session template */ protected SqlSessionTemplate template; @@ -97,4 +101,23 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO, return result; } + /** + * @see org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO#getRecordFoldersWithSchedules() + */ + @Override + public List getRecordFoldersWithSchedules() + { + List entities = template.selectList(SCHEDULED_FOLDERS); + + List results = new ArrayList<>(); + + // convert the entities to NodeRefs + for (NodeRefEntity nodeRefEntity : entities) + { + results.add(new NodeRef(nodeRefEntity.getProtocol(), nodeRefEntity.getIdentifier(), nodeRefEntity.getUuid())); + } + + return results; + } + }