mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-6787 updating copy and add behaviors for other aspects to use duplication utility class
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
<bean id="rmv.versionRecord" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.VersionRecordAspect" parent="rm.baseBehaviour">
|
<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="recordableVersionService" ref="RecordableVersionService" />
|
||||||
<property name="relationshipService" ref="RelationshipService" />
|
<property name="relationshipService" ref="RelationshipService" />
|
||||||
|
<property name="contentBinDuplicationUtility" ref="contentBinDuplicationUtility"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- extended version service bean definition -->
|
<!-- extended version service bean definition -->
|
||||||
|
@@ -369,7 +369,7 @@ public class RecordAspect extends AbstractDisposableItem
|
|||||||
extendedSecurityService.remove(targetNodeRef);
|
extendedSecurityService.remove(targetNodeRef);
|
||||||
|
|
||||||
//create a new content URL for the copy
|
//create a new content URL for the copy
|
||||||
createNewContentURL(targetNodeRef);
|
contentBinDuplicationUtility.duplicate(targetNodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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.model.RecordsManagementModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.relationship.Relationship;
|
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.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.module.org_alfresco_module_rm.version.RecordableVersionService;
|
||||||
import org.alfresco.repo.node.NodeServicePolicies;
|
import org.alfresco.repo.node.NodeServicePolicies;
|
||||||
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
||||||
@@ -64,6 +65,11 @@ public class VersionRecordAspect extends BaseBehaviourBean
|
|||||||
/** relationship service */
|
/** relationship service */
|
||||||
private RelationshipService relationshipService;
|
private RelationshipService relationshipService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for duplicating content
|
||||||
|
*/
|
||||||
|
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param recordableVersionService recordable version service
|
* @param recordableVersionService recordable version service
|
||||||
*/
|
*/
|
||||||
@@ -80,6 +86,16 @@ public class VersionRecordAspect extends BaseBehaviourBean
|
|||||||
this.relationshipService = relationshipService;
|
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
|
* 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))
|
if (!nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_RECORD_ORIGINATING_DETAILS))
|
||||||
{
|
{
|
||||||
//create a new content URL for the version record
|
//create a new content URL for the version record
|
||||||
createNewContentURL(nodeRef);
|
contentBinDuplicationUtility.duplicate(nodeRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,9 @@ package org.alfresco.module.org_alfresco_module_rm.util;
|
|||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
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.ContentService;
|
||||||
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,23 +38,37 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
* @author Ross Gale
|
* @author Ross Gale
|
||||||
* @since 2.7.2
|
* @since 2.7.2
|
||||||
*/
|
*/
|
||||||
public class ContentBinDuplicationUtility extends ServiceBaseImpl
|
public class ContentBinDuplicationUtility
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Behaviour filter
|
* Behaviour filter
|
||||||
*/
|
*/
|
||||||
protected BehaviourFilter behaviourFilter;
|
private BehaviourFilter behaviourFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides methods for accessing and transforming content.
|
||||||
|
*/
|
||||||
|
private ContentService contentService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setter for behaviour filter
|
* Setter for behaviour filter
|
||||||
* @param behaviourFilter
|
* @param behaviourFilter BehaviourFilter
|
||||||
*/
|
*/
|
||||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||||
{
|
{
|
||||||
this.behaviourFilter = behaviourFilter;
|
this.behaviourFilter = behaviourFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for content service
|
||||||
|
* @param contentService ContentService
|
||||||
|
*/
|
||||||
|
public void setContentService(ContentService contentService)
|
||||||
|
{
|
||||||
|
this.contentService = contentService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*
|
*
|
||||||
@@ -60,19 +77,31 @@ public class ContentBinDuplicationUtility extends ServiceBaseImpl
|
|||||||
public void duplicate(NodeRef nodeRef)
|
public void duplicate(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
//disabling versioning and auditing
|
//disabling versioning and auditing
|
||||||
behaviourFilter.disableBehaviour(ContentModel.ASPECT_AUDITABLE);
|
behaviourFilter.disableBehaviour();
|
||||||
behaviourFilter.disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//create a new content URL for the copy/original node
|
//create a new content URL for the copy/original node
|
||||||
createNewContentURL(nodeRef);
|
updateContentProperty(nodeRef);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
//enable versioning and auditing
|
//enable versioning and auditing
|
||||||
behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE);
|
behaviourFilter.enableBehaviour();
|
||||||
behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
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.FilePlanComponentKind;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.hold.HoldService;
|
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.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.rendition.RenditionService;
|
import org.alfresco.service.cmr.rendition.RenditionService;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
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.ContentService;
|
||||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
||||||
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.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
@@ -554,30 +552,4 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte
|
|||||||
result.add(nodeService.getType(nodeRef));
|
result.add(nodeService.getType(nodeRef));
|
||||||
return result;
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -76,7 +76,7 @@ public class RecordAspectUnitTest
|
|||||||
@Mock
|
@Mock
|
||||||
private ExtendedSecurityService mockExtendedSecurityService;
|
private ExtendedSecurityService mockExtendedSecurityService;
|
||||||
@Mock
|
@Mock
|
||||||
private ContentBinDuplicationUtility contentBinDuplicationUtility;
|
private ContentBinDuplicationUtility mockContentBinDuplicationUtility;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
@@ -94,7 +94,7 @@ public class RecordAspectUnitTest
|
|||||||
|
|
||||||
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
|
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
|
||||||
|
|
||||||
verify(contentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
|
verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check that the bin is duplicated before adding the aspect if the file is a copy. */
|
/** Check that the bin is duplicated before adding the aspect if the file is a copy. */
|
||||||
@@ -107,7 +107,7 @@ public class RecordAspectUnitTest
|
|||||||
|
|
||||||
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
|
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
|
||||||
|
|
||||||
verify(contentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
|
verify(mockContentBinDuplicationUtility, times(1)).duplicate(NODE_REF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check that the bin is not duplicated before adding the aspect if the node has no copies. */
|
/** Check that the bin is not duplicated before adding the aspect if the node has no copies. */
|
||||||
@@ -119,7 +119,7 @@ public class RecordAspectUnitTest
|
|||||||
|
|
||||||
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
|
recordAspect.beforeAddAspect(NODE_REF, ASPECT_RECORD);
|
||||||
|
|
||||||
verify(contentBinDuplicationUtility, times(0)).duplicate(NODE_REF);
|
verify(mockContentBinDuplicationUtility, times(0)).duplicate(NODE_REF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check that the bin is duplicated when copying a record. */
|
/** Check that the bin is duplicated when copying a record. */
|
||||||
@@ -134,8 +134,6 @@ public class RecordAspectUnitTest
|
|||||||
recordAspect.onCopyComplete(null, NODE_REF, COPY_REF, true, null);
|
recordAspect.onCopyComplete(null, NODE_REF, COPY_REF, true, null);
|
||||||
|
|
||||||
verify(mockExtendedSecurityService, times(1)).remove(COPY_REF);
|
verify(mockExtendedSecurityService, times(1)).remove(COPY_REF);
|
||||||
verify(mockContentService, times(1)).getReader(COPY_REF, ContentModel.PROP_CONTENT);
|
verify(mockContentBinDuplicationUtility, times(1)).duplicate(COPY_REF);
|
||||||
verify(mockContentService, times(1)).getWriter(COPY_REF, ContentModel.PROP_CONTENT, true);
|
|
||||||
verify(mockContentWriter, times(1)).putContent(mockContentReader);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -105,9 +105,7 @@ public class ContentBinDuplicationUtilityUnitTest
|
|||||||
*/
|
*/
|
||||||
private void checkBehaviours(int times)
|
private void checkBehaviours(int times)
|
||||||
{
|
{
|
||||||
verify(behaviourFilter, times(times)).disableBehaviour(ContentModel.ASPECT_AUDITABLE);
|
verify(behaviourFilter, times(times)).disableBehaviour();
|
||||||
verify(behaviourFilter, times(times)).disableBehaviour(ContentModel.ASPECT_VERSIONABLE);
|
verify(behaviourFilter, times(times)).enableBehaviour();
|
||||||
verify(behaviourFilter, times(times)).enableBehaviour(ContentModel.ASPECT_AUDITABLE);
|
|
||||||
verify(behaviourFilter, times(times)).enableBehaviour(ContentModel.ASPECT_VERSIONABLE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user