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 3ecc585a83..b49c740fb9 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
@@ -708,6 +708,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..85a13564fc 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,14 @@
+
+
+
+
+
+
+
+
\ 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 6916b0bd36..01ac11f766 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
@@ -341,6 +341,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 93d28f621c..df48940fbc 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
@@ -280,4 +280,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..83fdab1d53
--- /dev/null
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23SavedSearchesPatch.java
@@ -0,0 +1,88 @@
+/*
+ * #%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))
+ {
+ if(nodeService.hasAspect(savedSearchDetails.getNodeRef(),ASPECT_SAVED_SEARCH))
+ {
+ break;
+ }
+ 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);
+ }
+
+}