mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merge branch 'feature-2.7/MNT-20740_BinDuplicationHotFix' into hotfix-2.7/MNT-20740_BinDuplicationHotFix
# Conflicts: # rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/module-context.xml # rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ContentBinDuplicationUtility.java
This commit is contained in:
@@ -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,16 +227,19 @@ public class ContentDestructionComponent
|
||||
// get content data
|
||||
ContentData dataContent = (ContentData)entry.getValue();
|
||||
|
||||
// if enabled cleanse content
|
||||
if (isCleansingEnabled())
|
||||
if (!contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef))
|
||||
{
|
||||
// register for cleanse then immediate destruction
|
||||
getEagerContentStoreCleaner().registerOrphanedContentUrlForCleansing(dataContent.getContentUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
// register for immediate destruction
|
||||
getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true);
|
||||
// if enabled cleanse content
|
||||
if (isCleansingEnabled())
|
||||
{
|
||||
// register for cleanse then immediate destruction
|
||||
getEagerContentStoreCleaner().registerOrphanedContentUrlForCleansing(dataContent.getContentUrl());
|
||||
}
|
||||
else
|
||||
{
|
||||
// register for immediate destruction
|
||||
getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true);
|
||||
}
|
||||
}
|
||||
|
||||
// clear the property
|
||||
|
@@ -61,4 +61,10 @@ 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 a set of UUIDs which reference the given node
|
||||
*/
|
||||
Set<String> getNodeRefsWhichReferenceContentUrl(String contentUrl);
|
||||
}
|
||||
|
@@ -30,17 +30,24 @@ package org.alfresco.module.org_alfresco_module_rm.query;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
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;
|
||||
import org.alfresco.repo.version.Version2Model;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
|
||||
/**
|
||||
@@ -53,6 +60,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_NODE_IDS_WHICH_REFERENCE_CONTENT_URL = "select_NodeIdsWhichReferenceContentUrl";
|
||||
|
||||
/** SQL session template */
|
||||
protected SqlSessionTemplate template;
|
||||
@@ -101,7 +109,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
||||
if (pair != null)
|
||||
{
|
||||
// create query params
|
||||
Map<String, Object> params = new HashMap<String, Object>(2);
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put("qnameId", pair.getFirst());
|
||||
params.put("idValue", identifierValue);
|
||||
|
||||
@@ -143,4 +151,41 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
||||
return new HashSet<>(template.selectList(GET_CHILDREN_PROPERTY_VALUES, queryParams));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getNodeRefsWhichReferenceContentUrl(String contentUrl)
|
||||
{
|
||||
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
|
||||
contentUrlEntity.setContentUrl(contentUrl);
|
||||
if (contentUrlEntity.getContentUrlShort() != null)
|
||||
{
|
||||
contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
|
||||
}
|
||||
|
||||
// Get all the node ids which reference the given content url
|
||||
List<Long> nodeIds = template.selectList(SELECT_NODE_IDS_WHICH_REFERENCE_CONTENT_URL, contentUrlEntity);
|
||||
|
||||
// create a set of uuids which reference the content url
|
||||
Set<String> nodesReferencingContentUrl = new HashSet<>();
|
||||
for(Long nodeId : nodeIds)
|
||||
{
|
||||
String uuidToAdd;
|
||||
|
||||
// if the referencing node is a version2Store reference to the content url, add the uuid for the version 2 frozen node ref
|
||||
NodeRef version2FrozenNodeRef = (NodeRef) nodeDAO.getNodeProperty(nodeId, Version2Model.PROP_QNAME_FROZEN_NODE_REF);
|
||||
if (version2FrozenNodeRef != null)
|
||||
{
|
||||
uuidToAdd = version2FrozenNodeRef.getId();
|
||||
}
|
||||
|
||||
// add the uuid for the node ref of the referencing node
|
||||
else
|
||||
{
|
||||
uuidToAdd = (String) nodeDAO.getNodeProperty(nodeId, ContentModel.PROP_NODE_UUID);
|
||||
}
|
||||
nodesReferencingContentUrl.add(uuidToAdd);
|
||||
}
|
||||
|
||||
return nodesReferencingContentUrl;
|
||||
}
|
||||
}
|
||||
|
@@ -27,11 +27,15 @@
|
||||
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.policy.BehaviourFilter;
|
||||
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 java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility class to duplicate the content of a node without triggering the audit or versioning behaviours
|
||||
* @author Ross Gale
|
||||
@@ -45,6 +49,14 @@ public class ContentBinDuplicationUtility extends ServiceBaseImpl
|
||||
*/
|
||||
private BehaviourFilter behaviourFilter;
|
||||
|
||||
/**
|
||||
* Provides methods for accessing and transforming content.
|
||||
*/
|
||||
private ContentService contentService;
|
||||
|
||||
/** Records Management Query DAO */
|
||||
private RecordsManagementQueryDAO recordsManagementQueryDAO;
|
||||
|
||||
/**
|
||||
* Setter for behaviour filter
|
||||
* @param behaviourFilter BehaviourFilter
|
||||
@@ -54,6 +66,44 @@ public class ContentBinDuplicationUtility extends ServiceBaseImpl
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for content service
|
||||
* @param contentService ContentService
|
||||
*/
|
||||
public void setContentService(ContentService contentService)
|
||||
{
|
||||
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();
|
||||
|
||||
Set<String> referencesToContentNode = recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(contentUrl);
|
||||
if (referencesToContentNode.size() > 1)
|
||||
{
|
||||
hasAtLeastOneOtherReference = true;
|
||||
}
|
||||
return hasAtLeastOneOtherReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the content of a node without triggering the audit or versioning behaviours
|
||||
*
|
||||
|
Reference in New Issue
Block a user