From a27e2aaa9ebb62c65342a5f0c9d47dbf05760b17 Mon Sep 17 00:00:00 2001 From: estan Date: Sun, 28 Feb 2021 10:48:20 +0200 Subject: [PATCH 01/10] APPS-659 [Upgrade] Search Result points to incorrect link to Folder on Hold --- .../v35/RMv35HoldNewChildAssocPatch.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java index 0b620d07df..368e4c7e50 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java @@ -26,6 +26,11 @@ */ package org.alfresco.module.org_alfresco_module_rm.patch.v35; +import static org.alfresco.model.ContentModel.ASSOC_CONTAINS; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_CONTENT; + +import java.util.List; + import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.hold.HoldService; @@ -34,13 +39,13 @@ import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.namespace.RegexQNamePattern; /** * Patch to create new hold child association to link the record to the hold - * + *

* See: https://alfresco.atlassian.net/browse/APPS-659 * - * * @since 3.5 */ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch @@ -64,6 +69,7 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch /** * Setter for fileplanservice + * * @param filePlanService File plan service interface */ public void setFilePlanService(FilePlanService filePlanService) @@ -73,6 +79,7 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch /** * Setter for hold service + * * @param holdService Hold service interface. */ public void setHoldService(HoldService holdService) @@ -82,6 +89,7 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch /** * Setter for node service + * * @param nodeService Interface for public and internal node and store operations. */ public void setNodeService(NodeService nodeService) @@ -110,15 +118,21 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch { for (NodeRef hold : holdService.getHolds(filePlan)) { - for (ChildAssociationRef ref : nodeService.getChildAssocs(hold)) + List frozenAssoc = nodeService.getChildAssocs(hold, + ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL); + for (ChildAssociationRef ref : frozenAssoc) { - holdService.removeFromHold(hold, ref.getChildRef()); - holdService.addToHold(hold, ref.getChildRef()); + //search the second parent + List parentAssoc = nodeService.getParentAssocs(ref.getChildRef(), ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); + if (parentAssoc.isEmpty()) + { + ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(hold); + nodeService.addChild(hold, hold, ASSOC_CONTAINS, primaryParentAssoc.getQName()); + } } } } - } - finally + } finally { behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE); behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE); From e7f8862a7bb9650f5b025abf47dfae90992bc0b1 Mon Sep 17 00:00:00 2001 From: estan Date: Sun, 28 Feb 2021 19:22:31 +0200 Subject: [PATCH 02/10] APPS-659 [Upgrade] Search Result points to incorrect link to Folder on Hold --- .../org_alfresco_module_rm/patch/rm-patch-v35-context.xml | 2 +- .../patch/v35/RMv35HoldNewChildAssocPatch.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml index 63ccdb75e8..51dad9f953 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml @@ -10,7 +10,7 @@ parent="rm.parentModulePatch" class="org.alfresco.module.org_alfresco_module_rm.patch.v35.RMv35HoldNewChildAssocPatch"> - + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java index 368e4c7e50..59670184ad 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java @@ -122,12 +122,13 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef ref : frozenAssoc) { + NodeRef nodeRef = ref.getChildRef(); //search the second parent - List parentAssoc = nodeService.getParentAssocs(ref.getChildRef(), ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); + List parentAssoc = nodeService.getParentAssocs(nodeRef, ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); if (parentAssoc.isEmpty()) { - ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(hold); - nodeService.addChild(hold, hold, ASSOC_CONTAINS, primaryParentAssoc.getQName()); + ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(nodeRef); + nodeService.addChild(hold, nodeRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); } } } From b3d8975444fe9d0c725810d6fb77c8c0c9633c97 Mon Sep 17 00:00:00 2001 From: estan Date: Tue, 2 Mar 2021 15:04:41 +0200 Subject: [PATCH 03/10] APPS-659 [Upgrade] Search Result points to incorrect link to Folder on Hold --- .../patch/v35/RMv35HoldNewChildAssocPatch.java | 2 +- .../v35/RMv35HoldNewChildAssocPatchUnitTest.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java index 59670184ad..6a3b131603 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java @@ -125,7 +125,7 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch NodeRef nodeRef = ref.getChildRef(); //search the second parent List parentAssoc = nodeService.getParentAssocs(nodeRef, ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); - if (parentAssoc.isEmpty()) + if (parentAssoc.size() <= 1) { ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(nodeRef); nodeService.addChild(hold, nodeRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java index 01b04de73d..5fd5abdcd5 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java @@ -27,6 +27,8 @@ package org.alfresco.module.org_alfresco_module_rm.patch.v35; +import static org.alfresco.model.ContentModel.ASSOC_CONTAINS; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_CONTENT; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyMap; import static org.mockito.Mockito.doReturn; @@ -48,6 +50,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef; 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.RegexQNamePattern; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -77,11 +80,14 @@ public class RMv35HoldNewChildAssocPatchUnitTest private RMv35HoldNewChildAssocPatch patch; private NodeRef filePlanRef, holdRef, heldItemRef; + private Set fileplans; private List holds; @Mock private ChildAssociationRef childAssociationRef; + @Mock + private ChildAssociationRef primaryParentAssoc; private List childAssocs; @@ -104,15 +110,15 @@ public class RMv35HoldNewChildAssocPatchUnitTest * Test held items are removed from a hold and re-add to make sure the association is correct */ @Test - public void testAHoldIsRemovedAndReplacedDuringUpgrade() + public void testAddChildDuringUpgrade() { when(mockFilePlanService.getFilePlans()).thenReturn(fileplans); when(mockHoldService.getHolds(filePlanRef)).thenReturn(holds); + when(mockNodeService.getChildAssocs(holdRef, ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL)).thenReturn(childAssocs); when(childAssociationRef.getChildRef()).thenReturn(heldItemRef); - when(mockNodeService.getChildAssocs(holdRef)).thenReturn(childAssocs); + when(mockNodeService.getPrimaryParent(heldItemRef)).thenReturn(primaryParentAssoc); patch.applyInternal(); - verify(mockHoldService, times(1)).removeFromHold(holdRef, heldItemRef); - verify(mockHoldService, times(1)).addToHold(holdRef, heldItemRef); + verify(mockNodeService, times(1)).addChild(holdRef, heldItemRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); } @Test From d27b26ded1bfc9bc57d89a697e81f9c93ab8676f Mon Sep 17 00:00:00 2001 From: estan Date: Wed, 3 Mar 2021 15:04:00 +0200 Subject: [PATCH 04/10] APPS-659 [Upgrade] Search Result points to incorrect link to Folder on Hold --changed fixesFromSchema --- .../org_alfresco_module_rm/patch/rm-patch-v35-context.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml index 51dad9f953..cc54b588ad 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v35-context.xml @@ -5,12 +5,12 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - + - + From e2ad8baee45b3917f83dc105f03bbd60c348d984 Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Wed, 3 Mar 2021 14:37:57 +0000 Subject: [PATCH 05/10] [maven-release-plugin][skip ci] prepare release V3.5.0-A6 --- pom.xml | 4 ++-- rm-automation/pom.xml | 2 +- rm-automation/rm-automation-community-rest-api/pom.xml | 2 +- rm-community/pom.xml | 2 +- rm-community/rm-community-repo/pom.xml | 2 +- rm-community/rm-community-rest-api-explorer/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index f30f477d14..f1eb2895e0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.alfresco alfresco-governance-services pom - 3.5.0-SNAPSHOT + 3.5.0-A6 Alfresco Governance Services http://www.alfresco.org/ @@ -18,7 +18,7 @@ scm:git:https://github.com/Alfresco/governance-services.git scm:git:https://github.com/Alfresco/governance-services.git https://github.com/Alfresco/governance-services - HEAD + V3.5.0-A6 diff --git a/rm-automation/pom.xml b/rm-automation/pom.xml index 5eee570158..e65a29758b 100644 --- a/rm-automation/pom.xml +++ b/rm-automation/pom.xml @@ -8,7 +8,7 @@ org.alfresco alfresco-governance-services - 3.5.0-SNAPSHOT + 3.5.0-A6 diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index b559c7682d..053d8bd673 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -8,7 +8,7 @@ org.alfresco alfresco-governance-services-automation - 3.5.0-SNAPSHOT + 3.5.0-A6 diff --git a/rm-community/pom.xml b/rm-community/pom.xml index 3e065f78e6..7f51b4c234 100644 --- a/rm-community/pom.xml +++ b/rm-community/pom.xml @@ -8,7 +8,7 @@ org.alfresco alfresco-governance-services - 3.5.0-SNAPSHOT + 3.5.0-A6 diff --git a/rm-community/rm-community-repo/pom.xml b/rm-community/rm-community-repo/pom.xml index f942056ed3..0cc5c4683e 100644 --- a/rm-community/rm-community-repo/pom.xml +++ b/rm-community/rm-community-repo/pom.xml @@ -9,7 +9,7 @@ org.alfresco alfresco-governance-services-community - 3.5.0-SNAPSHOT + 3.5.0-A6 diff --git a/rm-community/rm-community-rest-api-explorer/pom.xml b/rm-community/rm-community-rest-api-explorer/pom.xml index 7c19b1535b..095133d33e 100644 --- a/rm-community/rm-community-rest-api-explorer/pom.xml +++ b/rm-community/rm-community-rest-api-explorer/pom.xml @@ -7,7 +7,7 @@ org.alfresco alfresco-governance-services-community - 3.5.0-SNAPSHOT + 3.5.0-A6 From 84bd8f5dd9e7221d2280883a3bfa0bbf3ac8576f Mon Sep 17 00:00:00 2001 From: Travis CI User Date: Wed, 3 Mar 2021 14:38:04 +0000 Subject: [PATCH 06/10] [maven-release-plugin][skip ci] prepare for next development iteration --- pom.xml | 4 ++-- rm-automation/pom.xml | 2 +- rm-automation/rm-automation-community-rest-api/pom.xml | 2 +- rm-community/pom.xml | 2 +- rm-community/rm-community-repo/pom.xml | 2 +- rm-community/rm-community-rest-api-explorer/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index f1eb2895e0..f30f477d14 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.alfresco alfresco-governance-services pom - 3.5.0-A6 + 3.5.0-SNAPSHOT Alfresco Governance Services http://www.alfresco.org/ @@ -18,7 +18,7 @@ scm:git:https://github.com/Alfresco/governance-services.git scm:git:https://github.com/Alfresco/governance-services.git https://github.com/Alfresco/governance-services - V3.5.0-A6 + HEAD diff --git a/rm-automation/pom.xml b/rm-automation/pom.xml index e65a29758b..5eee570158 100644 --- a/rm-automation/pom.xml +++ b/rm-automation/pom.xml @@ -8,7 +8,7 @@ org.alfresco alfresco-governance-services - 3.5.0-A6 + 3.5.0-SNAPSHOT diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 053d8bd673..b559c7682d 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -8,7 +8,7 @@ org.alfresco alfresco-governance-services-automation - 3.5.0-A6 + 3.5.0-SNAPSHOT diff --git a/rm-community/pom.xml b/rm-community/pom.xml index 7f51b4c234..3e065f78e6 100644 --- a/rm-community/pom.xml +++ b/rm-community/pom.xml @@ -8,7 +8,7 @@ org.alfresco alfresco-governance-services - 3.5.0-A6 + 3.5.0-SNAPSHOT diff --git a/rm-community/rm-community-repo/pom.xml b/rm-community/rm-community-repo/pom.xml index 0cc5c4683e..f942056ed3 100644 --- a/rm-community/rm-community-repo/pom.xml +++ b/rm-community/rm-community-repo/pom.xml @@ -9,7 +9,7 @@ org.alfresco alfresco-governance-services-community - 3.5.0-A6 + 3.5.0-SNAPSHOT diff --git a/rm-community/rm-community-rest-api-explorer/pom.xml b/rm-community/rm-community-rest-api-explorer/pom.xml index 095133d33e..7c19b1535b 100644 --- a/rm-community/rm-community-rest-api-explorer/pom.xml +++ b/rm-community/rm-community-rest-api-explorer/pom.xml @@ -7,7 +7,7 @@ org.alfresco alfresco-governance-services-community - 3.5.0-A6 + 3.5.0-SNAPSHOT From 5326ebad041c1deaea27265db648613f2659c242 Mon Sep 17 00:00:00 2001 From: estan Date: Thu, 4 Mar 2021 14:42:30 +0200 Subject: [PATCH 07/10] APPS-659 [Upgrade] Search Result points to incorrect link to Folder on Hold --- .../patch/v35/RMv35HoldNewChildAssocPatch.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java index 6a3b131603..21504042e5 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java @@ -39,6 +39,7 @@ import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.service.cmr.repository.ChildAssociationRef; 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.RegexQNamePattern; /** @@ -122,13 +123,14 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef ref : frozenAssoc) { - NodeRef nodeRef = ref.getChildRef(); - //search the second parent - List parentAssoc = nodeService.getParentAssocs(nodeRef, ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); - if (parentAssoc.size() <= 1) + NodeRef childNodeRef = ref.getChildRef(); + List parentAssocs = nodeService.getParentAssocs(childNodeRef, ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); + ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(childNodeRef); + boolean parentExists = + parentAssocs.stream().anyMatch(entry -> entry.getParentRef().equals(hold) && entry.getQName().equals(primaryParentAssoc.getQName())); + if (parentAssocs.isEmpty() || !parentExists) { - ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(nodeRef); - nodeService.addChild(hold, nodeRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); + nodeService.addChild(hold, childNodeRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); } } } From 74deefe0c093dbdd682333aa42851c825da416e3 Mon Sep 17 00:00:00 2001 From: ehardon Date: Thu, 4 Mar 2021 15:27:35 +0200 Subject: [PATCH 08/10] APPS-852: Allow lowercase operation - modify operation field to op --- .../util/UpdateActionType.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/UpdateActionType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/UpdateActionType.java index 71c1382504..08637b970b 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/UpdateActionType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/UpdateActionType.java @@ -38,5 +38,20 @@ import org.alfresco.api.AlfrescoPublicApi; public enum UpdateActionType { ADD, - REMOVE + REMOVE; + + public static UpdateActionType valueOfIgnoreCase(String name) + { + UpdateActionType actionType; + try + { + actionType = UpdateActionType.valueOf(name.toUpperCase()); + } + catch (Exception e) + { + throw new IllegalArgumentException("Could not find enum with name '" + name + "'. Not one of the values accepted for Enum class: [ADD, REMOVE]"); + } + + return actionType; + } } From 2f0c70eed61193e3edf81ac9065a11af48a9074e Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 4 Mar 2021 16:47:31 +0000 Subject: [PATCH 09/10] APPS-659 Avoid relying on the primary parent being a CONTAINS relation. --- .../v35/RMv35HoldNewChildAssocPatch.java | 21 +++++++---- .../RMv35HoldNewChildAssocPatchUnitTest.java | 37 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java index 21504042e5..a90e7d03ab 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java @@ -27,6 +27,7 @@ package org.alfresco.module.org_alfresco_module_rm.patch.v35; import static org.alfresco.model.ContentModel.ASSOC_CONTAINS; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementCustomModel.RM_CUSTOM_URI; import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_CONTENT; import java.util.List; @@ -51,6 +52,9 @@ import org.alfresco.service.namespace.RegexQNamePattern; */ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch { + /** A name for the associations created by this patch. */ + protected static final QName PATCH_ASSOC_NAME = QName.createQName(RM_CUSTOM_URI,RMv35HoldNewChildAssocPatch .class.getSimpleName()); + /** * File plan service interface */ @@ -119,23 +123,24 @@ public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch { for (NodeRef hold : holdService.getHolds(filePlan)) { - List frozenAssoc = nodeService.getChildAssocs(hold, - ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL); + List frozenAssoc = nodeService.getChildAssocs(hold, ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL); for (ChildAssociationRef ref : frozenAssoc) { NodeRef childNodeRef = ref.getChildRef(); + // In testing we found that this was returning more than just "contains" associations. + // Possibly this is due to the code in Node2ServiceImpl.getParentAssocs not using the second parameter. List parentAssocs = nodeService.getParentAssocs(childNodeRef, ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL); - ChildAssociationRef primaryParentAssoc = nodeService.getPrimaryParent(childNodeRef); - boolean parentExists = - parentAssocs.stream().anyMatch(entry -> entry.getParentRef().equals(hold) && entry.getQName().equals(primaryParentAssoc.getQName())); - if (parentAssocs.isEmpty() || !parentExists) + boolean childContainedByHold = + parentAssocs.stream().anyMatch(entry -> entry.getParentRef().equals(hold) && entry.getTypeQName().equals(ASSOC_CONTAINS)); + if (!childContainedByHold) { - nodeService.addChild(hold, childNodeRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); + nodeService.addChild(hold, childNodeRef, ASSOC_CONTAINS, PATCH_ASSOC_NAME); } } } } - } finally + } + finally { behaviourFilter.enableBehaviour(ContentModel.ASPECT_AUDITABLE); behaviourFilter.enableBehaviour(ContentModel.ASPECT_VERSIONABLE); diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java index 5fd5abdcd5..351ca02bb0 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatchUnitTest.java @@ -27,11 +27,16 @@ package org.alfresco.module.org_alfresco_module_rm.patch.v35; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; + import static org.alfresco.model.ContentModel.ASSOC_CONTAINS; import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_CONTENT; +import static org.alfresco.module.org_alfresco_module_rm.patch.v35.RMv35HoldNewChildAssocPatch.PATCH_ASSOC_NAME; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyMap; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; @@ -86,8 +91,6 @@ public class RMv35HoldNewChildAssocPatchUnitTest @Mock private ChildAssociationRef childAssociationRef; - @Mock - private ChildAssociationRef primaryParentAssoc; private List childAssocs; @@ -107,7 +110,7 @@ public class RMv35HoldNewChildAssocPatchUnitTest } /** - * Test held items are removed from a hold and re-add to make sure the association is correct + * Test secondary associations are created for held items so that they are "contained" in the hold. */ @Test public void testAddChildDuringUpgrade() @@ -116,36 +119,35 @@ public class RMv35HoldNewChildAssocPatchUnitTest when(mockHoldService.getHolds(filePlanRef)).thenReturn(holds); when(mockNodeService.getChildAssocs(holdRef, ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL)).thenReturn(childAssocs); when(childAssociationRef.getChildRef()).thenReturn(heldItemRef); - when(mockNodeService.getPrimaryParent(heldItemRef)).thenReturn(primaryParentAssoc); + patch.applyInternal(); - verify(mockNodeService, times(1)).addChild(holdRef, heldItemRef, ASSOC_CONTAINS, primaryParentAssoc.getQName()); + + verify(mockNodeService, times(1)).addChild(holdRef, heldItemRef, ASSOC_CONTAINS, PATCH_ASSOC_NAME); } @Test - public void patchRunWithSuccessWhenNoHoldChilds() + public void patchRunWithSuccessWhenNoHeldChildren() { - List holdList = new ArrayList<>(); - holdList.add(holdRef); - when(childAssociationRef.getChildRef()).thenReturn(heldItemRef); - when(mockNodeService.getChildAssocs(holdRef)).thenReturn(new ArrayList<>()); + when(mockFilePlanService.getFilePlans()).thenReturn(fileplans); + when(mockHoldService.getHolds(filePlanRef)).thenReturn(holds); + when(mockNodeService.getChildAssocs(holdRef, ASSOC_FROZEN_CONTENT, RegexQNamePattern.MATCH_ALL)).thenReturn(emptyList()); + patch.applyInternal(); - verify(mockHoldService, times(0)).removeFromHold(holdRef, heldItemRef); - verify(mockHoldService, times(0)).addToHold(holdRef, heldItemRef); - + verify(mockNodeService, never()).addChild(any(NodeRef.class), any(NodeRef.class), any(QName.class), any(QName.class)); } @Test public void patchRunWithSuccessWhenNoHolds() { //no holds - List holdList = new ArrayList<>(); + List holdList = emptyList(); when(mockFilePlanService.getFilePlans()).thenReturn(fileplans); when(mockHoldService.getHolds(filePlanRef)).thenReturn(holdList); + patch.applyInternal(); - verify(mockHoldService, times(0)).removeFromHold(holdRef, heldItemRef); - verify(mockHoldService, times(0)).addToHold(holdRef, heldItemRef); + verify(mockNodeService, never()).addChild(any(NodeRef.class), any(NodeRef.class), any(QName.class), any(QName.class)); } @Test @@ -158,7 +160,6 @@ public class RMv35HoldNewChildAssocPatchUnitTest patch.applyInternal(); // then - verifyZeroInteractions(mockHoldService); - verify(mockNodeService, times(0)).addAspect(any(NodeRef.class), any(QName.class), anyMap()); + verify(mockNodeService, never()).addChild(any(NodeRef.class), any(NodeRef.class), any(QName.class), any(QName.class)); } } From 162247df6860a39a7936386e4ec47901a1f16562 Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 4 Mar 2021 16:54:41 +0000 Subject: [PATCH 10/10] APPS-659 Whitespace fix. --- .../patch/v35/RMv35HoldNewChildAssocPatch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java index a90e7d03ab..c0bd756b56 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v35/RMv35HoldNewChildAssocPatch.java @@ -53,7 +53,7 @@ import org.alfresco.service.namespace.RegexQNamePattern; public class RMv35HoldNewChildAssocPatch extends AbstractModulePatch { /** A name for the associations created by this patch. */ - protected static final QName PATCH_ASSOC_NAME = QName.createQName(RM_CUSTOM_URI,RMv35HoldNewChildAssocPatch .class.getSimpleName()); + protected static final QName PATCH_ASSOC_NAME = QName.createQName(RM_CUSTOM_URI, RMv35HoldNewChildAssocPatch.class.getSimpleName()); /** * File plan service interface