diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java index fe4534e345..3d5310997b 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java @@ -34,7 +34,6 @@ import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDispos 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; import org.alfresco.repo.copy.CopyServicePolicies; @@ -77,8 +76,7 @@ public class RecordAspect extends AbstractDisposableItem RecordsManagementPolicies.OnRemoveReference, NodeServicePolicies.OnMoveNodePolicy, CopyServicePolicies.OnCopyCompletePolicy, - NodeServicePolicies.OnUpdatePropertiesPolicy, - ContentServicePolicies.OnContentPropertyUpdatePolicy + NodeServicePolicies.OnUpdatePropertiesPolicy { /** Well-known location of the scripts folder. */ // TODO make configurable @@ -101,7 +99,7 @@ public class RecordAspect extends AbstractDisposableItem /** I18N */ private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content"; - private static final String MSG_UPDATE_STORE_NAME = "rm.action.update-store-name"; + private static final String MSG_WORM_RECORD_LOCKED = "rm.action.worm-record-locked"; // WORM lock aspect public static final String RME_URI = "http://www.alfresco.org/model/recordsmanagemententerprise/1.0"; @@ -412,51 +410,43 @@ public class RecordAspect extends AbstractDisposableItem }, AuthenticationUtil.getSystemUserName()); } - /** - * Behaviour to prevent content update for records - * - * @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(NodeRef, Map, Map) - */ - @Override - @Behaviour - ( - kind = BehaviourKind.CLASS, - notificationFrequency = NotificationFrequency.FIRST_EVENT - ) - public void onUpdateProperties(NodeRef nodeRef, Map before, Map after) - { - String storeNameAfter = (String) after.get(ContentModel.PROP_STORE_NAME); - String storeNameBefore = (String) before.get(ContentModel.PROP_STORE_NAME); - - ContentData contentAfter = (ContentData) after.get(ContentModel.PROP_CONTENT); - if (storeNameAfter != null && !storeNameAfter.equals(storeNameBefore)) + /** + * Behaviour to prevent content update for records + * + * @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(NodeRef, Map, Map) + */ + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + notificationFrequency = NotificationFrequency.FIRST_EVENT + ) + public void onUpdateProperties(NodeRef nodeRef, Map before, Map after) { - if (nodeService.hasAspect(nodeRef, ASPECT_WORM_LOCK)) - { - // we cannot change the worm store name - throw new IntegrityException(MSG_UPDATE_STORE_NAME, null); - } - // Does not allow setting content to null when moving content between stores (case not covered by - // ContentPropertyRestrictionInterceptor) - else if (contentAfter != null) - { - return; - } - } - } + String storeNameAfter = (String) after.get(ContentModel.PROP_STORE_NAME); + ContentData contentBefore = (ContentData) before.get(ContentModel.PROP_CONTENT); + ContentData contentAfter = (ContentData) after.get(ContentModel.PROP_CONTENT); + // Check only storeNameAfter since the store name is updated before this method is triggered + // Does not allow setting content to null when moving content between stores (case not covered by + // ContentPropertyRestrictionInterceptor) + if (storeNameAfter != null) + { + if (nodeService.hasAspect(nodeRef, ASPECT_WORM_LOCK)) + { + if (contentBefore != null && !contentBefore.equals(contentAfter)) + { - @Override - @Behaviour - ( - kind = BehaviourKind.CLASS, - notificationFrequency = NotificationFrequency.FIRST_EVENT - ) - public void onContentPropertyUpdate(NodeRef nodeRef, QName propertyQName, ContentData beforeValue, ContentData afterValue) - { - // Allow creation of content but not update - if (beforeValue != null) - { - throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_UPDATE_RECORD_CONTENT), null); + throw new IntegrityException(MSG_WORM_RECORD_LOCKED, null); + } + } + if (contentAfter != null) + { + return; + } + } + if (contentBefore != null && !contentBefore.equals(contentAfter)) + { + throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_UPDATE_RECORD_CONTENT), null); + } } - } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java index 5b18bc46b8..3c2d422c38 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspectUnitTest.java @@ -26,23 +26,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; - -import static org.alfresco.model.ContentModel.PROP_CONTENT; -import static org.alfresco.model.ContentModel.PROP_STORE_NAME; -import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_RECORD; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; - -import java.io.Serializable; -import java.util.Locale; -import java.util.Map; - import com.google.common.collect.ImmutableMap; - import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.util.ContentBinDuplicationUtility; @@ -57,6 +41,20 @@ import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import java.io.Serializable; +import java.util.Locale; +import java.util.Map; + +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static org.alfresco.model.ContentModel.PROP_CONTENT; +import static org.alfresco.model.ContentModel.PROP_STORE_NAME; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_RECORD; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + /** * Unit tests for the {@link RecordAspect}. * @@ -145,4 +143,15 @@ public class RecordAspectUnitTest "/plain", 0L, "UTF-8", Locale.UK), PROP_STORE_NAME, "store2"); recordAspect.onUpdateProperties(NODE_REF, before, after); } + + /** + * Check that an IntegrityException is thrown when content is changed + */ + @Test(expected = IntegrityException.class) + public void testOnUpdatePropertiesContentChanged() + { + Map before = ImmutableMap.of(PROP_CONTENT, new ContentData("dummyContentUrl", "text/plain", 0L, "UTF-8", Locale.UK)); + Map after = ImmutableMap.of(PROP_CONTENT, new ContentData("dummyContentUrl2", "text" + "/plain", 0L, "UTF-8", Locale.UK)); + recordAspect.onUpdateProperties(NODE_REF, before, after); + } }