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:
@@ -18,6 +18,7 @@
|
|||||||
<property name="nodeService" ref="nodeService" />
|
<property name="nodeService" ref="nodeService" />
|
||||||
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
<property name="behaviourFilter" ref="policyBehaviourFilter" />
|
||||||
<property name="cleansingEnabled" value="${rm.content.cleansing.enabled}" />
|
<property name="cleansingEnabled" value="${rm.content.cleansing.enabled}" />
|
||||||
|
<property name="contentBinDuplicationUtility" ref="contentBinDuplicationUtility"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- extended eager content store cleaner -->
|
<!-- extended eager content store cleaner -->
|
||||||
|
@@ -250,6 +250,8 @@
|
|||||||
|
|
||||||
<bean name="contentBinDuplicationUtility" class="org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility" parent="baseService">
|
<bean name="contentBinDuplicationUtility" class="org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility" parent="baseService">
|
||||||
<property name="behaviourFilter" ref="policyBehaviourFilter"/>
|
<property name="behaviourFilter" ref="policyBehaviourFilter"/>
|
||||||
|
<property name="contentService" ref="contentService"/>
|
||||||
|
<property name="recordsManagementQueryDAO" ref="recordsManagementQueryDAO"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Prevent ghosted records being renditioned -->
|
<!-- Prevent ghosted records being renditioned -->
|
||||||
|
@@ -8,6 +8,10 @@
|
|||||||
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
|
<parameter property="idValue" jdbcType="BIGINT" javaType="java.lang.String"/>
|
||||||
</parameterMap>
|
</parameterMap>
|
||||||
|
|
||||||
|
<resultMap id="result_NodeIds" type="java.lang.Long">
|
||||||
|
<result property="node.id" column="node_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
<select id="select_CountRMIndentifier" parameterMap="parameter_CountRMIndentifier" resultType="java.lang.Integer">
|
<select id="select_CountRMIndentifier" parameterMap="parameter_CountRMIndentifier" resultType="java.lang.Integer">
|
||||||
select
|
select
|
||||||
count(*)
|
count(*)
|
||||||
@@ -35,6 +39,21 @@
|
|||||||
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- Get list of node ids which reference given content url -->
|
||||||
|
<select id="select_NodeIdsWhichReferenceContentUrl"
|
||||||
|
parameterType="ContentUrl"
|
||||||
|
resultMap="result_NodeIds">
|
||||||
|
select
|
||||||
|
p.node_id
|
||||||
|
from
|
||||||
|
alf_content_url cu
|
||||||
|
LEFT OUTER JOIN alf_content_data cd ON (cd.content_url_id = cu.id)
|
||||||
|
LEFT OUTER JOIN alf_node_properties p ON (p.long_value = cd.id)
|
||||||
|
WHERE
|
||||||
|
content_url_short = #{contentUrlShort} and
|
||||||
|
content_url_crc = #{contentUrlCrc}
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
@@ -2,6 +2,11 @@
|
|||||||
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
|
<typeAliases>
|
||||||
|
<!-- Content -->
|
||||||
|
<typeAlias alias="ContentUrl" type="org.alfresco.repo.domain.contentdata.ContentUrlEntity"/>
|
||||||
|
</typeAliases>
|
||||||
|
|
||||||
<typeHandlers>
|
<typeHandlers>
|
||||||
<typeHandler javaType="java.io.Serializable" handler="org.alfresco.ibatis.SerializableTypeHandler"/>
|
<typeHandler javaType="java.io.Serializable" handler="org.alfresco.ibatis.SerializableTypeHandler"/>
|
||||||
</typeHandlers>
|
</typeHandlers>
|
||||||
|
@@ -33,6 +33,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.model.RenditionModel;
|
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.BehaviourFilter;
|
||||||
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
import org.alfresco.repo.policy.annotation.BehaviourBean;
|
||||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
@@ -63,6 +64,9 @@ public class ContentDestructionComponent
|
|||||||
/** behaviour filter */
|
/** behaviour filter */
|
||||||
private BehaviourFilter behaviourFilter;
|
private BehaviourFilter behaviourFilter;
|
||||||
|
|
||||||
|
/** Utility class for duplicating content */
|
||||||
|
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
||||||
|
|
||||||
/** indicates whether cleansing is enabled or not */
|
/** indicates whether cleansing is enabled or not */
|
||||||
private boolean cleansingEnabled = false;
|
private boolean cleansingEnabled = false;
|
||||||
|
|
||||||
@@ -138,6 +142,15 @@ public class ContentDestructionComponent
|
|||||||
this.behaviourFilter = behaviourFilter;
|
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
|
* @param cleansingEnabled true if cleansing enabled, false otherwise
|
||||||
*/
|
*/
|
||||||
@@ -214,6 +227,8 @@ public class ContentDestructionComponent
|
|||||||
// get content data
|
// get content data
|
||||||
ContentData dataContent = (ContentData)entry.getValue();
|
ContentData dataContent = (ContentData)entry.getValue();
|
||||||
|
|
||||||
|
if (!contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef))
|
||||||
|
{
|
||||||
// if enabled cleanse content
|
// if enabled cleanse content
|
||||||
if (isCleansingEnabled())
|
if (isCleansingEnabled())
|
||||||
{
|
{
|
||||||
@@ -225,6 +240,7 @@ public class ContentDestructionComponent
|
|||||||
// register for immediate destruction
|
// register for immediate destruction
|
||||||
getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true);
|
getEagerContentStoreCleaner().registerOrphanedContentUrl(dataContent.getContentUrl(), true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clear the property
|
// clear the property
|
||||||
if (clearContentProperty)
|
if (clearContentProperty)
|
||||||
|
@@ -61,4 +61,10 @@ public interface RecordsManagementQueryDAO
|
|||||||
* @return list of distinct property values
|
* @return list of distinct property values
|
||||||
*/
|
*/
|
||||||
public Set<String> getChildrenStringPropertyValues(NodeRef parent, QName property);
|
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.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
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.node.NodeDAO;
|
||||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||||
import org.alfresco.repo.tenant.TenantService;
|
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.InvalidNodeRefException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.mybatis.spring.SqlSessionTemplate;
|
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 COUNT_IDENTIFIER = "alfresco.query.rm.select_CountRMIndentifier";
|
||||||
private static final String GET_CHILDREN_PROPERTY_VALUES = "select_GetStringPropertyValuesOfChildren";
|
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 */
|
/** SQL session template */
|
||||||
protected SqlSessionTemplate template;
|
protected SqlSessionTemplate template;
|
||||||
@@ -101,7 +109,7 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
if (pair != null)
|
if (pair != null)
|
||||||
{
|
{
|
||||||
// create query params
|
// 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("qnameId", pair.getFirst());
|
||||||
params.put("idValue", identifierValue);
|
params.put("idValue", identifierValue);
|
||||||
|
|
||||||
@@ -143,4 +151,41 @@ public class RecordsManagementQueryDAOImpl implements RecordsManagementQueryDAO,
|
|||||||
return new HashSet<>(template.selectList(GET_CHILDREN_PROPERTY_VALUES, queryParams));
|
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;
|
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
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.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
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
|
* Utility class to duplicate the content of a node without triggering the audit or versioning behaviours
|
||||||
* @author Ross Gale
|
* @author Ross Gale
|
||||||
@@ -45,6 +49,14 @@ public class ContentBinDuplicationUtility extends ServiceBaseImpl
|
|||||||
*/
|
*/
|
||||||
private BehaviourFilter behaviourFilter;
|
private BehaviourFilter behaviourFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides methods for accessing and transforming content.
|
||||||
|
*/
|
||||||
|
private ContentService contentService;
|
||||||
|
|
||||||
|
/** Records Management Query DAO */
|
||||||
|
private RecordsManagementQueryDAO recordsManagementQueryDAO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for behaviour filter
|
* Setter for behaviour filter
|
||||||
* @param behaviourFilter BehaviourFilter
|
* @param behaviourFilter BehaviourFilter
|
||||||
@@ -54,6 +66,44 @@ public class ContentBinDuplicationUtility extends ServiceBaseImpl
|
|||||||
this.behaviourFilter = behaviourFilter;
|
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
|
* Duplicate the content of a node without triggering the audit or versioning behaviours
|
||||||
*
|
*
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
package org.alfresco.module.org_alfresco_module_rm.util;
|
package org.alfresco.module.org_alfresco_module_rm.util;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.service.cmr.repository.ContentReader;
|
import org.alfresco.service.cmr.repository.ContentReader;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
@@ -39,6 +40,12 @@ import org.mockito.InjectMocks;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -50,6 +57,9 @@ import static org.mockito.Mockito.when;
|
|||||||
*/
|
*/
|
||||||
public class ContentBinDuplicationUtilityUnitTest
|
public class ContentBinDuplicationUtilityUnitTest
|
||||||
{
|
{
|
||||||
|
private final static NodeRef NODE_REF = new NodeRef("some://test/noderef");
|
||||||
|
private final static NodeRef NODE_REF2 = new NodeRef("some://test/anothernoderef");
|
||||||
|
private final static String CONTENT_URL = "someContentUrl";
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
@@ -63,6 +73,9 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
@Mock
|
@Mock
|
||||||
private ContentWriter contentWriter;
|
private ContentWriter contentWriter;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private RecordsManagementQueryDAO recordsManagementQueryDAO;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
||||||
|
|
||||||
@@ -78,10 +91,9 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testContentUrlIsUpdated()
|
public void testContentUrlIsUpdated()
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
when(contentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(contentWriter);
|
||||||
when(contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true)).thenReturn(contentWriter);
|
contentBinDuplicationUtility.duplicate(NODE_REF);
|
||||||
contentBinDuplicationUtility.duplicate(nodeRef);
|
|
||||||
verify(contentWriter, times(1)).putContent(contentReader);
|
verify(contentWriter, times(1)).putContent(contentReader);
|
||||||
checkBehaviours(1);
|
checkBehaviours(1);
|
||||||
}
|
}
|
||||||
@@ -92,13 +104,58 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testDuplicationDoesntHappenWithNoContent()
|
public void testDuplicationDoesntHappenWithNoContent()
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = new NodeRef("some://test/noderef");
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null);
|
||||||
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(null);
|
contentBinDuplicationUtility.duplicate(NODE_REF);
|
||||||
contentBinDuplicationUtility.duplicate(nodeRef);
|
|
||||||
verify(contentWriter, times(0)).putContent(contentReader);
|
verify(contentWriter, times(0)).putContent(contentReader);
|
||||||
checkBehaviours(1);
|
checkBehaviours(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test hasAtLeastOneOtherReference returns true when node has another reference to it
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testHasAtLeastOneOtherReference()
|
||||||
|
{
|
||||||
|
Set<String> multipleReferences = new HashSet<>();
|
||||||
|
Collections.addAll(multipleReferences, NODE_REF.getId(), NODE_REF2.getId());
|
||||||
|
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(CONTENT_URL);
|
||||||
|
when(recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(CONTENT_URL)).thenReturn(multipleReferences);
|
||||||
|
|
||||||
|
assertTrue(contentBinDuplicationUtility.hasAtLeastOneOtherReference(NODE_REF));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test hasAtLeastOneOtherReference returns false when node has no other reference to it other than its own content ref
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testHasNoOtherReference()
|
||||||
|
{
|
||||||
|
Set<String> singleReference = Collections.singleton(NODE_REF.getId());
|
||||||
|
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(CONTENT_URL);
|
||||||
|
when(recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(CONTENT_URL)).thenReturn(singleReference);
|
||||||
|
|
||||||
|
assertFalse(contentBinDuplicationUtility.hasAtLeastOneOtherReference(NODE_REF));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test hasAtLeastOneOtherReference returns false when node has no references to it at all
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testHasNoReferences()
|
||||||
|
{
|
||||||
|
Set<String> noReferences = Collections.<String> emptySet();
|
||||||
|
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
|
||||||
|
when(contentService.getReader(NODE_REF, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(CONTENT_URL);
|
||||||
|
when(recordsManagementQueryDAO.getNodeRefsWhichReferenceContentUrl(CONTENT_URL)).thenReturn(noReferences);
|
||||||
|
|
||||||
|
assertFalse(contentBinDuplicationUtility.hasAtLeastOneOtherReference(NODE_REF));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the behaviours are disabled and re-enabled the correct number of times
|
* Check that the behaviours are disabled and re-enabled the correct number of times
|
||||||
* @param times the times the behaviours should be called
|
* @param times the times the behaviours should be called
|
||||||
|
Reference in New Issue
Block a user