Merge remote-tracking branch 'origin/feature/APPS-1722' into feature/APPS-1722

This commit is contained in:
sbisht
2022-11-09 10:33:47 +05:30

View File

@@ -1,7 +1,34 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2022 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.rules;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
import org.alfresco.rest.rm.community.model.fileplan.FilePlan;
import org.alfresco.rest.rm.community.model.record.Record;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
@@ -16,6 +43,7 @@ import org.alfresco.rest.v0.RulesAPI;
import org.alfresco.rest.v0.service.RoleService;
import org.alfresco.utility.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -23,7 +51,9 @@ import java.util.Collections;
import java.util.Random;
import static java.lang.Integer.MAX_VALUE;
import static java.util.Arrays.asList;
import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.FILE_PLAN_ALIAS;
import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS;
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy;
@@ -32,8 +62,7 @@ import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.*;
import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric;
import static org.alfresco.utility.data.RandomData.getRandomName;
import static org.alfresco.utility.report.log.Step.STEP;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.*;
import static org.testng.Assert.assertNotNull;
@@ -41,14 +70,15 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{
private String unfiledRecordsNodeRef;
private String recordFolder2;
private RecordCategoryChild recordFolder2;
private String nonElectronicId;
private Record electronicRecord;
private UnfiledContainer unfiledContainer;
private UserModel rmAdmin;
private RecordCategory RecordCategoryOne;
public RecordCategory RecordCategoryOne;
public RestNodeModel RecordCategoryCopy;
private RecordCategoryChild recordFolder;
public static final String RECORD_FOLDER_ONE = "record-folder-one";
private final String TEST_PREFIX = generateTestPrefix(MoveToRuleOnFoldersTest.class);
@@ -67,7 +97,7 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{
private RoleService roleService;
@Autowired
private RecordsAPI recordsAPI;
public RecordsAPI recordsAPI;
@BeforeClass(alwaysRun = true)
public void precondition()
@@ -95,21 +125,10 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{
STEP("Check the electronic record has been created");
assertStatusCode(CREATED);
// Generate update metadata
String newName = getModifiedPropertyValue(electronicRecord.getName());
String newTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle());
String newDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription());
// Update record:EDIT electronic and non electronic metadata [PENDING]
// recordsAPI.updateRecord(createRecordModel(newName, newDescription, newTitle), electronicRecord.getId());
// assertStatusCode(OK);
//create non electronic record
STEP("Create a non-electronic record by completing some of the fields");
// Use these properties for non-electronic record to be created
// Use these properties for non-electronic record to be created
String title = "Title " + getRandomAlphanumeric();
String description = "Description " + getRandomAlphanumeric();
String box = "Box "+ getRandomAlphanumeric();
@@ -125,36 +144,70 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{
Record nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize);
// Create non-electronic record
nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1).getId();
// STEP("Check the non-electronic record has been created");
STEP("Check the non-electronic record has been created");
assertStatusCode(CREATED);
// move the electronic and nonelectronic record from folder1 to folder2
STEP("Create the record folder2 inside the rootCategory");
recordFolder2 = createCategoryFolderInFilePlan().getId();
STEP("Update metadata for Non-Electronic Record");
org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
Record nonelecrecord = recordsAPI.getRecord(nonElectronicId);
String nonelecnewName = getModifiedPropertyValue(nonElectrinicRecordModel.getName());
String nonelecnewTitle = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getTitle());
String nonelecnewDescription = getModifiedPropertyValue(nonElectrinicRecordModel.getProperties().getDescription());
recordsAPI.updateRecord(createRecordModel(nonelecnewName, nonelecnewDescription, nonelecnewTitle),nonelecrecord.getId());
assertStatusCode(OK);
// //create a rule for completing record for folder 2
STEP("Update metadata for Electronic Record");
Record elecrecord = recordsAPI.getRecord(electronicRecord.getId());
String elecnewName = getModifiedPropertyValue(electronicRecord.getName());
String elecnewTitle = getModifiedPropertyValue(electronicRecord.getProperties().getTitle());
String elecnewDescription = getModifiedPropertyValue(electronicRecord.getProperties().getDescription());
recordsAPI.updateRecord(createRecordModel(elecnewName, elecnewDescription, elecnewTitle),elecrecord.getId());
assertStatusCode(OK);
STEP("Create the folder2 inside the rootCategory");
recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder"));
STEP("create a rule MOVE_TO for folder 2");
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1")
.applyToChildren(true).title(title)
.actions(Collections.singletonList(ActionsOnRule.COMPLETE_RECORD.getActionValue()));
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder2, ruleDefinition);
.runInBackground(true).title(title)
.actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue()));
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder2.getId() , ruleDefinition);
}
@Test
public void MoveToRuleFoldersTest()
{ STEP("Move electronic record from folder1 to folder2");
{
STEP("Move electronic record from folder1 to folder2");
RestNodeModel electronicDocRestNodeModel = getRestAPIFactory()
.getNodeAPI(toContentModel(electronicRecord.getId()))
.move(createBodyForMoveCopy(recordFolder2));
.move(createBodyForMoveCopy(recordFolder2.getId()));
assertStatusCode(OK);
STEP("Move non-electronic record from folder1 to folder2");
RestNodeModel nonelectronicDocRestNodeModel = getRestAPIFactory()
.getNodeAPI(toContentModel(nonElectronicId))
.move(createBodyForMoveCopy(recordFolder2));
.move(createBodyForMoveCopy(recordFolder2.getId()));
assertStatusCode(OK);
STEP("Create Copy of RootRecord");
FilePlan filePlan = getRestAPIFactory().getFilePlansAPI().getFilePlan(FILE_PLAN_ALIAS);
RecordCategoryCopy=getRestAPIFactory().getNodeAPI(toContentModel(RecordCategoryOne.getId())).copy(createBodyForMoveCopy(filePlan.getId()));
}
@AfterClass(alwaysRun = true)
public void cleanMoveToRuleOnFoldersTest()
{
deleteRecordCategory(RecordCategoryOne.getId());
// Delete record and verify status
// recordsAPI.deleteRecord(RecordCategoryCopy.getName(),RecordCategoryCopy.);
// assertStatusCode(NO_CONTENT);
getDataUser().deleteUser(rmAdmin);
}
private String getModifiedPropertyValue(String originalValue) {
@@ -162,6 +215,5 @@ public class MoveToRuleOnFoldersTest extends BaseRMRestTest{
String MODIFIED_PREFIX = "modified_";
return MODIFIED_PREFIX + originalValue;
}
}
}