[MNT-21818] Added behavior to update cache. Changed clear method.

This commit is contained in:
tiagos
2020-09-14 22:00:02 +01:00
parent 7d38d2a596
commit eb79016d90
5 changed files with 177 additions and 13 deletions

View File

@@ -125,6 +125,13 @@
<!-- Import the deprecated beans --> <!-- Import the deprecated beans -->
<import resource="classpath:alfresco/module/org_alfresco_module_rm/rm-deprecated-context.xml"/> <import resource="classpath:alfresco/module/org_alfresco_module_rm/rm-deprecated-context.xml"/>
<!-- Records Management Root Cache Behavior -->
<bean id="cleanRecordsManagementRootCache" class="org.alfresco.module.org_alfresco_module_rm.behaviour.CleanRecordsManagementRootCache" init-method="init">
<property name="policyComponent" ref="policyComponent"/>
<property name="nodeService" ref="nodeService"/>
<property name="filePlanService" ref="FilePlanService" />
</bean>
<!-- Event types --> <!-- Event types -->
<bean id="rmEventType" init-method="init" abstract="true"> <bean id="rmEventType" init-method="init" abstract="true">
<property name="recordsManagementEventService" ref="recordsManagementEventService"/> <property name="recordsManagementEventService" ref="recordsManagementEventService"/>

View File

@@ -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 <http://www.gnu.org/licenses/>.
* #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());
}
}
}

View File

@@ -346,9 +346,11 @@ public interface FilePlanService
*/ */
NodeRef createRecordCategory(NodeRef parent, String name, Map<QName, Serializable> properties); NodeRef createRecordCategory(NodeRef parent, String name, Map<QName, Serializable> properties);
/** /**
* Clears the records management root node cache * Clears the records management root node cache
*/ *
void clearRootRecordsManagementCache(); * @param storeRef
*/
void clearRootRecordsManagementCache(StoreRef storeRef);
} }

View File

@@ -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<StoreRef, String> key = new Pair<StoreRef, String>(storeRef, ASPECT_RECORDS_MANAGEMENT_ROOT.toString());
if (rootRecordsManagementCache.contains(key))
{
this.rootRecordsManagementCache.remove(key);
}
}
else
{
this.rootRecordsManagementCache.clear();
}
} }
/** /**

View File

@@ -458,11 +458,6 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
filter.disableBehaviour(); filter.disableBehaviour();
try try
{ {
if (filePlanService != null)
{
filePlanService.clearRootRecordsManagementCache();
}
if (filePlan != null && nodeService.exists(filePlan)) if (filePlan != null && nodeService.exists(filePlan))
{ {
List<NodeRef> holds = holdService.getHolds(filePlan); List<NodeRef> holds = holdService.getHolds(filePlan);
@@ -489,6 +484,11 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
{ {
siteService.deleteSite(collabSiteId); siteService.deleteSite(collabSiteId);
} }
if (filePlanService != null)
{
filePlanService.clearRootRecordsManagementCache(null);
}
} }
finally finally
{ {
@@ -941,6 +941,15 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
public void then() throws Exception { /** empty implementation */ } public void then() throws Exception { /** empty implementation */ }
public void after() 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 public void run() throws Exception
{ {