From c8932192f944ea914c5b303a3c228bb46e429ece Mon Sep 17 00:00:00 2001 From: Ross Gale Date: Tue, 5 Dec 2017 16:21:07 +0000 Subject: [PATCH] RM-5878 mnt changes added to a 2.4 branch --- .../model/recordsModel.xml | 4 + .../patch/rm-patch-v23-context.xml | 11 +++ .../rm-service-context.xml | 1 + .../model/RecordsManagementModel.java | 2 + .../patch/v20/RMv2SavedSearchPatch.java | 9 +- .../patch/v23/RMv23SavedSearchesPatch.java | 84 +++++++++++++++++ .../RecordsManagementSearchServiceImpl.java | 22 ++++- .../v23/RMv23SavedSearchesPatchUnitTest.java | 91 +++++++++++++++++++ 8 files changed, 216 insertions(+), 8 deletions(-) create mode 100644 rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatch.java create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatchUnitTest.java diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml index 1afe8754bc..8b03748dc2 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/model/recordsModel.xml @@ -696,6 +696,10 @@ + + Saved search + + Vital Record Definition diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml index 1600a1b836..868f8c8644 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml @@ -34,4 +34,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index b724fdb5b1..06af025456 100644 --- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -337,6 +337,7 @@ ]]> + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java index 3aa95d9fc6..02494e5c4a 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/RecordsManagementModel.java @@ -277,4 +277,6 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel // Countable aspect QName ASPECT_COUNTABLE = QName.createQName(RM_URI, "countable"); QName PROP_COUNT = QName.createQName(RM_URI, "count"); + + QName ASPECT_SAVED_SEARCH = QName.createQName(RM_URI, "savedSearch"); } diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2SavedSearchPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2SavedSearchPatch.java index f6eaec547b..4aa0090055 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2SavedSearchPatch.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v20/RMv2SavedSearchPatch.java @@ -27,6 +27,8 @@ package org.alfresco.module.org_alfresco_module_rm.patch.v20; +import static org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType.DEFAULT_SITE_NAME; + import java.util.List; import org.alfresco.model.ContentModel; @@ -51,9 +53,6 @@ import org.springframework.beans.factory.BeanNameAware; public class RMv2SavedSearchPatch extends ModulePatchComponent implements BeanNameAware, RecordsManagementModel, DOD5015Model { - /** RM site id */ - private static final String RM_SITE_ID = "rm"; - /** Records management search service */ private RecordsManagementSearchService recordsManagementSearchService; @@ -93,10 +92,10 @@ public class RMv2SavedSearchPatch extends ModulePatchComponent @Override protected void executePatch() { - if (siteService.getSite(RM_SITE_ID) != null) + if (siteService.getSite(DEFAULT_SITE_NAME) != null) { // get the saved searches - List savedSearches = recordsManagementSearchService.getSavedSearches(RM_SITE_ID); + List savedSearches = recordsManagementSearchService.getSavedSearches(DEFAULT_SITE_NAME); if (LOGGER.isDebugEnabled()) { diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatch.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatch.java new file mode 100644 index 0000000000..d337cb6d1d --- /dev/null +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatch.java @@ -0,0 +1,84 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 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.v23; + +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_SAVED_SEARCH; +import static org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType.DEFAULT_SITE_NAME; + +import org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch; +import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService; +import org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails; +import org.alfresco.service.cmr.repository.NodeService; + +/** + * RM v2.3 patch that adds the saved search aspect. + * + * @author Ross Gale + * @since 2.3 + */ +public class RMv23SavedSearchesPatch extends AbstractModulePatch +{ + /** + * records management search service + */ + private RecordsManagementSearchService recordsManagementSearchService; + + /** + * node service + */ + private NodeService nodeService; + + /** + * @param recordsManagementSearchService records management search service + */ + public void setRecordsManagementSearchService(RecordsManagementSearchService recordsManagementSearchService) + { + this.recordsManagementSearchService = recordsManagementSearchService; + } + + /** + * @param nodeService node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** + * Retrieves all saved searches for the records management site and adds ASPECT_SAVED_SEARCH + */ + @Override + public void applyInternal() + { + for (SavedSearchDetails savedSearchDetails : recordsManagementSearchService.getSavedSearches(DEFAULT_SITE_NAME)) + { + nodeService.addAspect(savedSearchDetails.getNodeRef(), ASPECT_SAVED_SEARCH, null); + } + } +} + diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/search/RecordsManagementSearchServiceImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/search/RecordsManagementSearchServiceImpl.java index 5a836ee770..f817e4cc5b 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/search/RecordsManagementSearchServiceImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/search/RecordsManagementSearchServiceImpl.java @@ -43,6 +43,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentWriter; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.SearchParameters; @@ -58,6 +59,8 @@ import org.json.JSONException; import org.json.JSONObject; import org.springframework.extensions.surf.util.I18NUtil; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_SAVED_SEARCH; + /** * Records management search service implementation * @@ -82,7 +85,12 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear /** Namespace service */ private NamespaceService namespaceService; - /** List of report details */ + /** + * Node service + */ + private NodeService nodeService; + + /** List of report details */ private List reports = new ArrayList(13); /** @@ -117,7 +125,15 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear this.namespaceService = namespaceService; } - /** + /** + * @param nodeService Node service + */ + public void setNodeService(NodeService nodeService) + { + this.nodeService = nodeService; + } + + /** * @param reportsJSON */ public void setReportsJSON(String reportsJSON) @@ -526,7 +542,7 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear } }, AuthenticationUtil.getSystemUserName()); } - + nodeService.addAspect(searchNode, ASPECT_SAVED_SEARCH, null); // Write the JSON content to search node final NodeRef writableSearchNode = searchNode; AuthenticationUtil.runAs(new RunAsWork() diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatchUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatchUnitTest.java new file mode 100644 index 0000000000..60e6a5e3b9 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatchUnitTest.java @@ -0,0 +1,91 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 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.v23; + +import static java.util.Arrays.asList; +import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.ASPECT_SAVED_SEARCH; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; + +import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchServiceImpl; +import org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * patch.v23 unit test + * + * @author Ross Gale + * @since 2.3 + */ +public class RMv23SavedSearchesPatchUnitTest +{ + + @Mock + private NodeService nodeService; + + @Mock + private RecordsManagementSearchServiceImpl recordsManagementSearchService; + + @Mock + private SavedSearchDetails mockSavedSearchDetails1, mockSavedSearchDetails2; + + @InjectMocks + private RMv23SavedSearchesPatch patch; + + /** + * Given that I am upgrading an existing repository to v2.3 + * When I execute the patch + * Then any existing rm saved searches will have the saved search aspect applied + */ + @Test + public void executePatch() + { + MockitoAnnotations.initMocks(this); + NodeRef noderef1 = new NodeRef("foo://123/456"); + NodeRef noderef2 = new NodeRef("bar://123/456"); + List searches = asList(mockSavedSearchDetails1, mockSavedSearchDetails2); + when(mockSavedSearchDetails1.getNodeRef()).thenReturn(noderef1); + when(mockSavedSearchDetails2.getNodeRef()).thenReturn(noderef2); + when(recordsManagementSearchService.getSavedSearches("rm")).thenReturn(searches); + + // execute patch + patch.applyInternal(); + + verify(nodeService, times(1)).addAspect(noderef1, ASPECT_SAVED_SEARCH, null); + verify(nodeService, times(1)).addAspect(noderef2, ASPECT_SAVED_SEARCH, null); + } + +}