diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml
index 4ccba8a2a0..9f279987b2 100644
--- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml
+++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml
@@ -125,6 +125,13 @@
+
+
+
+
+
+
+
diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/behaviour/CleanRecordsManagementRootCache.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/behaviour/CleanRecordsManagementRootCache.java
new file mode 100644
index 0000000000..2f311e4adb
--- /dev/null
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/behaviour/CleanRecordsManagementRootCache.java
@@ -0,0 +1,135 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2020 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.behaviour;
+
+import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
+import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
+import org.alfresco.repo.node.NodeServicePolicies.OnDeleteNodePolicy;
+import org.alfresco.repo.node.NodeServicePolicies.OnRemoveAspectPolicy;
+import org.alfresco.repo.policy.JavaBehaviour;
+import org.alfresco.repo.policy.PolicyComponent;
+import org.alfresco.service.cmr.repository.ChildAssociationRef;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.util.PropertyCheck;
+
+public class CleanRecordsManagementRootCache implements RecordsManagementModel, OnDeleteNodePolicy, OnRemoveAspectPolicy
+{
+
+ private PolicyComponent policyComponent;
+
+ private NodeService nodeService;
+
+ private FilePlanService filePlanService;
+
+ /**
+ *
+ * @param policyComponent
+ */
+ public void setPolicyComponent(PolicyComponent policyComponent)
+ {
+ this.policyComponent = policyComponent;
+ }
+
+ /**
+ * @param nodeService
+ */
+ public void setNodeService(NodeService nodeService)
+ {
+ this.nodeService = nodeService;
+ }
+
+ /**
+ *
+ * @param filePlanService
+ */
+ public void setFilePlanService(FilePlanService filePlanService)
+ {
+ this.filePlanService = filePlanService;
+ }
+
+ /**
+ * Performs the initialization operations for this behavior
+ */
+ public void init()
+ {
+ // check that required properties have been set
+ PropertyCheck.mandatory("CleanRecordsManagementRootCache", "policyComponent", policyComponent);
+ PropertyCheck.mandatory("CleanRecordsManagementRootCache", "nodeService", nodeService);
+ PropertyCheck.mandatory("CleanRecordsManagementRootCache", "filePlanService", filePlanService);
+
+ // register behaviour
+ policyComponent.bindClassBehaviour(
+ QName.createQName(NamespaceService.ALFRESCO_URI, "onRemoveAspect"),
+ this,
+ new JavaBehaviour(this, "onRemoveAspect"));
+ policyComponent.bindClassBehaviour(
+ QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteNode"),
+ this,
+ new JavaBehaviour(this, "onDeleteNode"));
+ }
+
+ /**
+ * On remove aspect, performs the records management root cache clean operation but only
+ * if the removed aspects matches {@link RecordsManagementModel#ASPECT_RECORDS_MANAGEMENT_ROOT}
+ */
+ @Override
+ public void onRemoveAspect(NodeRef nodeRef, QName aspectTypeQName)
+ {
+ if (nodeRef != null && ASPECT_RECORDS_MANAGEMENT_ROOT.isMatch(aspectTypeQName))
+ {
+ clearRootRecordsManagementCache(nodeRef);
+ }
+ }
+
+ /**
+ * On delete node, performs the records management root cache clean operation
+ */
+ @Override
+ public void onDeleteNode(ChildAssociationRef childAssocRef, boolean isNodeArchived)
+ {
+ if (childAssocRef != null)
+ {
+ clearRootRecordsManagementCache(childAssocRef.getParentRef());
+ clearRootRecordsManagementCache(childAssocRef.getChildRef());
+ }
+ }
+
+ /**
+ * Cleans the records managements root cache in case of supplied nodeRef has {@link RecordsManagementModel#ASPECT_RECORDS_MANAGEMENT_ROOT} aspect
+ *
+ * @param nodeRef
+ */
+ private void clearRootRecordsManagementCache(NodeRef nodeRef) {
+ if (nodeRef != null && nodeService.hasAspect(nodeRef, ASPECT_RECORDS_MANAGEMENT_ROOT))
+ {
+ filePlanService.clearRootRecordsManagementCache(nodeRef.getStoreRef());
+ }
+ }
+}
\ No newline at end of file
diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java
index ca09908ef2..f5c6ee4c88 100644
--- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanService.java
@@ -346,9 +346,11 @@ public interface FilePlanService
*/
NodeRef createRecordCategory(NodeRef parent, String name, Map properties);
- /**
- * Clears the records management root node cache
- */
- void clearRootRecordsManagementCache();
+ /**
+ * Clears the records management root node cache
+ *
+ * @param storeRef
+ */
+ void clearRootRecordsManagementCache(StoreRef storeRef);
-}
+}
\ No newline at end of file
diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java
index f32d905daf..fe70233cf4 100644
--- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/fileplan/FilePlanServiceImpl.java
@@ -178,11 +178,22 @@ public class FilePlanServiceImpl extends ServiceBaseImpl
}
/**
- * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#clearRootRecordsManagementCache()
+ * @see org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService#clearRootRecordsManagementCache(StoreRef)
*/
- public void clearRootRecordsManagementCache()
+ public void clearRootRecordsManagementCache(StoreRef storeRef)
{
- this.rootRecordsManagementCache.clear();
+ if (storeRef != null)
+ {
+ Pair key = new Pair(storeRef, ASPECT_RECORDS_MANAGEMENT_ROOT.toString());
+ if (rootRecordsManagementCache.contains(key))
+ {
+ this.rootRecordsManagementCache.remove(key);
+ }
+ }
+ else
+ {
+ this.rootRecordsManagementCache.clear();
+ }
}
/**
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 3f3b899bd6..180d85954c 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
@@ -458,11 +458,6 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
filter.disableBehaviour();
try
{
- if (filePlanService != null)
- {
- filePlanService.clearRootRecordsManagementCache();
- }
-
if (filePlan != null && nodeService.exists(filePlan))
{
List holds = holdService.getHolds(filePlan);
@@ -489,6 +484,11 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{
siteService.deleteSite(collabSiteId);
}
+
+ if (filePlanService != null)
+ {
+ filePlanService.clearRootRecordsManagementCache(null);
+ }
}
finally
{
@@ -941,6 +941,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
public void then() throws Exception { /** empty implementation */ }
public void after() throws Exception { /** empty implementation */ }
+
+ public void mAfter() throws Exception
+ {
+ this.after();
+ if (filePlanService != null)
+ {
+ filePlanService.clearRootRecordsManagementCache(null);
+ }
+ }
public void run() throws Exception
{