RM-5878 add fix and patch for saved search mnt (MNT-15575)

This commit is contained in:
Ross Gale
2017-11-23 11:29:23 +00:00
parent d231772e75
commit 885ef4faaa
7 changed files with 207 additions and 8 deletions

View File

@@ -699,6 +699,10 @@
</mandatory-aspects>
</aspect>
<aspect name="rma:savedSearch">
<title>Saved search</title>
</aspect>
<aspect name="rma:vitalRecordDefinition">
<title>Vital Record Definition</title>
<properties>

View File

@@ -34,4 +34,14 @@
<property name="authorityService" ref="authorityService"/>
</bean>
<bean id="rm.savedSearchPatch"
parent="rm.parentModulePatch"
class="org.alfresco.module.org_alfresco_module_rm.patch.v23.RMv23SavedSearchesPatch">
<property name="description" value="Add aspect to saved searches."/>
<property name="fixesToSchema" value="1012"/>
<property name="targetSchema" value="1013"/>
<property name="recordsManagementSearchService" ref="RecordsManagementSearchService"/>
<property name="nodeService" ref="NodeService"/>
</bean>
</beans>

View File

@@ -327,6 +327,7 @@
]]>
</value>
</property>
<property name="nodeService" ref="NodeService"/>
</bean>
<bean id="RecordsManagementSearchService" class="org.springframework.aop.framework.ProxyFactoryBean">

View File

@@ -16,6 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.model;
import org.alfresco.service.namespace.QName;
@@ -149,7 +150,9 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
QName PROP_DISPOSITION_ACTION_ID = QName.createQName(RM_URI, "dispositionActionId");
QName PROP_DISPOSITION_ACTION = QName.createQName(RM_URI, "dispositionAction");
QName PROP_DISPOSITION_AS_OF = QName.createQName(RM_URI, "dispositionAsOf");
/** A flag indicating that the "disposition as of" date has been manually set and shouldn't be changed. */
/**
* A flag indicating that the "disposition as of" date has been manually set and shouldn't be changed.
*/
QName PROP_MANUALLY_SET_AS_OF = QName.createQName(RM_URI, "manuallySetAsOf");
QName PROP_DISPOSITION_EVENTS_ELIGIBLE = QName.createQName(RM_URI, "dispositionEventsEligible");
QName PROP_DISPOSITION_ACTION_STARTED_AT = QName.createQName(RM_URI, "dispositionActionStartedAt");
@@ -229,13 +232,16 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
QName PROP_RS_DISPOSITION_EVENTS_ELIGIBLE = QName.createQName(RM_URI, "recordSearchDispositionEventsEligible");
QName PROP_RS_DISPOSITION_EVENTS = QName.createQName(RM_URI, "recordSearchDispositionEvents");
QName PROP_RS_VITAL_RECORD_REVIEW_PERIOD = QName.createQName(RM_URI, "recordSearchVitalRecordReviewPeriod");
QName PROP_RS_VITAL_RECORD_REVIEW_PERIOD_EXPRESSION = QName.createQName(RM_URI, "recordSearchVitalRecordReviewPeriodExpression");
QName PROP_RS_VITAL_RECORD_REVIEW_PERIOD_EXPRESSION = QName.createQName(RM_URI,
"recordSearchVitalRecordReviewPeriodExpression");
QName PROP_RS_DISPOSITION_PERIOD = QName.createQName(RM_URI, "recordSearchDispositionPeriod");
QName PROP_RS_DISPOSITION_PERIOD_EXPRESSION = QName.createQName(RM_URI, "recordSearchDispositionPeriodExpression");
QName PROP_RS_HAS_DISPOITION_SCHEDULE = QName.createQName(RM_URI, "recordSearchHasDispositionSchedule");
QName PROP_RS_DISPOITION_INSTRUCTIONS = QName.createQName(RM_URI, "recordSearchDispositionInstructions");
QName PROP_RS_DISPOITION_AUTHORITY = QName.createQName(RM_URI, "recordSearchDispositionAuthority");
/** @depreacted as of 2.2, because disposable items can now be in multiple holds */
/**
* @depreacted as of 2.2, because disposable items can now be in multiple holds
*/
@Deprecated
QName PROP_RS_HOLD_REASON = QName.createQName(RM_URI, "recordSearchHoldReason");
@@ -245,9 +251,12 @@ public interface RecordsManagementModel extends RecordsManagementCustomModel
// Extended security aspect
// @deprecated as of 2.5, because of performance issues
@Deprecated QName ASPECT_EXTENDED_SECURITY = QName.createQName(RM_URI, "extendedSecurity");
@Deprecated QName PROP_READERS = QName.createQName(RM_URI, "readers");
@Deprecated QName PROP_WRITERS = QName.createQName(RM_URI, "writers");
@Deprecated
QName ASPECT_EXTENDED_SECURITY = QName.createQName(RM_URI, "extendedSecurity");
@Deprecated
QName PROP_READERS = QName.createQName(RM_URI, "readers");
@Deprecated
QName PROP_WRITERS = QName.createQName(RM_URI, "writers");
// Originating details of a record
QName ASPECT_RECORD_ORIGINATING_DETAILS = QName.createQName(RM_URI, "recordOriginatingDetails");
@@ -269,4 +278,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 SAVED_SEARCH_ASPECT = QName.createQName(RM_URI, "savedSearch");
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.patch.v23;
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;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.SAVED_SEARCH_ASPECT;
/**
* 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;
}
/**
* @see AbstractModulePatch#applyInternal()
*/
@Override
public void applyInternal()
{
for(SavedSearchDetails savedSearchDetails : recordsManagementSearchService.getSavedSearches("rm"))
{
nodeService.addAspect(savedSearchDetails.getNodeRef(),SAVED_SEARCH_ASPECT,null);
}
}
}

View File

@@ -34,6 +34,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;
@@ -49,6 +50,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.SAVED_SEARCH_ASPECT;
/**
* Records management search service implementation
*
@@ -73,6 +76,9 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear
/** Namespace service */
private NamespaceService namespaceService;
/** Node service */
private NodeService nodeService;
/** List of report details */
private List<ReportDetails> reports = new ArrayList<ReportDetails>(13);
@@ -108,6 +114,14 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear
this.namespaceService = namespaceService;
}
/**
* @param nodeService Node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param reportsJSON
*/
@@ -520,7 +534,7 @@ public class RecordsManagementSearchServiceImpl implements RecordsManagementSear
}
}, AuthenticationUtil.getSystemUserName());
}
nodeService.addAspect(searchNode, SAVED_SEARCH_ASPECT, null);
// Write the JSON content to search node
final NodeRef writableSearchNode = searchNode;
AuthenticationUtil.runAs(new RunAsWork<Void>()

View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2005-2014 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.patch.v23;
import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchServiceImpl;
import org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.version.NodeServiceImpl;
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;
import java.util.ArrayList;
import java.util.List;
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.SAVED_SEARCH_ASPECT;
import static org.mockito.Mockito.mockingDetails;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* patch.v23 unit test
*
* @author Ross Gale
* @since 2.3
*/
public class RMv23SavedSearchesPatchUnitTest// extends BaseUnitTest
{
@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.2
* When I execute the patch
* Then the capabilities are updated
*/
@Test
public void executePatch()
{
MockitoAnnotations.initMocks(this);
NodeRef noderef1 = new NodeRef("foo://123/456");
NodeRef noderef2 = new NodeRef("bar://123/456");
List<SavedSearchDetails> searches = new ArrayList<>();
searches.add(mockSavedSearchDetails1);
searches.add(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,SAVED_SEARCH_ASPECT,null);
verify(nodeService, times(1)).addAspect(noderef2, SAVED_SEARCH_ASPECT, null);
}
}