From 4c11e48ff343b05f0817fde52bab9d423d06b23c Mon Sep 17 00:00:00 2001 From: cagache Date: Fri, 18 May 2018 17:45:38 +0300 Subject: [PATCH] RM-6320 Automated tests for Declassification review for records and record folders --- .../org/alfresco/rest/core/v0/BaseAPI.java | 31 +++++ .../FilePlanComponentFields.java | 2 + .../rest/v0/RMRolesAndActionsAPI.java | 54 +++++++- .../java/org/alfresco/rest/v0/SearchAPI.java | 23 ++++ .../service/DispositionScheduleService.java | 124 ++++++++++++++++++ .../rm/community/base/BaseRMRestTest.java | 2 +- 6 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/DispositionScheduleService.java diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 66c1cdf37d..e87c7a21b2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -674,6 +674,8 @@ public abstract class BaseAPI CUT_OFF("cutoff"), UNDO_CUT_OFF("undoCutoff"), TRANSFER("transfer"), + COMPLETE_EVENT("completeEvent"), + UNDO_EVENT("undoEvent"), DESTROY("destroy"); String action; @@ -688,6 +690,35 @@ public abstract class BaseAPI } } + public enum RM_EVENTS + { + ABOLISHED("abolished", "Abolished"), + ALL_ALLOWANCES_GRANTED_ARE_TERMINATED("all_allowances_granted_are_terminated", "All Allowances Granted are Terminated"), + CASE_CLOSED("case_closed", "Case Closed"), + DECLASSIFICATION_REVIEW("declassification_review", "Declassification Review"), + OBSOLETE("obsolete", "Obsolete"), + NO_LONGER_NEEDED("no_longer_needed", "No Longer Needed"), + STUDY_COMPLETE("study_complete", "Study Complete"); + String eventName; + String eventDisplayLabel; + + RM_EVENTS(String eventName, String eventDisplayLabel) + { + this.eventName = eventName; + this.eventDisplayLabel = eventDisplayLabel; + } + + public String getEventName() + { + return eventName; + } + + public String getEventDisplayLabel() + { + return eventDisplayLabel; + } + } + public enum PermissionType { SET_READ, diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java index 2fbbf3cc15..4732c28a17 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/fileplancomponents/FilePlanComponentFields.java @@ -58,6 +58,8 @@ public class FilePlanComponentFields public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_ACTION_NAME = "rma:recordSearchDispositionActionName"; public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_EVENTS_ELIGIBLE = "rma:recordSearchDispositionEventsEligible"; public static final String PROPERTIES_RECORD_SEARCH_DISPOSITION_INSTRUCTIONS = "rma:recordSearchDispositionInstructions"; + public static final String PROPERTIES_DECLASSIFICATION_REVIEW_COMPLETED_BY = "rma:declassificationReviewCompletedBy"; + public static final String PROPERTIES_DECLASSIFICATION_REVIEW_COMPLETED_AT = "rma:declassificationReviewCompletedAt"; /** File plan properties */ diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java index 61de24b76c..c222dd1fb2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/RMRolesAndActionsAPI.java @@ -325,9 +325,9 @@ public class RMRolesAndActionsAPI extends BaseAPI /** * Perform an action on the record folder * - * @param user the user closing the folder + * @param user the user executing the action * @param password the user's password - * @param contentName the record folder name + * @param contentName the content name * @param date the date to be updated * @return The HTTP response. */ @@ -349,6 +349,56 @@ public class RMRolesAndActionsAPI extends BaseAPI return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); } + /** + * Complete an event on the record/record folder + * + * @param user the user executing the action + * @param password the user's password + * @param contentName the content name + * @param event the event to be completed + * @param date the date to be updated + * @return The HTTP response. + */ + public HttpResponse completeEvent(String user, String password, String contentName, RM_EVENTS event, ZonedDateTime date) + { + String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, contentName); + JSONObject requestParams = new JSONObject(); + requestParams.put("name", RM_ACTIONS.COMPLETE_EVENT.getAction()); + requestParams.put("nodeRef", recNodeRef); + date = (date != null) ? date : ZonedDateTime.now(); + String formattedDate = date.format(DateTimeFormatter.ISO_INSTANT); + requestParams.put("params", new JSONObject() + .put("eventName", event.getEventName()) + .put("eventCompletedBy", user) + .put("eventCompletedAt", new JSONObject() + .put("iso8601", formattedDate) + ) + ); + + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); + } + + /** + * Undo an event on the record/record folder + * + * @param user the user executing the action + * @param password the user's password + * @param contentName the content name + * @param event the event to be completed + * @return The HTTP response. + */ + public HttpResponse undoEvent(String user, String password, String contentName, RM_EVENTS event) + { + String recNodeRef = getNodeRefSpacesStore() + contentService.getNodeRef(user, password, RM_SITE_ID, contentName); + JSONObject requestParams = new JSONObject(); + requestParams.put("name", RM_ACTIONS.UNDO_EVENT.getAction()); + requestParams.put("nodeRef", recNodeRef); + requestParams.put("params", new JSONObject() + .put("eventName", event.getEventName())); + + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_ACTIONS_API); + } + /** * Deletes every item in the given container * diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index f462f06cdf..62c0ba697f 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -66,6 +66,9 @@ public class SearchAPI extends BaseAPI /** RM document search filters */ private static final String RM_DEFAULT_RECORD_FILTERS = "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; + /** RM all content search filters */ + private static final String RM_DEFAULT_CONTENT_FILTERS = + "records/true,undeclared/true,vital/false,folders/true,categories/true,frozen/false,cutoff/false"; /** * Perform search request on search endpoint as a user. @@ -139,6 +142,26 @@ public class SearchAPI extends BaseAPI return getItemNames(rmSearch(username, password, "rm", query, RM_DEFAULT_RECORD_FILTERS, sortby)); } + /** + * Search as a user for content on site "rm" matching query, using SearchAPI.RM_DEFAULT_CONTENT_FILTERS and sorted + * by sortby + *
+ * If more fine-grained control of search parameters is required, use rmSearch() directly. + * @param username + * @param password + * @param query + * @param sortby + * @return list of record names + */ + public List searchForRmContentAsUser( + String username, + String password, + String query, + String sortby) + { + return getItemNames(rmSearch(username, password, "rm", query, RM_DEFAULT_CONTENT_FILTERS, sortby)); + } + /** * Generic faceted search. * @param username diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/DispositionScheduleService.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/DispositionScheduleService.java new file mode 100644 index 0000000000..c414e16b2c --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/DispositionScheduleService.java @@ -0,0 +1,124 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2018 Alfresco Software Limited + * %% + * License rights for this program may be obtained from Alfresco Software, Ltd. + * pursuant to a written agreement and any use of this program without such an + * agreement is prohibited. + * #L% + */ +package org.alfresco.rest.v0.service; + + +import java.util.HashMap; + +import org.alfresco.rest.core.v0.BaseAPI; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +import org.alfresco.rest.v0.RecordCategoriesAPI; +import org.alfresco.utility.data.DataUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * Service for different disposition schedule actions + * + * @author jcule + * @since 2.7.0.1 + */ +@Service +public class DispositionScheduleService extends BaseAPI +{ + @Autowired + private RecordCategoriesAPI recordCategoriesAPI; + + @Autowired + private DataUser dataUser; + + /** + * Helper method for adding a cut off after period step + * + * @param categoryName the category in whose schedule the step will be added + * @param period + * @return + */ + public void addCutOffAfterPeriodStep(String categoryName, String period) + { + HashMap cutOffStep = new HashMap<>(); + cutOffStep.put(RETENTION_SCHEDULE.NAME, "cutoff"); + cutOffStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD, period); + cutOffStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Cut off after a period step"); + recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), categoryName, cutOffStep); + } + + /** + * Helper method for adding a cut off after an event occurs step + * + * @param categoryName the category in whose schedule the step will be added + * @param events + */ + public void addCutOffAfterEventStep(String categoryName, String events) + { + HashMap cutOffStep = new HashMap<>(); + cutOffStep.put(RETENTION_SCHEDULE.NAME, "cutoff"); + cutOffStep.put(RETENTION_SCHEDULE.RETENTION_EVENTS, events); + cutOffStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Cut off after event step"); + + recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), categoryName, cutOffStep); + } + + /** + * Helper method for accession step properties + * + * @param timeOrEvent + * @param events + * @param period + * @param periodProperty + * @param combineConditions + * @return + */ + public void addAccessionStep(String categoryName, Boolean timeOrEvent, String events, String period, String + periodProperty, Boolean combineConditions) + { + HashMap accessionStep = new HashMap<>(); + accessionStep.put(RETENTION_SCHEDULE.NAME, "accession"); + accessionStep.put(RETENTION_SCHEDULE.COMBINE_DISPOSITION_STEP_CONDITIONS, Boolean.toString(combineConditions)); + accessionStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD, period); + accessionStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY, periodProperty); + if (!timeOrEvent) + { + accessionStep.put(RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT, Boolean.toString(timeOrEvent)); + } + accessionStep.put(RETENTION_SCHEDULE.RETENTION_EVENTS, events); + accessionStep.put(RETENTION_SCHEDULE.DESCRIPTION, + "Accession step with time and event conditions."); + recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), categoryName, accessionStep); + } + + /** + * Helper method to create retention schedule with general fields for the given category as admin + * and apply it to the records + * + * @param categoryName + * @param appliedToRecords + */ + public void createCategoryRetentionSchedule(String categoryName, Boolean appliedToRecords) + { + recordCategoriesAPI.createRetentionSchedule(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), categoryName); + String retentionScheduleNodeRef = recordCategoriesAPI.getDispositionScheduleNodeRef( + dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), categoryName); + + HashMap retentionScheduleGeneralFields = new HashMap<>(); + retentionScheduleGeneralFields.put(RETENTION_SCHEDULE.RETENTION_AUTHORITY, "Authority"); + retentionScheduleGeneralFields.put(RETENTION_SCHEDULE.RETENTION_INSTRUCTIONS, "Instructions"); + recordCategoriesAPI.setRetentionScheduleGeneralFields(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), retentionScheduleNodeRef, retentionScheduleGeneralFields, + appliedToRecords); + + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java index 5de8128200..29b06b488f 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/BaseRMRestTest.java @@ -696,7 +696,7 @@ public class BaseRMRestTest extends RestTest } } - results = searchApi.searchForRecordsAsUser(user.getUsername(), user.getPassword(), term, sortby); + results = searchApi.searchForRmContentAsUser(user.getUsername(), user.getPassword(), term, sortby); if (!results.isEmpty() && results.containsAll(expectedResults)) { break;