mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-20740 BinDuplicationHotFixSqlRefactor
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
<property name="nodeService" ref="nodeService" />
|
||||
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
||||
<property name="cleansingEnabled" value="${rm.content.cleansing.enabled}" />
|
||||
<property name="contentBinDuplicationUtility" ref="contentBinDuplicationUtility"/>
|
||||
</bean>
|
||||
|
||||
<!-- extended eager content store cleaner -->
|
||||
|
@@ -251,6 +251,7 @@
|
||||
<bean name="contentBinDuplicationUtility" class="org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility">
|
||||
<property name="behaviourFilter" ref="policyBehaviourFilter"/>
|
||||
<property name="contentService" ref="contentService"/>
|
||||
<property name="recordsManagementQueryDAO" ref="recordsManagementQueryDAO"/>
|
||||
</bean>
|
||||
|
||||
<!-- Prevent ghosted records being renditioned -->
|
||||
|
@@ -2,12 +2,28 @@
|
||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||
<configuration>
|
||||
|
||||
<typeAliases>
|
||||
<!-- General -->
|
||||
<typeAlias alias="Ids" type="org.alfresco.ibatis.IdsEntity"/>
|
||||
|
||||
<!-- Content -->
|
||||
<typeAlias alias="Mimetype" type="org.alfresco.repo.domain.mimetype.MimetypeEntity"/>
|
||||
<typeAlias alias="Encoding" type="org.alfresco.repo.domain.encoding.EncodingEntity"/>
|
||||
<typeAlias alias="ContentUrl" type="org.alfresco.repo.domain.contentdata.ContentUrlEntity"/>
|
||||
<typeAlias alias="ContentUrlUpdate" type="org.alfresco.repo.domain.contentdata.ContentUrlUpdateEntity"/>
|
||||
<typeAlias alias="ContentData" type="org.alfresco.repo.domain.contentdata.ContentDataEntity"/>
|
||||
<typeAlias alias="ContentUrlKey" type="org.alfresco.repo.domain.contentdata.ContentUrlKeyEntity"/>
|
||||
<typeAlias alias="ContentUrlOrphanQuery" type="org.alfresco.repo.domain.contentdata.ContentUrlOrphanQuery"/>
|
||||
<typeAlias alias="SymmetricKeyCount" type="org.alfresco.repo.domain.contentdata.SymmetricKeyCount"/>
|
||||
</typeAliases>
|
||||
|
||||
<typeHandlers>
|
||||
<typeHandler javaType="java.io.Serializable" handler="org.alfresco.ibatis.SerializableTypeHandler"/>
|
||||
</typeHandlers>
|
||||
|
||||
<mappers>
|
||||
<mapper resource="alfresco/module/org_alfresco_module_rm/query/rm-common-SqlMap.xml"/>
|
||||
<mapper resource="alfresco/ibatis/#resource.dialect#/content-common-SqlMap.xml"/>
|
||||
</mappers>
|
||||
|
||||
</configuration>
|
@@ -33,6 +33,7 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.RenditionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
@@ -63,6 +64,9 @@ public class ContentDestructionComponent
|
||||
/** behaviour filter */
|
||||
private BehaviourFilter behaviourFilter;
|
||||
|
||||
/** Utility class for duplicating content */
|
||||
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
||||
|
||||
/** indicates whether cleansing is enabled or not */
|
||||
private boolean cleansingEnabled = false;
|
||||
|
||||
@@ -138,6 +142,15 @@ public class ContentDestructionComponent
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for content duplication utility class
|
||||
* @param contentBinDuplicationUtility ContentBinDuplicationUtility
|
||||
*/
|
||||
public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility)
|
||||
{
|
||||
this.contentBinDuplicationUtility = contentBinDuplicationUtility;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cleansingEnabled true if cleansing enabled, false otherwise
|
||||
*/
|
||||
@@ -214,6 +227,8 @@ public class ContentDestructionComponent
|
||||
// get content data
|
||||
ContentData dataContent = (ContentData)entry.getValue();
|
||||
|
||||
if (!contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef))
|
||||
{
|
||||
// if enabled cleanse content
|
||||
if (isCleansingEnabled())
|
||||
{
|
||||
@@ -225,6 +240,7 @@ public class ContentDestructionComponent
|
||||
// register for immediate destruction
|
||||
getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true);
|
||||
}
|
||||
}
|
||||
|
||||
// clear the property
|
||||
if (clearContentProperty)
|
||||
|
@@ -77,8 +77,7 @@ public class RecordAspect extends AbstractDisposableItem
|
||||
RecordsManagementPolicies.OnRemoveReference,
|
||||
NodeServicePolicies.OnMoveNodePolicy,
|
||||
CopyServicePolicies.OnCopyCompletePolicy,
|
||||
ContentServicePolicies.OnContentPropertyUpdatePolicy,
|
||||
NodeServicePolicies.BeforeDeleteNodePolicy
|
||||
ContentServicePolicies.OnContentPropertyUpdatePolicy
|
||||
{
|
||||
/** Well-known location of the scripts folder. */
|
||||
// TODO make configurable
|
||||
@@ -422,23 +421,4 @@ public class RecordAspect extends AbstractDisposableItem
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaviour to protect access to copied records binary files created prior to 2.7.2
|
||||
* @param nodeRef Node with the binary in need of protection
|
||||
*/
|
||||
@Override
|
||||
@Behaviour
|
||||
(
|
||||
kind = BehaviourKind.CLASS,
|
||||
notificationFrequency = NotificationFrequency.FIRST_EVENT
|
||||
)
|
||||
public void beforeDeleteNode(NodeRef nodeRef)
|
||||
{
|
||||
if (!nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() ||
|
||||
!nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty())
|
||||
{
|
||||
contentBinDuplicationUtility.orphanContent(nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ package org.alfresco.module.org_alfresco_module_rm.query;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
@@ -61,4 +62,11 @@ public interface RecordsManagementQueryDAO
|
||||
* @return list of distinct property values
|
||||
*/
|
||||
public Set<String> getChildrenStringPropertyValues(NodeRef parent, QName property);
|
||||
|
||||
/**
|
||||
* @param contentUrl the URL of the content url entity
|
||||
* @return Return the entity or null if it doesn't exist or is still
|
||||
* referenced by a content_data entity
|
||||
*/
|
||||
public ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl);
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
@@ -53,6 +54,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
||||
{
|
||||
private static final String COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
|
||||
private static final String GET_CHILDREN_PROPERTY_VALUES = "select_GetStringPropertyValuesOfChildren";
|
||||
private static final String SELECT_CONTENT_URL_BY_KEY_UNREFERENCED = "alfresco.content.select_ContentUrlByKeyUnreferenced";
|
||||
|
||||
/** SQL session template */
|
||||
protected SqlSessionTemplate template;
|
||||
@@ -143,4 +145,18 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
||||
return new HashSet<>(template.selectList(GET_CHILDREN_PROPERTY_VALUES, queryParams));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl)
|
||||
{
|
||||
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
||||
contentUrlEntity.setContentUrl(contentUrl);
|
||||
if (contentUrlEntity.getContentUrlShort() != null)
|
||||
{
|
||||
contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
|
||||
}
|
||||
contentUrlEntity = (ContentUrlEntity) template.selectOne(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity);
|
||||
|
||||
return contentUrlEntity;
|
||||
}
|
||||
}
|
||||
|
@@ -26,16 +26,14 @@
|
||||
*/
|
||||
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.transaction.TransactionalResourceHelper;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
|
||||
/**
|
||||
* Utility class to duplicate the content of a node without triggering the audit or versioning behaviours
|
||||
@@ -55,7 +53,8 @@ public class ContentBinDuplicationUtility
|
||||
*/
|
||||
private ContentService contentService;
|
||||
|
||||
private NodeService nodeService;
|
||||
/** Records Management Query DAO */
|
||||
private RecordsManagementQueryDAO recordsManagementQueryDAO;
|
||||
|
||||
/**
|
||||
* Setter for behaviour filter
|
||||
@@ -75,6 +74,34 @@ public class ContentBinDuplicationUtility
|
||||
this.contentService = contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Records Management QueryDAO
|
||||
*
|
||||
* @param recordsManagementQueryDAO The RM query DAO to set
|
||||
*/
|
||||
public void setRecordsManagementQueryDAO(RecordsManagementQueryDAO recordsManagementQueryDAO)
|
||||
{
|
||||
this.recordsManagementQueryDAO = recordsManagementQueryDAO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the bin file for a given node has at least one other reference to it
|
||||
* Will return true if the binary exists and is referenced by at least one other node
|
||||
* @param nodeRef Node with the binary in question
|
||||
* @return boolean for if the bin has at least one other reference to it
|
||||
*/
|
||||
public boolean hasAtLeastOneOtherReference(NodeRef nodeRef)
|
||||
{
|
||||
boolean hasAtLeastOneOtherReference = false;
|
||||
String contentUrl = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl();
|
||||
ContentUrlEntity contentUrlEntity = recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl);
|
||||
if (contentUrlEntity == null)
|
||||
{
|
||||
hasAtLeastOneOtherReference = true;
|
||||
}
|
||||
return hasAtLeastOneOtherReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the content of a node without triggering the audit or versioning behaviours
|
||||
*
|
||||
@@ -110,23 +137,4 @@ public class ContentBinDuplicationUtility
|
||||
writer.putContent(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purposely orphans a binary file.
|
||||
*
|
||||
* This will prevent the removal of a binary file to address MNT-20740 where a binary
|
||||
* file may be shared across nodes that try to delete the binary on deletion.
|
||||
*
|
||||
* Nodes created before 2.7.2 won't have been picked up by the binary duplication code
|
||||
* and will cause problems if the file is removed. Orphaning the binary will mean if
|
||||
* there is a node sharing this it will still be available and if there isn't the orphaned
|
||||
* file will be picked up by the content cleaner on it's next pass.
|
||||
*
|
||||
* @param nodeRef The node who's binary file we want to orphan
|
||||
*/
|
||||
public void orphanContent(NodeRef nodeRef)
|
||||
{
|
||||
Set<String> urlsToDelete = TransactionalResourceHelper.getSet("ContentStoreCleaner.PostCommitDeletionUrls");
|
||||
urlsToDelete.remove(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl());
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,8 @@
|
||||
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
@@ -39,6 +41,8 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -63,6 +67,9 @@ public class ContentBinDuplicationUtilityUnitTest
|
||||
@Mock
|
||||
private ContentWriter contentWriter;
|
||||
|
||||
@Mock
|
||||
private RecordsManagementQueryDAO recordsManagementQueryDAO;
|
||||
|
||||
@InjectMocks
|
||||
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
||||
|
||||
@@ -99,6 +106,41 @@ public class ContentBinDuplicationUtilityUnitTest
|
||||
checkBehaviours(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hasAtLeastOneOtherReference returns true when node has another reference to it
|
||||
*/
|
||||
@Test
|
||||
public void testHasAtLeastOneOtherReference()
|
||||
{
|
||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
||||
String contentUrl = "someContentUrl";
|
||||
|
||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(contentUrl);
|
||||
when(recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl)).thenReturn(null);
|
||||
|
||||
boolean hasReference = contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef);
|
||||
assertTrue(hasReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hasAtLeastOneOtherReference returns false when node has no other reference to it
|
||||
*/
|
||||
@Test
|
||||
public void testHasNoOtherReference()
|
||||
{
|
||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
||||
String contentUrl = "someContentUrl";
|
||||
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
||||
|
||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(contentUrl);
|
||||
when(recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl)).thenReturn(contentUrlEntity);
|
||||
|
||||
boolean hasReference = contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef);
|
||||
assertFalse(hasReference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the behaviours are disabled and re-enabled the correct number of times
|
||||
* @param times the times the behaviours should be called
|
||||
|
Reference in New Issue
Block a user