APPS-995 Refactor DispositionScheduleLinkedRecordsTest in order to create prec… (#448)

* Refactor DispositionScheduleLinkedRecordsTest in order to create precondition through rest api [ags][skip repo][skip share][skip db][skip tas]

* code review comments [ags][skip repo][skip share][skip db][skip tas]

* code review comments [ags][skip repo][skip share][skip db][skip tas]
This commit is contained in:
Claudia Agache
2021-05-13 13:05:57 +00:00
committed by GitHub
parent bd14bd3743
commit 7492f9e3bb
8 changed files with 174 additions and 40 deletions

View File

@@ -0,0 +1,52 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2021 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 <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.model.recordcategory;
/**
* The property of the dispositioned item that is used to calculate the "as of" period.
*/
public enum RetentionPeriodProperty
{
/** Item created date. */
CREATED_DATE("cm:created"),
/** Record filed date. */
DATE_FILED("rma:dateFiled"),
/** Item cut off date. */
CUT_OFF_DATE("rma:cutOffDate");
String periodProperty;
RetentionPeriodProperty(String periodProperty)
{
this.periodProperty = periodProperty;
}
public String getPeriodProperty()
{
return periodProperty;
}
}

View File

@@ -125,6 +125,7 @@ public class RecordCategoriesAPI extends BaseAPI
addPropertyToRequest(requestParams, "period", properties, RETENTION_SCHEDULE.RETENTION_PERIOD);
addPropertyToRequest(requestParams, "ghostOnDestroy", properties, RETENTION_SCHEDULE.RETENTION_GHOST);
addPropertyToRequest(requestParams, "periodProperty", properties, RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY);
addPropertyToRequest(requestParams, "location", properties, RETENTION_SCHEDULE.RETENTION_LOCATION);
String events = getPropertyValue(properties, RETENTION_SCHEDULE.RETENTION_EVENTS);
if(!events.equals(""))
{

View File

@@ -27,11 +27,15 @@
package org.alfresco.rest.v0.service;
import static org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty.CUT_OFF_DATE;
import java.util.HashMap;
import org.alfresco.rest.core.v0.BaseAPI;
import org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty;
import org.alfresco.rest.v0.RecordCategoriesAPI;
import org.alfresco.utility.data.DataUserAIS;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -54,7 +58,7 @@ public class DispositionScheduleService extends BaseAPI
* Helper method for adding a retain after period step
*
* @param categoryName the category in whose schedule the step will be added
* @param period
* @param period for what period the item will be retained
*/
public void addRetainAfterPeriodStep(String categoryName, String period)
{
@@ -66,44 +70,92 @@ public class DispositionScheduleService extends BaseAPI
dataUser.getAdminUser().getPassword(), categoryName, retainStep);
}
/**
* Helper method for adding a cut off immediately after created date step
*
* @param categoryName the category in whose schedule the step will be added
*/
public void addCutOffImmediatelyStep(String categoryName)
{
HashMap<RETENTION_SCHEDULE, String> cutOffStep = new HashMap<>();
cutOffStep.put(RETENTION_SCHEDULE.NAME, "cutoff");
cutOffStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD, "immediately");
cutOffStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Cut off immediately step");
recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(), categoryName, cutOffStep);
}
/**
* Helper method for adding a cut off after period step
*
* @param categoryName the category in whose schedule the step will be added
* @param period
* @param categoryName the category in whose schedule the step will be added
* @param period the period that needs to pass from periodProperty for cut off to be available
* @param periodProperty the property of the dispositioned item that is used to calculate the "as of" period
*/
public void addCutOffAfterPeriodStep(String categoryName, String period)
public void addCutOffAfterPeriodStep(String categoryName, String period, RetentionPeriodProperty periodProperty)
{
HashMap<RETENTION_SCHEDULE, String> cutOffStep = new HashMap<>();
cutOffStep.put(RETENTION_SCHEDULE.NAME, "cutoff");
cutOffStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD, period);
cutOffStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY, periodProperty.getPeriodProperty());
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 destroy with ghosting after period
* Helper method for adding a destroy step with ghosting immediately after CUT OFF date
*
* @param categoryName the category in whose schedule the step will be added
* @param period
* @param categoryName the category in whose schedule the step will be added
*/
public void addDestroyWithGhostingAfterPeriodStep(String categoryName, String period)
public void addDestroyWithGhostingImmediatelyAfterCutOff(String categoryName)
{
addDestroyWithGhostingAfterPeriodStep(categoryName, "immediately", CUT_OFF_DATE);
}
/**
* Helper method for adding a destroy step with ghosting after period
*
* @param categoryName the category in whose schedule the step will be added
* @param period the period that needs to pass for destroy to be available
* @param periodProperty the property of the dispositioned item that is used to calculate the "as of" period
*/
public void addDestroyWithGhostingAfterPeriodStep(String categoryName, String period, RetentionPeriodProperty periodProperty)
{
HashMap<RETENTION_SCHEDULE, String> destroyStep = new HashMap<>();
destroyStep.put(RETENTION_SCHEDULE.NAME, "destroy");
destroyStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD, period);
destroyStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Destroy after a period step");
destroyStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY, periodProperty.getPeriodProperty());
destroyStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Destroy after a period step with keep metadata");
destroyStep.put(RETENTION_SCHEDULE.RETENTION_GHOST, "on");
recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(), categoryName, destroyStep);
}
/**
* Helper method for adding a destroy step without ghosting after period
*
* @param categoryName the category in whose schedule the step will be added
* @param period the period that needs to pass for destroy to be available
* @param periodProperty the property of the dispositioned item that is used to calculate the "as of" period
*/
public void addDestroyWithoutGhostingAfterPeriodStep(String categoryName, String period,
RetentionPeriodProperty periodProperty)
{
HashMap<RETENTION_SCHEDULE, String> destroyStep = new HashMap<>();
destroyStep.put(RETENTION_SCHEDULE.NAME, "destroy");
destroyStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD, period);
destroyStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY, periodProperty.getPeriodProperty());
destroyStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Destroy after a period step");
recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(), categoryName, destroyStep);
}
/**
* 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
* @param events the events that need to occur for cut off to be available
*/
public void addCutOffAfterEventStep(String categoryName, String events)
{
@@ -116,6 +168,27 @@ public class DispositionScheduleService extends BaseAPI
dataUser.getAdminUser().getPassword(), categoryName, cutOffStep);
}
/**
* Helper method for adding a transfer after an event occurs step
*
* @param categoryName the category in whose schedule the step will be added
* @param location the transfer location
* @param events the events that need to occur for transfer to be available
*/
public void addTransferAfterEventStep(String categoryName, String location, String events)
{
HashMap<RETENTION_SCHEDULE, String> transferStep = new HashMap<>();
transferStep.put(RETENTION_SCHEDULE.NAME, "transfer");
transferStep.put(RETENTION_SCHEDULE.RETENTION_LOCATION, location);
transferStep.put(RETENTION_SCHEDULE.RETENTION_EVENTS, events);
transferStep.put(RETENTION_SCHEDULE.DESCRIPTION, "Transfer after event step");
transferStep.put(RETENTION_SCHEDULE.COMBINE_DISPOSITION_STEP_CONDITIONS, "false");
transferStep.put(RETENTION_SCHEDULE.RETENTION_ELIGIBLE_FIRST_EVENT, "true");
recordCategoriesAPI.addDispositionScheduleSteps(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(), categoryName, transferStep);
}
/**
* Helper method for adding an accession step
*
@@ -124,47 +197,56 @@ public class DispositionScheduleService extends BaseAPI
* @param period
* @param periodProperty
* @param combineConditions
* @return
*/
public void addAccessionStep(String categoryName, Boolean timeOrEvent, String events, String period, String
periodProperty, Boolean combineConditions)
public void addAccessionStep(String categoryName, Boolean timeOrEvent, String events, String period,
RetentionPeriodProperty periodProperty, Boolean combineConditions)
{
HashMap<RETENTION_SCHEDULE, String> 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);
accessionStep.put(RETENTION_SCHEDULE.RETENTION_PERIOD_PROPERTY, periodProperty.getPeriodProperty());
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.");
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
* Helper method to create retention schedule with general fields for the given category as user
* and apply it to the records/ record folders
*
* @param categoryName
* @param appliedToRecords
* @param user the user who creates the retention schedule
* @param categoryName the category on which is created the retention schedule
* @param appliedToRecords true if is applied on records, false if is applied on folders
*/
public void createCategoryRetentionSchedule(String categoryName, Boolean appliedToRecords)
public void createCategoryRetentionSchedule(UserModel user, String categoryName, Boolean appliedToRecords)
{
recordCategoriesAPI.createRetentionSchedule(dataUser.getAdminUser().getUsername(),
dataUser.getAdminUser().getPassword(), categoryName);
recordCategoriesAPI.createRetentionSchedule(user.getUsername(), user.getPassword(), categoryName);
String retentionScheduleNodeRef = recordCategoriesAPI.getDispositionScheduleNodeRef(
dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), categoryName);
dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), categoryName);
HashMap<RETENTION_SCHEDULE, String> 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);
dataUser.getAdminUser().getPassword(), retentionScheduleNodeRef, retentionScheduleGeneralFields,
appliedToRecords);
}
/**
* Helper method to create retention schedule with general fields for the given category as admin
* and apply it to the records/record folders
*
* @param categoryName the category on which is created the retention schedule
* @param appliedToRecords true if is applied on records, false if is applied on folders
*/
public void createCategoryRetentionSchedule(String categoryName, Boolean appliedToRecords)
{
createCategoryRetentionSchedule(dataUser.getAdminUser(), categoryName, appliedToRecords);
}
}

View File

@@ -39,7 +39,6 @@ import org.alfresco.rest.rm.community.model.user.UserPermissions;
import org.alfresco.rest.rm.community.model.user.UserRoles;
import org.alfresco.rest.v0.RMRolesAndActionsAPI;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.data.DataUser;
import org.alfresco.utility.data.DataUserAIS;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;

View File

@@ -271,8 +271,8 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
RecordCategory categoryWithRS = getRestAPIFactory().getRecordCategoryAPI()
.getRecordCategory(recordFolder.getParentId());
dispositionScheduleService.createCategoryRetentionSchedule(categoryWithRS.getName(), false);
dispositionScheduleService.addCutOffAfterPeriodStep(categoryWithRS.getName(), "immediately");
dispositionScheduleService.addDestroyWithGhostingAfterPeriodStep(categoryWithRS.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(categoryWithRS.getName());
dispositionScheduleService.addDestroyWithGhostingImmediatelyAfterCutOff(categoryWithRS.getName());
STEP("Check the record folder has a disposition schedule");
RecordFolder folderWithRS = getRestAPIFactory().getRecordFolderAPI().getRecordFolder(recordFolder.getId());
@@ -297,7 +297,7 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
categoryWithRS = createRootCategory(getRandomName("CategoryWithRS"));
dispositionScheduleService.createCategoryRetentionSchedule(categoryWithRS.getName(), true);
dispositionScheduleService.addRetainAfterPeriodStep(categoryWithRS.getName(), "immediately");
dispositionScheduleService.addDestroyWithGhostingAfterPeriodStep(categoryWithRS.getName(), "immediately");
dispositionScheduleService.addDestroyWithGhostingImmediatelyAfterCutOff(categoryWithRS.getName());
STEP("Create record folder with a record.");
RecordCategoryChild folder = createFolder(categoryWithRS.getId(), getRandomName("RecFolder"));
@@ -325,5 +325,4 @@ public class PreventActionsOnFrozenContentTests extends BaseRMRestTest
deleteRecordCategory(recordFolder.getParentId());
deleteRecordCategory(categoryWithRS.getId());
}
}

View File

@@ -64,7 +64,7 @@ public class AutomaticDispositionTest extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(categoryWithRSOnRecords.getName(), true);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(categoryWithRSOnRecords.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(categoryWithRSOnRecords.getName());
STEP("Create a record folder with a record");
RecordCategoryChild recordFolder = createRecordFolder(categoryWithRSOnRecords.getId(), getRandomName

View File

@@ -65,7 +65,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(rootCategory.getName(), true);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(rootCategory.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(rootCategory.getName());
STEP("Add retention schedule retain step with immediate period.");
dispositionScheduleService.addRetainAfterPeriodStep(rootCategory.getName(), "immediately");
@@ -101,7 +101,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(rootCategory.getName(), false);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(rootCategory.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(rootCategory.getName());
STEP("Add retention schedule retain step with immediate period.");
dispositionScheduleService.addRetainAfterPeriodStep(rootCategory.getName(), "immediately");
@@ -133,7 +133,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(rootCategory.getName(), true);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(rootCategory.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(rootCategory.getName());
STEP("Create a subcategory with retention schedule and apply it to records.");
RecordCategoryChild subCategory1 = createRecordCategory(rootCategory.getId(), getRandomName("subCategory"));
@@ -189,7 +189,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(subcategory1Path, false);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(subcategory1Path, "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(subcategory1Path);
STEP("Create a subcategory2 with a record folder in subcategory1");
RecordCategoryChild subCategory2 = createRecordCategory(subCategory1.getId(), getRandomName("subCategory"));
@@ -220,7 +220,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(rootCategory.getName(), false);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(rootCategory.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(rootCategory.getName());
STEP("Create a subcategory with retention schedule and apply it to records.");
RecordCategoryChild subCategory = createRecordCategory(rootCategory.getId(), getRandomName("subCategory"));
@@ -267,7 +267,7 @@ public class DispositionScheduleInheritanceTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(rootCategory.getName(), true);
STEP("Add retention schedule cut off step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(rootCategory.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(rootCategory.getName());
STEP("Create a subcategory with retention schedule and apply it to record folders.");
RecordCategoryChild subCategory = createRecordCategory(rootCategory.getId(), getRandomName("subCategory"));

View File

@@ -29,6 +29,7 @@ package org.alfresco.rest.rm.community.records;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE;
import static org.alfresco.rest.rm.community.model.recordcategory.RetentionPeriodProperty.CUT_OFF_DATE;
import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_POWER_USER;
@@ -310,8 +311,8 @@ public class DeleteRecordTests extends BaseRMRestTest
dispositionScheduleService.createCategoryRetentionSchedule(recordCategory.getName(), true);
STEP("Add retention schedule cut off and destroy step with immediate period.");
dispositionScheduleService.addCutOffAfterPeriodStep(recordCategory.getName(), "immediately");
dispositionScheduleService.addDestroyWithGhostingAfterPeriodStep(recordCategory.getName(), "immediately");
dispositionScheduleService.addCutOffImmediatelyStep(recordCategory.getName());
dispositionScheduleService.addDestroyWithGhostingImmediatelyAfterCutOff(recordCategory.getName());
STEP("Create a record folder and file the record");
RecordCategoryChild recFolder = createFolder(recordCategory.getId(), getRandomName("recFolder"));