Merge branch 'merge/RM-6787_VersionWhenClassifyFileWithCopies' into 'master'

Resolve RM-6787 "Merge/ versionwhenclassifyfilewithcopies"

Closes RM-6787

See merge request records-management/records-management!1150
This commit is contained in:
Rodica Sutu
2019-04-10 10:54:41 +01:00
10 changed files with 320 additions and 138 deletions

View File

@@ -248,6 +248,12 @@
</property>
</bean>
<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="nodeService" ref="nodeService"/>
</bean>
<!-- Prevent ghosted records being renditioned -->
<bean id="noRenditionsForGhosts" parent="baseRenditionPreventionClass">
<constructor-arg value="rma:ghosted"/>

View File

@@ -145,6 +145,7 @@
<property name="recordService" ref="RecordService" />
<property name="dispositionService" ref="DispositionService" />
<property name="quickShareService" ref="QuickShareService"/>
<property name="contentBinDuplicationUtility" ref="contentBinDuplicationUtility"/>
</bean>
<bean id="rma.recordComponentIdentifier" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.RecordComponentIdentifierAspect" parent="rm.baseBehaviour">

View File

@@ -17,6 +17,7 @@
<bean id="rmv.versionRecord" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.VersionRecordAspect" parent="rm.baseBehaviour">
<property name="recordableVersionService" ref="RecordableVersionService" />
<property name="relationshipService" ref="RelationshipService" />
<property name="contentBinDuplicationUtility" ref="contentBinDuplicationUtility"/>
</bean>
<!-- extended version service bean definition -->

View File

@@ -31,8 +31,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Sets;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.repo.policy.BehaviourFilter;
@@ -43,8 +44,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.surf.util.I18NUtil;
import com.google.common.collect.Sets;
/**
* Convenient base class for behaviour beans.
*
@@ -102,7 +101,7 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
/**
* Helper method that checks if the newly created child association complies with the RM rules
* @param parent the parent node
* @param childType the child node
* @param child the child node
* @param acceptedUniqueChildType a list of node types that are accepted as children of the provided parent only once
* @param acceptedMultipleChildType a list of node types that are accepted as children of the provided parent multiple times
* @throws IntegrityException if the child association doesn't comply with the RM rules
@@ -126,7 +125,7 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
/**
* Helper method that checks if the newly created child association is between the sub-types of accepted types.
* @param childType the child node
* @param child the child node
* @param acceptedMultipleChildType a list of node types that are accepted as children of the provided parent multiple times
* @throws IntegrityException if the child association isn't between the sub-types of accepted types
*/
@@ -144,31 +143,4 @@ public abstract class BaseBehaviourBean extends ServiceBaseImpl
throw new IntegrityException(I18NUtil.getMessage(MULTIPLE_CHILDREN_TYPE_ERROR, childType), null);
}
/**
* Helper method to duplicate the bin file of a node and replace the contenturl property with the new reference
*
* @param nodeRef The node to update with a new copy of the bin file
*/
protected void duplicateContentFileIfRequired(NodeRef nodeRef)
{
//Adding fix for RM-6788 where too many duplicates are being made this is a workaround waiting on a full solution
if (!nodeService.hasAspect(nodeRef, ASPECT_ARCHIVED))
{
//disable versioning and auditing
behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
behaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
try
{
//create a new content URL for the copy/original node
createNewContentURL(nodeRef);
}
finally
{
//enable versioning and auditing
behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
}
}
}
}

View File

@@ -38,6 +38,7 @@ import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.copy.CopyBehaviourCallback;
import org.alfresco.repo.copy.CopyDetails;
@@ -94,6 +95,9 @@ public class RecordAspect extends AbstractDisposableItem
/** quickShare service */
private QuickShareService quickShareService;
/** Utility class for duplicating content */
private ContentBinDuplicationUtility contentBinDuplicationUtility;
/** I18N */
private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content";
@@ -130,6 +134,15 @@ public class RecordAspect extends AbstractDisposableItem
this.quickShareService = quickShareService;
}
/**
* Setter for content duplication utility class
* @param contentBinDuplicationUtility ContentBinDuplicationUtility
*/
public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility)
{
this.contentBinDuplicationUtility = contentBinDuplicationUtility;
}
/**
* Behaviour to ensure renditions have the appropriate extended security.
*
@@ -356,7 +369,7 @@ public class RecordAspect extends AbstractDisposableItem
extendedSecurityService.remove(targetNodeRef);
//create a new content URL for the copy
createNewContentURL(targetNodeRef);
contentBinDuplicationUtility.duplicate(targetNodeRef);
}
}
@@ -401,7 +414,7 @@ public class RecordAspect extends AbstractDisposableItem
if (!nodeService.getTargetAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty() ||
!nodeService.getSourceAssocs(nodeRef, ContentModel.ASSOC_ORIGINAL).isEmpty())
{
duplicateContentFileIfRequired(nodeRef);
contentBinDuplicationUtility.duplicate(nodeRef);
}
return null;

View File

@@ -33,6 +33,7 @@ import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship;
import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService;
import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility;
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionService;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
@@ -64,6 +65,11 @@ public class VersionRecordAspect extends BaseBehaviourBean
/** relationship service */
private RelationshipService relationshipService;
/**
* Utility class for duplicating content
*/
private ContentBinDuplicationUtility contentBinDuplicationUtility;
/**
* @param recordableVersionService recordable version service
*/
@@ -80,6 +86,16 @@ public class VersionRecordAspect extends BaseBehaviourBean
this.relationshipService = relationshipService;
}
/**
* Setter for content duplication utility class
*
* @param contentBinDuplicationUtility ContentBinDuplicationUtility
*/
public void setContentBinDuplicationUtility(ContentBinDuplicationUtility contentBinDuplicationUtility)
{
this.contentBinDuplicationUtility = contentBinDuplicationUtility;
}
/**
* If the record is a version record then delete the associated version entry
*
@@ -148,7 +164,7 @@ public class VersionRecordAspect extends BaseBehaviourBean
if (!nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_RECORD_ORIGINATING_DETAILS))
{
//create a new content URL for the version record
createNewContentURL(nodeRef);
contentBinDuplicationUtility.duplicate(nodeRef);
}
}
}

View File

@@ -0,0 +1,138 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 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.util;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_ARCHIVED;
import org.alfresco.model.ContentModel;
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 org.alfresco.service.cmr.repository.NodeService;
/**
* Utility class to duplicate the content of a node without triggering the audit or versioning behaviours
* @author Ross Gale
* @since 2.7.2
*/
public class ContentBinDuplicationUtility
{
/**
* Behaviour filter
*/
private BehaviourFilter behaviourFilter;
/**
* Provides methods for accessing and transforming content.
*/
private ContentService contentService;
/**
* Node service
*/
private NodeService nodeService;
/**
* Setter for behaviour filter
* @param behaviourFilter BehaviourFilter
*/
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
{
this.behaviourFilter = behaviourFilter;
}
/**
* Setter for content service
* @param contentService ContentService
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Setter for node service
*
* @param nodeService NodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Getter for node service
*
* @return nodeService
*/
public NodeService getNodeService()
{
return nodeService;
}
/**
* Duplicate the content of a node without triggering the audit or versioning behaviours
*
* @param nodeRef The node with the content to duplicate
*/
public void duplicate(NodeRef nodeRef)
{
//Adding fix for RM-6788 where too many duplicates are being made this is a workaround waiting on a full
// solution
if (!nodeService.hasAspect(nodeRef, ASPECT_ARCHIVED))
{
//disabling versioning and auditing
behaviourFilter.disableBehaviour();
try
{
//create a new content URL for the copy/original node
updateContentProperty(nodeRef);
}
finally
{
//enable versioning and auditing
behaviourFilter.enableBehaviour();
}
}
}
/**
* Helper to update the content property for the node
*
* @param nodeRef the node
*/
private void updateContentProperty(NodeRef nodeRef)
{
ContentReader reader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (reader != null)
{
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
writer.putContent(reader);
}
}
}

View File

@@ -31,7 +31,7 @@ import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.hold.HoldService;
@@ -39,9 +39,7 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.rendition.RenditionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
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;
import org.alfresco.service.namespace.QName;
@@ -554,30 +552,4 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
result.add(nodeService.getType(nodeRef));
return result;
}
/**
* Helper to update the given content property for the node
*
* @param nodeRef the node
* @param contentProperty the property to be updated
*/
protected void updateContentProperty(NodeRef nodeRef, QName contentProperty)
{
ContentReader reader = contentService.getReader(nodeRef, contentProperty);
if (reader != null)
{
ContentWriter writer = contentService.getWriter(nodeRef, contentProperty, true);
writer.putContent(reader);
}
}
/**
* Helper to create a new content URL for the node
*
* @param nodeRef the node
*/
protected void createNewContentURL(NodeRef nodeRef)
{
updateContentProperty(nodeRef, ContentModel.PROP_CONTENT);
}
}

View File

@@ -31,8 +31,6 @@ import static java.util.Collections.emptyList;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_ARCHIVED;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_RECORD;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -40,11 +38,8 @@ import static org.mockito.MockitoAnnotations.initMocks;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility;
import org.alfresco.service.cmr.repository.AssociationRef;
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;
import org.junit.Before;
@@ -71,15 +66,9 @@ public class RecordAspectUnitTest
@Mock
private NodeService mockNodeService;
@Mock
private BehaviourFilter mockBehaviorFilter;
@Mock
private ContentService mockContentService;
@Mock
private ContentReader mockContentReader;
@Mock
private ContentWriter mockContentWriter;
@Mock
private ExtendedSecurityService mockExtendedSecurityService;
@Mock
private ContentBinDuplicationUtility mockContentBinDuplicationUtility;
@Before
public void setUp()
@@ -92,12 +81,10 @@ public class RecordAspectUnitTest
public void testDuplicateBinBeforeAddingAspectForFileWithCopy()
{
when(mockNodeService.getSourceAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(SOURCE_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(1);
verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
}
/** Check that the bin is duplicated before adding the aspect if the file is a copy. */
@@ -105,29 +92,10 @@ public class RecordAspectUnitTest
public void testDuplicateBinBeforeAddingAspectForCopy()
{
when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(NODE_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(1);
}
/** Check that no content bin is created if the file does not have content. */
@Test
public void testBeforeAddAspectOnFileWithNoContent()
{
when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(1)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
verify(mockContentService, times(1)).getReader(NODE_REF, ContentModel.PROP_CONTENT);
verify(mockContentService, never()).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true);
verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(1)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
}
/** Check that the bin is not duplicated before adding the aspect if the node has no copies. */
@@ -139,7 +107,7 @@ public class RecordAspectUnitTest
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(0);
verify(mockContentBinDuplicationUtility, times(0)).duplicate(NODE_REF);
}
/** Check that the bin is duplicated when copying a record. */
@@ -148,47 +116,12 @@ public class RecordAspectUnitTest
{
when(mockNodeService.exists(COPY_REF)).thenReturn(true);
when(mockNodeService.hasAspect(COPY_REF, ASPECT_RECORD)).thenReturn(true);
when(mockContentService.getReader(COPY_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(COPY_REF, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
recordAspect.onCopyComplete(null, NODE_REF, COPY_REF, true, null);
verify(mockExtendedSecurityService, times(1)).remove(COPY_REF);
verify(mockContentService, times(1)).getReader(COPY_REF, ContentModel.PROP_CONTENT);
verify(mockContentService, times(1)).getWriter(COPY_REF, ContentModel.PROP_CONTENT, true);
verify(mockContentWriter, times(1)).putContent(mockContentReader);
verify(mockContentBinDuplicationUtility, times(1)).duplicate(COPY_REF);
}
/**
* This is testing the fix for RM-6788 where archived content couldn't be declared as a record
* This was caused by attempting to copy the bin file and updating the content url of the
* archived piece of content which failed as this is a protected property. This is done if
* the node is/has a copy but the same duplication already happens during archive.
*/
@Test
public void testBinFileNotDuplicatedForArchivedContent()
{
when(mockNodeService.getTargetAssocs(NODE_REF, ContentModel.ASSOC_ORIGINAL)).thenReturn(asList(TARGET_ASSOC_REF));
when(mockContentService.getReader(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(null);
when(mockNodeService.hasAspect(NODE_REF, ASPECT_ARCHIVED)).thenReturn(true);
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
verifyBeforeAddAspectMethodsInvocations(0);
}
/**
* Helper to verify beforeAddAspect methods invocations
*
* @param wantedNumberOfInvocations wanted number of invocations for each method
*/
private void verifyBeforeAddAspectMethodsInvocations(int wantedNumberOfInvocations)
{
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).disableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
verify(mockContentService, times(wantedNumberOfInvocations)).getReader(NODE_REF, ContentModel.PROP_CONTENT);
verify(mockContentService, times(wantedNumberOfInvocations)).getWriter(NODE_REF, ContentModel.PROP_CONTENT, true);
verify(mockContentWriter, times(wantedNumberOfInvocations)).putContent(mockContentReader);
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_AUDITABLE));
verify(mockBehaviorFilter, times(wantedNumberOfInvocations)).enableBehaviour(eq(ContentModel.ASPECT_VERSIONABLE));
}
}

View File

@@ -0,0 +1,130 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 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.util;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_ARCHIVED;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.alfresco.model.ContentModel;
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 org.alfresco.service.cmr.repository.NodeService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Test class for the ContentBinDuplicationUtility
* @author Ross Gale
* @since 2.7.2
*/
public class ContentBinDuplicationUtilityUnitTest
{
@Mock
private ContentService mockContentService;
@Mock
private BehaviourFilter mockBehaviourFilter;
@Mock
private ContentReader mockContentReader;
@Mock
private ContentWriter mockContentWriter;
@Mock
private NodeService mockNodeService;
@InjectMocks
private ContentBinDuplicationUtility contentBinDuplicationUtility;
@Before
public void setUp()
{
MockitoAnnotations.initMocks(this);
}
/**
* Tests that the requests are made to disable and re-enable the audit and versioning and to update the content bin
*/
@Test
public void testContentUrlIsUpdated()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
when(mockContentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(mockContentReader);
when(mockContentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true)).thenReturn(mockContentWriter);
contentBinDuplicationUtility.duplicate(nodeRef);
verify(mockContentWriter, times(1)).putContent(mockContentReader);
checkBehaviours(1);
}
/**
* Test content duplication doesn't happen when node has no content
*/
@Test
public void testDuplicationDoesntHappenWithNoContent()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
when(mockContentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(null);
contentBinDuplicationUtility.duplicate(nodeRef);
verify(mockContentWriter, times(0)).putContent(mockContentReader);
checkBehaviours(1);
}
/**
* This is testing the fix for RM-6788 where archived content couldn't be declared as a record
* This was caused by attempting to copy the bin file and updating the content url of the
* archived piece of content which failed as this is a protected property. This is done if
* the node is/has a copy but the same duplication already happens during archive.
*/
@Test
public void testBinFileNotDuplicatedForArchivedContent()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
when(mockNodeService.hasAspect(nodeRef, ASPECT_ARCHIVED)).thenReturn(true);
contentBinDuplicationUtility.duplicate(nodeRef);
verify(mockContentReader, times(0)).getReader();
checkBehaviours(0);
}
/**
* Check that the behaviours are disabled and re-enabled the correct number of times
* @param times the times the behaviours should be called
*/
private void checkBehaviours(int times)
{
verify(mockBehaviourFilter, times(times)).disableBehaviour();
verify(mockBehaviourFilter, times(times)).enableBehaviour();
}
}