mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merge pull request #1531 from Alfresco/feature/APPS-1722
Feature/apps 1722
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* #%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.rm.community.base.BaseRMRestTest;
|
||||
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;
|
||||
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
||||
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI;
|
||||
import org.alfresco.rest.rm.community.smoke.CreateCategoriesTests;
|
||||
import org.alfresco.rest.v0.RulesAPI;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.alfresco.rest.core.v0.BaseAPI.NODE_PREFIX;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.ELECTRONIC_RECORD_NAME;
|
||||
import static org.alfresco.rest.rm.community.base.TestData.NONELECTRONIC_RECORD_NAME;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.rest.rm.community.utils.CoreUtil.createBodyForMoveCopy;
|
||||
import static org.alfresco.rest.rm.community.utils.CoreUtil.toContentModel;
|
||||
import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.*;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomName;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.*;
|
||||
|
||||
public class CopyToRuleOnFoldersTest extends BaseRMRestTest {
|
||||
|
||||
private RecordCategory category;
|
||||
private RecordCategoryChild folder1,folder2;
|
||||
private final static String title = "Run in background";
|
||||
private final String TEST_PREFIX = generateTestPrefix(CopyToRuleOnFoldersTest.class);
|
||||
private final String RM_ADMIN = TEST_PREFIX + "rm_admin";
|
||||
private final String electronicRecord = TEST_PREFIX + "record_electronic_for_copyTo";
|
||||
private final String nonElectronicRecord = TEST_PREFIX + "record_non_electronic_for_copyTo";
|
||||
|
||||
@Autowired
|
||||
private RulesAPI rulesAPI;
|
||||
|
||||
@Test
|
||||
@AlfrescoTest(jira = "RM-2994")
|
||||
public void copyToRuleOnFoldersTest()
|
||||
{
|
||||
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1")
|
||||
.runInBackground(true).title(title)
|
||||
.actions(Collections.singletonList(ActionsOnRule.COPY_TO.getActionValue()));
|
||||
|
||||
|
||||
STEP("Create the RM site if doesn't exist");
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
STEP("Create record categories and record folders");
|
||||
category= createRootCategory(getRandomName("recordCategory"));
|
||||
String folder1 = createCategoryFolderInFilePlan().getId();
|
||||
String folder2 = createCategoryFolderInFilePlan().getId();
|
||||
|
||||
// create a rule on folder
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folder1, ruleDefinition);
|
||||
|
||||
// create electronic record in record folder
|
||||
String electronicRecordId = createElectronicRecord(folder1, ELECTRONIC_RECORD_NAME).getId();
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// create non-electronic record in record folder
|
||||
String nonElectronicRecord = createElectronicRecord(folder1, NONELECTRONIC_RECORD_NAME).getId();
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
// Move the electronic and non-electronic records from "Category with records"> "Folder with rule"
|
||||
// to "Copy Category with records" > "Folder with rule"
|
||||
getRestAPIFactory().getNodeAPI(toContentModel(folder1)).copy(createBodyForMoveCopy(category.getId()));
|
||||
getRestAPIFactory().getNodeAPI(toContentModel( electronicRecord)).move(createBodyForMoveCopy(folder2));
|
||||
getRestAPIFactory().getNodeAPI(toContentModel( nonElectronicRecord)).move(createBodyForMoveCopy(folder2));
|
||||
|
||||
RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
// Delete the record category
|
||||
RecordCategoryAPI recordCategoryAPI = getRestAPIFactory().getRecordCategoryAPI();
|
||||
String recordCategoryId = category.getId();
|
||||
recordCategoryAPI.deleteRecordCategory(recordCategoryId);
|
||||
recordsAPI.deleteRecord(electronicRecord);
|
||||
recordsAPI.deleteRecord(nonElectronicRecord);
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* #%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.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
||||
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry;
|
||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.rm.community.smoke.FileAsRecordTests;
|
||||
import org.alfresco.rest.v0.RulesAPI;
|
||||
import org.alfresco.rest.v0.service.RoleService;
|
||||
import org.alfresco.test.AlfrescoTest;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
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;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
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.model.user.UserPermissions.PERMISSION_FILING;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomName;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
|
||||
@AlfrescoTest (jira = "APPS-36")
|
||||
public class FileAsRecordRuleTests extends BaseRMRestTest
|
||||
{
|
||||
private UserModel nonRMUser, rmManager;
|
||||
private RecordCategory category_manager, category_admin;
|
||||
private RecordCategoryChild folder_admin, folder_manager ;
|
||||
private static final String CATEGORY_MANAGER = "catManager" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private static final String CATEGORY_ADMIN = "catAdmin" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private FolderModel testFolder;
|
||||
private FileModel document,inPlaceRecord;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private RulesAPI rulesAPI;
|
||||
|
||||
/**
|
||||
* Create preconditions:
|
||||
* 1. RM site is created
|
||||
* 2. Two users: user without RM role and a user with RM manager role
|
||||
* 3. Two Record categories with one folder each
|
||||
* 4. User with RM MANAGER role has Filling permission over one category
|
||||
* 5. A collaboration folder with rule set to declare and file as record to a record folder
|
||||
**/
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void preconditionForDeclareFileAsRecordRuleTests()
|
||||
{
|
||||
STEP("Create the RM site if doesn't exist");
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
STEP("Create a user");
|
||||
nonRMUser = dataUser.createRandomTestUser("testUser");
|
||||
|
||||
STEP("Create a collaboration site");
|
||||
testSite = dataSite.usingUser(nonRMUser).createPublicRandomSite();
|
||||
|
||||
STEP("Create two categories with two folders");
|
||||
category_manager = createRootCategory(CATEGORY_MANAGER);
|
||||
category_admin = createRootCategory(CATEGORY_ADMIN);
|
||||
folder_admin = createFolder(category_admin.getId(),FOLDER_ADMIN);
|
||||
folder_manager = createFolder(category_manager.getId(),FOLDER_MANAGER);
|
||||
|
||||
STEP("Create an rm user and give filling permission over CATEGORY_MANAGER record category");
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
|
||||
rmManager = roleService.createCollaboratorWithRMRoleAndPermission(testSite, recordCategory,
|
||||
UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
|
||||
|
||||
STEP("Create a collaboration folder with a rule set to declare and file as record to a record folder");
|
||||
RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
}
|
||||
/**
|
||||
* Given I am a user that can create a rule on a folder in a collaboration site
|
||||
* When I am creating the rule
|
||||
* Then I have the option of adding a "Declare and File as Record" action to the rule
|
||||
* <p>
|
||||
* Given I am creating a rule
|
||||
* When I add the "Declare and File as Record" action to the rule
|
||||
* Then I am able to select the record folder I want the declared record to be filed to
|
||||
* <p>
|
||||
* Given I am configuring a "Declare and File as Record" action within a rule
|
||||
* And I have at least one records management role (eg RM User)
|
||||
* When I am selecting the record folder location to file the declared record to
|
||||
* Then I see the record folders in the file plan that I have file access to as the creator of the record
|
||||
**/
|
||||
@Test
|
||||
public void declareAsRecordRuleAsRMUserWithFilingPermissions() {
|
||||
STEP("Create a collaboration folder");
|
||||
testFolder = dataContent.usingSite(testSite)
|
||||
.usingUser(rmManager)
|
||||
.createFolder();
|
||||
|
||||
STEP("Create a rule with Declare as Record action and check that user can select a record folder.");
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
}
|
||||
/**
|
||||
* Given I am configuring a "Declare and File as Record" action within a rule
|
||||
* And I don't have a records management role
|
||||
* When I am selecting the record folder location to file the declared record to
|
||||
* Then I can see only the file plan
|
||||
*/
|
||||
@Test
|
||||
public void declareAsRecordRuleAsNonRMUser()
|
||||
{
|
||||
STEP("Create a collaboration folder");
|
||||
testFolder = dataContent.usingSite(testSite)
|
||||
.usingUser(nonRMUser)
|
||||
.createFolder();
|
||||
|
||||
STEP("Create a rule with Declare as Record action and check that user can select a record folder.");
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(nonRMUser.getUsername(), nonRMUser.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given I have not selected a record folder location
|
||||
* When the rule is triggered
|
||||
* Then the file is declared as record to the UnFiled Records folder
|
||||
*/
|
||||
@Test
|
||||
public void triggerDeclareToUnfiledRuleAsNonRMUser()
|
||||
{
|
||||
STEP("Create a collaboration folder with a rule set to declare and file as record without a record folder location");
|
||||
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
|
||||
RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
STEP("Create as nonRMUser a new file into the previous folder in order to trigger the rule");
|
||||
inPlaceRecord = dataContent.usingUser(nonRMUser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
||||
// Verify that declared record is in Unfilled Records Folder
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
List<UnfiledContainerChildEntry> matchingRecords = unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.filter(e -> e.getEntry().getId().equals(inPlaceRecord.getNodeRefWithoutVersion()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void cleanupDeclareAsRecordRuleTests()
|
||||
{
|
||||
STEP("Delete the collaboration site");
|
||||
dataSite.usingUser(nonRMUser).deleteSite(testSite);
|
||||
|
||||
STEP("Delete Users");
|
||||
dataUser.deleteUser(nonRMUser);
|
||||
dataUser.deleteUser(rmManager);
|
||||
|
||||
STEP("Delete categories");
|
||||
getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry ->
|
||||
deleteRecordCategory(recordCategoryEntry.getEntry().getId()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* #%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.dataprep.CMISUtil;
|
||||
import org.alfresco.rest.rm.community.base.BaseRMRestTest;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory;
|
||||
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
|
||||
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
||||
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry;
|
||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.rm.community.smoke.FileAsRecordTests;
|
||||
import org.alfresco.rest.v0.RulesAPI;
|
||||
import org.alfresco.rest.v0.service.RoleService;
|
||||
import org.alfresco.utility.model.FileModel;
|
||||
import org.alfresco.utility.model.FileType;
|
||||
import org.alfresco.utility.model.FolderModel;
|
||||
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;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.model.user.UserPermissions.PERMISSION_FILING;
|
||||
import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
|
||||
import static org.alfresco.utility.data.RandomData.getRandomName;
|
||||
import static org.alfresco.utility.report.log.Step.STEP;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
|
||||
public class FileVersionAsRecordRuleTest extends BaseRMRestTest {
|
||||
|
||||
private UserModel nonRMuser, rmManager;
|
||||
private RecordCategory category_manager, category_admin;
|
||||
private RecordCategoryChild folder_admin, folder_manager ;
|
||||
private static final String CATEGORY_MANAGER = "catManager" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private static final String CATEGORY_ADMIN = "catAdmin" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private static final String FOLDER_MANAGER = "recordFolder" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private static final String FOLDER_ADMIN = "recordFolder" + generateTestPrefix(FileAsRecordTests.class);
|
||||
private FolderModel testFolder;
|
||||
private FileModel document,inPlaceRecord;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
@Autowired
|
||||
private RulesAPI rulesAPI;
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void createTestPrecondition()
|
||||
{
|
||||
|
||||
|
||||
STEP("Create the RM site if doesn't exist");
|
||||
createRMSiteIfNotExists();
|
||||
|
||||
STEP("Create a user");
|
||||
nonRMuser = dataUser.createRandomTestUser("testUser");
|
||||
|
||||
STEP("Create a collaboration site");
|
||||
testSite = dataSite.usingUser(nonRMuser).createPublicRandomSite();
|
||||
|
||||
STEP("Create a document with the user without RM role");
|
||||
document = dataContent.usingSite(testSite)
|
||||
.usingUser(nonRMuser)
|
||||
.createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
||||
STEP("Create two categories with two folders");
|
||||
category_manager = createRootCategory(CATEGORY_MANAGER);
|
||||
category_admin = createRootCategory(CATEGORY_ADMIN);
|
||||
folder_admin = createFolder(category_admin.getId(),FOLDER_ADMIN);
|
||||
folder_manager = createFolder(category_manager.getId(),FOLDER_MANAGER);
|
||||
|
||||
|
||||
STEP("Create an rm user and give filling permission over CATEGORY_MANAGER record category");
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId())
|
||||
.build();
|
||||
rmManager = roleService.createCollaboratorWithRMRoleAndPermission(testSite, recordCategory,
|
||||
UserRoles.ROLE_RM_MANAGER, PERMISSION_FILING);
|
||||
|
||||
|
||||
|
||||
STEP("Create a collaboration folder with a rule set to declare and file version as record to a record folder");
|
||||
RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX + folderWithRule.getId(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void declareVersionAsRecordRuleAsRMUserWithFilingPermissions()
|
||||
{
|
||||
|
||||
STEP("Create a collaboration folder");
|
||||
testFolder = dataContent.usingSite(testSite)
|
||||
.usingUser(rmManager)
|
||||
.createFolder();
|
||||
|
||||
STEP("Create a rule with Declare as Record action and check that user can select a record folder.");
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
RecordCategoryChild folderWithRule = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(rmManager.getUsername(), rmManager.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void declareVersionAsRecordRuleAsNonRMUser()
|
||||
{
|
||||
|
||||
STEP("Create a collaboration folder");
|
||||
testFolder = dataContent.usingSite(testSite)
|
||||
.usingUser(nonRMuser)
|
||||
.createFolder();
|
||||
|
||||
STEP("Create a rule with Declare as Record action and check that user can select a record folder.");
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(nonRMuser.getUsername(), nonRMuser.getPassword(), NODE_PREFIX + testFolder.getNodeRef(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void triggerDeclareToUnfiledRuleAsNonRMUser() throws Exception {
|
||||
|
||||
STEP("Create a collaboration folder with a rule set to declare and file as record without a record folder location");
|
||||
|
||||
|
||||
FileModel inplaceRecord = dataContent.usingSite(testSite).usingUser(nonRMuser)
|
||||
.createContent(new FileModel("declareAndFileToIntoUnfiledRecordFolder",
|
||||
FileType.TEXT_PLAIN));
|
||||
|
||||
RecordCategory recordCategory = new RecordCategory().builder()
|
||||
.id(category_manager.getId()).build();
|
||||
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description")
|
||||
.applyToChildren(true)
|
||||
.actions(Collections.singletonList(ActionsOnRule.DECLARE_AS_RECORD.getActionValue()));
|
||||
rulesAPI.createRule(nonRMuser.getUsername(), nonRMuser.getPassword(), NODE_PREFIX + inplaceRecord.getNodeRef(), ruleDefinition);
|
||||
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
STEP("Create as nonRMuser a new file into the previous folder in order to trigger the rule");
|
||||
inPlaceRecord = dataContent.usingUser(nonRMuser).usingResource(testFolder).createContent(CMISUtil.DocumentType.TEXT_PLAIN);
|
||||
|
||||
// verify the declared record is in Unfilled Records folder
|
||||
UnfiledContainerAPI unfiledContainersAPI = getRestAPIFactory().getUnfiledContainersAPI();
|
||||
List<UnfiledContainerChildEntry> matchingRecords = unfiledContainersAPI.getUnfiledContainerChildren(UNFILED_RECORDS_CONTAINER_ALIAS)
|
||||
.getEntries()
|
||||
.stream()
|
||||
.filter(e -> e.getEntry().getId().equals(inplaceRecord.getNodeRefWithoutVersion()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void cleanupDeclareVersionAsRecordRuleTests()
|
||||
{
|
||||
|
||||
STEP("Delete the collaboration site");
|
||||
dataSite.usingUser(nonRMuser).deleteSite(testSite);
|
||||
|
||||
STEP("Delete Users");
|
||||
dataUser.deleteUser(nonRMuser);
|
||||
dataUser.deleteUser(rmManager);
|
||||
|
||||
|
||||
STEP("Delete categories");
|
||||
getRestAPIFactory().getFilePlansAPI().getRootRecordCategories(FILE_PLAN_ALIAS).getEntries().forEach(recordCategoryEntry ->
|
||||
deleteRecordCategory(recordCategoryEntry.getEntry().getId()));
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* #%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;
|
||||
import org.alfresco.rest.rm.community.model.rules.ActionsOnRule;
|
||||
import org.alfresco.rest.rm.community.model.rules.ConditionsOnRule;
|
||||
import org.alfresco.rest.rm.community.model.rules.RuleDefinition;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer;
|
||||
import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChildEntry;
|
||||
import org.alfresco.rest.rm.community.model.user.UserRoles;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI;
|
||||
import org.alfresco.rest.rm.community.requests.gscore.api.UnfiledContainerAPI;
|
||||
import org.alfresco.rest.search.RestRequestQueryModel;
|
||||
import org.alfresco.rest.v0.HoldsAPI;
|
||||
import org.alfresco.rest.v0.RecordsAPI;
|
||||
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;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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;
|
||||
import static org.alfresco.rest.rm.community.utils.CoreUtil.toContentModel;
|
||||
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.*;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
|
||||
public class MoveToRuleOnFoldersTest extends BaseRMRestTest{
|
||||
|
||||
|
||||
private RecordCategoryChild recordFolder2;
|
||||
private RecordCategoryChild recordFolder1;
|
||||
private String nonElectronicId;
|
||||
|
||||
public Record electronicRecord;
|
||||
|
||||
private String ruleType = ConditionsOnRule.UPDATE.getWhenConditionValue();
|
||||
private UserModel rmAdmin;
|
||||
public RecordCategory RecordCategoryOne;
|
||||
private RecordCategoryChild recordFolder;
|
||||
public static final String RECORD_FOLDER_ONE = "record-folder-one";
|
||||
private final String TEST_PREFIX = generateTestPrefix(MoveToRuleOnFoldersTest.class);
|
||||
|
||||
private final String RECORD_CATEGORY_ONE = TEST_PREFIX + "category";
|
||||
|
||||
private final String recordName = "Test record";
|
||||
private final String recordTitle = recordName + " title";
|
||||
private final String recordDescription = recordName + " description";
|
||||
private Record nonElectrinicRecordModel;
|
||||
private RecordFolderAPI recordFolderAPI;
|
||||
public String title,description,box,file,shelf,storageLocation,name;
|
||||
@Autowired
|
||||
private RulesAPI rulesAPI;
|
||||
@Autowired
|
||||
private HoldsAPI holdsAPI;
|
||||
|
||||
@Autowired
|
||||
private RoleService roleService;
|
||||
|
||||
@Autowired
|
||||
public RecordsAPI recordsAPI;
|
||||
|
||||
|
||||
@BeforeClass(alwaysRun = true)
|
||||
public void precondition()
|
||||
{
|
||||
//create RM site
|
||||
createRMSiteIfNotExists();
|
||||
rmAdmin = roleService.createUserWithRMRole(UserRoles.ROLE_RM_ADMIN.roleId);
|
||||
//create root category, create folders , add electronic and non electronic records
|
||||
RecordCategoryOne = createRootCategory(RECORD_CATEGORY_ONE);
|
||||
recordFolder1=createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder"));
|
||||
// recordFolder1_id = createRecordFolder(RecordCategoryOne.getId(), getRandomName("recFolder")).getId();
|
||||
recordFolder2 = createFolder(getAdminUser(),RecordCategoryOne.getId(),getRandomName("recFolder"));
|
||||
|
||||
|
||||
STEP("CREATE ELECTRONIC RECORD");
|
||||
recordFolderAPI = getRestAPIFactory().getRecordFolderAPI();
|
||||
electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE));
|
||||
STEP("Check the electronic record has been created");
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
|
||||
STEP("Create a non-electronic record by completing some of the fields");
|
||||
// Use these properties for non-electronic record to be created
|
||||
title = "Title " + getRandomAlphanumeric();
|
||||
description = "Description " + getRandomAlphanumeric();
|
||||
box = "Box "+ getRandomAlphanumeric();
|
||||
file = "File " + getRandomAlphanumeric();
|
||||
shelf = "Shelf " + getRandomAlphanumeric();
|
||||
storageLocation = "Storage Location " + getRandomAlphanumeric();
|
||||
name = "Record " + getRandomAlphanumeric();
|
||||
Random random = new Random();
|
||||
Integer numberOfCopies = random.nextInt(MAX_VALUE);
|
||||
Integer physicalSize = random.nextInt(MAX_VALUE);
|
||||
|
||||
// Set values of all available properties for the non electronic records
|
||||
nonElectrinicRecordModel = createFullNonElectronicRecordModel(name, title, description, box, file, shelf, storageLocation, numberOfCopies, physicalSize);
|
||||
// Create non-electronic record
|
||||
nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId();
|
||||
STEP("Check the non-electronic record has been created");
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void MoveToRuleFoldersTest()
|
||||
{
|
||||
|
||||
String CatName=RecordCategoryOne.getName();
|
||||
String folder2name=recordFolder2.getName();
|
||||
String recfolder2_path="/"+CatName+"/"+folder2name;
|
||||
|
||||
STEP("create a rule MOVE_TO for folder 1");
|
||||
RuleDefinition ruleDefinition = RuleDefinition.createNewRule().title("name").description("description1")
|
||||
.runInBackground(true).title(title)
|
||||
.actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path);
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition);
|
||||
|
||||
|
||||
|
||||
STEP("Update metadata for Non-Electronic Record");
|
||||
updateRecordMetadata();
|
||||
|
||||
STEP("Delete ELECTRONIC AND NON-ELECTRONIC RECORDS IN FOLDER 2");
|
||||
org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI recordsAPI = getRestAPIFactory().getRecordsAPI();
|
||||
recordsAPI.deleteRecord(electronicRecord.getId());
|
||||
assertStatusCode(NO_CONTENT);
|
||||
recordsAPI.deleteRecord(nonElectronicId);
|
||||
assertStatusCode(NO_CONTENT);
|
||||
|
||||
STEP("RULE CREATION FOR FOLDER 1 WITHOUT RUNNING IN BACKGROUND");
|
||||
|
||||
RuleDefinition ruleDefinition_notinbackground = RuleDefinition.createNewRule().title("name").description("description1")
|
||||
.runInBackground(false).title(title)
|
||||
.actions(Collections.singletonList(ActionsOnRule.MOVE_TO.getActionValue())).ruleType(ruleType).path(recfolder2_path);
|
||||
rulesAPI.createRule(getAdminUser().getUsername(), getAdminUser().getPassword(), NODE_PREFIX +recordFolder1.getId() , ruleDefinition);
|
||||
|
||||
STEP("CREATE ELECTRONIC AND NON-ELECTRONIC RECORDS");
|
||||
electronicRecord = recordFolderAPI.createRecord(createElectronicRecordModel(), recordFolder1.getId(), getFile(IMAGE_FILE));
|
||||
STEP("Check the electronic record has been created");
|
||||
assertStatusCode(CREATED);
|
||||
nonElectronicId = recordFolderAPI.createRecord(nonElectrinicRecordModel, recordFolder1.getId()).getId();
|
||||
STEP("Check the non-electronic record has been created");
|
||||
assertStatusCode(CREATED);
|
||||
|
||||
STEP("UPDATE METADATA");
|
||||
updateRecordMetadata();
|
||||
|
||||
STEP("CHECK IF ELECTRONIC AND NON-ELECTRONIC RECORDS MOVED TO FOLDER2");
|
||||
updateRecordMetadata();
|
||||
}
|
||||
|
||||
@AfterClass(alwaysRun = true)
|
||||
public void cleanMoveToRuleOnFoldersTest()
|
||||
{
|
||||
deleteRecordCategory(RecordCategoryOne.getId());
|
||||
|
||||
getDataUser().deleteUser(rmAdmin);
|
||||
}
|
||||
|
||||
private String getModifiedPropertyValue(String originalValue) {
|
||||
/* to be used to append to modifications */
|
||||
String MODIFIED_PREFIX = "modified_";
|
||||
return MODIFIED_PREFIX + originalValue;
|
||||
}
|
||||
private void updateRecordMetadata(){
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user