diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml new file mode 100644 index 0000000000..bd0e710238 --- /dev/null +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v32-context.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties index cf2c7c2600..67bd9c2e9c 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/version.properties @@ -1,3 +1,3 @@ # RM Schema number -version.rm.schema=2501 +version.rm.schema=3200 diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldChildAssocPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldChildAssocPatch.java new file mode 100644 index 0000000000..482dc127f3 --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldChildAssocPatch.java @@ -0,0 +1,126 @@ +/* + * #%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 . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.patch.v32; + +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_CONTENT; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_RECORDS; + +import java.util.List; +import java.util.Set; + +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.patch.AbstractModulePatch; +import org.alfresco.repo.domain.qname.QNameDAO; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; + +/** + * Patch to replace any use of the hold child association rma:frozenRecords with rma:frozenContent + * + * See: https://issues.alfresco.com/jira/browse/RM-6992 + * + * + * @author Ross Gale + * @since 3.2 + */ +public class RMv32HoldChildAssocPatch extends AbstractModulePatch +{ + /** + * Data abstraction layer for QName and Namespace entities. + */ + private QNameDAO qnameDAO; + + /** + * File plan service interface + */ + private FilePlanService filePlanService; + + /** + * Hold service interface. + */ + private HoldService holdService; + + /** + * Interface for public and internal node and store operations. + */ + private NodeService nodeService; + + /** + * Setter for qnamedao + * @param qnameDAO Data abstraction layer for QName and Namespace entities. + */ + public void setQnameDAO(QNameDAO qnameDAO) + { + this.qnameDAO = qnameDAO; + } + + /** + * Setter for fileplanservice + * @param filePlanService File plan service interface + */ + public void setFilePlanService(FilePlanService filePlanService) + { + this.filePlanService = filePlanService; + } + + /** + * Setter for hold service + * @param holdService Hold service interface. + */ + public void setHoldService(HoldService holdService) + { + this.holdService = holdService; + } + + /** + * Setter for node service + * @param nodeService Interface for public and internal node and store operations. + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + @Override + public void applyInternal() + { + qnameDAO.updateQName(ASSOC_FROZEN_RECORDS, ASSOC_FROZEN_CONTENT); + for (NodeRef filePlan : filePlanService.getFilePlans()) + { + for (NodeRef hold : holdService.getHolds(filePlan)) + { + for (ChildAssociationRef ref : nodeService.getChildAssocs(hold, ASSOC_FROZEN_CONTENT, ASSOC_FROZEN_RECORDS)) + { + holdService.removeFromHold(hold, ref.getChildRef()); + holdService.addToHold(hold, ref.getChildRef()); + } + } + } + } +} diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldChildAssocPatchUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldChildAssocPatchUnitTest.java new file mode 100644 index 0000000000..185eea7268 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v32/RMv32HoldChildAssocPatchUnitTest.java @@ -0,0 +1,123 @@ +/* + * #%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 . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.patch.v32; + +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_CONTENT; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASSOC_FROZEN_RECORDS; +import static org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock.generateNodeRef; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +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.model.RecordsManagementModel; +import org.alfresco.module.org_alfresco_module_rm.patch.v24.RMv24FilePlanContainerRuleInheritancePatch; +import org.alfresco.repo.domain.qname.QNameDAO; +import org.alfresco.repo.rule.RuleModel; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +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; + +/** + * RM V3.2 Hold child assoc patch unit test + * + * @author Ross Gale + * @since 3.2 + */ +public class RMv32HoldChildAssocPatchUnitTest +{ + @Mock + private QNameDAO qNameDAO; + + @Mock + private NodeService nodeService; + + @Mock + private FilePlanService filePlanService; + + @Mock + private HoldService holdService; + + @InjectMocks + private RMv32HoldChildAssocPatch patch; + + private NodeRef filePlanRef, holdRef, heldItemRef; + + private Set fileplans; + + private List holds; + + @Mock + private ChildAssociationRef childAssociationRef; + + private List childAssocs; + + @Before + public void setUp() + { + MockitoAnnotations.initMocks(this); + filePlanRef = new NodeRef("workspace://SpacesStore/filePlan"); + holdRef = new NodeRef("workspace://SpacesStore/hold"); + heldItemRef = new NodeRef("workspace://SpacesStore/heldItem"); + fileplans = new HashSet<>(); + fileplans.add(filePlanRef); + holds = new ArrayList<>(); + holds.add(holdRef); + childAssocs = new ArrayList<>(); + childAssocs.add(childAssociationRef); + } + + /** + * Test held items are removed from a hold and re-add to make sure the association is correct + */ + @Test + public void testAHoldIsRemovedAndReplacedDuringUpgrade() + { + when(filePlanService.getFilePlans()).thenReturn(fileplans); + when(holdService.getHolds(filePlanRef)).thenReturn(holds); + when(nodeService.getChildAssocs(holdRef, ASSOC_FROZEN_CONTENT, ASSOC_FROZEN_RECORDS)).thenReturn(childAssocs); + when(childAssociationRef.getChildRef()).thenReturn(heldItemRef); + patch.applyInternal(); + verify(holdService, times(1)).removeFromHold(holdRef, heldItemRef); + verify(holdService, times(1)).addToHold(holdRef, heldItemRef); + } +}