From 958f3760f50caee9ebafb9bed7611355cdcb7d7d Mon Sep 17 00:00:00 2001 From: estan Date: Mon, 23 Nov 2020 14:42:44 +0200 Subject: [PATCH] APPS-361 [AGS/S3]Moving records between buckets in S3 (also possible moving records between stores-filecontenstore) fails --revert --- .../model/rma/aspect/RecordAspect.java | 44 +++++-------------- .../rma/aspect/RecordAspectUnitTest.java | 24 ---------- 2 files changed, 10 insertions(+), 58 deletions(-) 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 25d03ad145..4957664e3b 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 @@ -27,6 +27,11 @@ package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + import org.alfresco.model.ContentModel; import org.alfresco.model.QuickShareModel; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies; @@ -34,6 +39,7 @@ 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; @@ -54,11 +60,6 @@ import org.alfresco.service.cmr.repository.ScriptService; import org.alfresco.service.namespace.QName; import org.springframework.extensions.surf.util.I18NUtil; -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - /** * rma:record behaviour bean * @@ -76,7 +77,7 @@ public class RecordAspect extends AbstractDisposableItem RecordsManagementPolicies.OnRemoveReference, NodeServicePolicies.OnMoveNodePolicy, CopyServicePolicies.OnCopyCompletePolicy, - NodeServicePolicies.OnUpdatePropertiesPolicy + ContentServicePolicies.OnContentPropertyUpdatePolicy { /** Well-known location of the scripts folder. */ // TODO make configurable @@ -99,7 +100,6 @@ 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_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"; @@ -410,40 +410,16 @@ 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) + public void onContentPropertyUpdate(NodeRef nodeRef, QName propertyQName, ContentData beforeValue, ContentData afterValue) { - 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)) - { - throw new IntegrityException(I18NUtil.getMessage(MSG_WORM_RECORD_LOCKED), null); - } - } - if (contentAfter != null) - { - return; - } - } - if (contentBefore != null && !contentBefore.equals(contentAfter)) + // Allow creation of content but not update + if (beforeValue != null) { 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 56621d505f..249bc72556 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 @@ -132,28 +132,4 @@ public class RecordAspectUnitTest verify(mockExtendedSecurityService, times(1)).remove(COPY_REF); verify(mockContentBinDuplicationUtility, times(1)).duplicate(COPY_REF); } - - /** - * Check that no exception is thrown when moving record between stores - */ - @Test - public void testOnUpdatePropertiesContentMovedToAnotherStore() - { - Map before = ImmutableMap.of(PROP_CONTENT, new ContentData("dummyContentUrl1", "text" + - "/plain", 0L, "UTF-8", Locale.UK)); - Map after = ImmutableMap.of(PROP_CONTENT, new ContentData("dummyContentUrl2", "text" + - "/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); - } }