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 43178fdb4d..efb3f2f58c 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 @@ -33,6 +33,7 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAlias.UNFILED_RECORDS_CONTAINER_ALIAS; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentAspects.ASPECTS_COMPLETED_RECORD; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.CONTENT_TYPE; +import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.NON_ELECTRONIC_RECORD_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_CATEGORY_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.RECORD_TYPE; @@ -529,6 +530,35 @@ public class BaseRMRestTest extends RestTest Record recordModel = Record.builder().name(name).nodeType(CONTENT_TYPE).build(); return recordFolderAPI.createRecord(recordModel, parentId); } + + /** + * Create a non-electronic record + * + * @param parentId the id of the parent + * @param name the name of the record + * @return the created record + * @throws Exception + */ + public Record createNonElectronicRecord(String parentId, String name) throws Exception + { + return createNonElectronicRecord(parentId, name, null); + } + + /** + * Create a non-electronic record + * + * @param parentId the id of the parent + * @param name the name of the record + * @return the created record + * @throws Exception + */ + public Record createNonElectronicRecord(String parentId, String name, UserModel user) throws Exception + { + RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(user); + Record recordModel = Record.builder().name(name).nodeType(NON_ELECTRONIC_RECORD_TYPE).build(); + return recordFolderAPI.createRecord(recordModel, parentId); + } + /** * Delete a record folder * diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java index b5f35e7320..733383936c 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/type/RecordCategoryType.java @@ -155,7 +155,10 @@ public class RecordCategoryType extends BaseBehaviourBean public Void doWork() { // setup vital record definition - vitalRecordService.setupVitalRecordDefinition(child); + if(nodeService.exists(child)) + { + vitalRecordService.setupVitalRecordDefinition(child); + } return null; } @@ -190,7 +193,10 @@ public class RecordCategoryType extends BaseBehaviourBean public Void doWork() { // setup record category permissions - filePlanPermissionService.setupRecordCategoryPermissions(childAssocRef.getChildRef()); + if(nodeService.exists(childAssocRef.getChildRef())) + { + filePlanPermissionService.setupRecordCategoryPermissions(childAssocRef.getChildRef()); + } return null; } diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 166e87aaf3..44d8bba814 100644 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -54,6 +54,7 @@ import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderServi import org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService; import org.alfresco.module.org_alfresco_module_rm.report.ReportService; import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; +import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService; import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; import org.alfresco.module.org_alfresco_module_rm.security.FilePlanPermissionService; @@ -173,6 +174,9 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase protected InplaceRecordService inplaceRecordService; protected RelationshipService relationshipService; + /** test utils */ + protected UserAndGroupsUtils userAndGroupsUtils; + /** test data */ protected String siteId; protected StoreRef storeRef; @@ -340,6 +344,7 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase // Get the application context applicationContext = ApplicationContextHelper.getApplicationContext(getConfigLocations()); utils = new CommonRMTestUtils(applicationContext); + userAndGroupsUtils = new UserAndGroupsUtils(applicationContext); // Initialise the service beans initServices(); diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/UserAndGroupsUtils.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/UserAndGroupsUtils.java new file mode 100644 index 0000000000..c70d185648 --- /dev/null +++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/UserAndGroupsUtils.java @@ -0,0 +1,100 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 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 . + * #L% + */ + +package org.alfresco.module.org_alfresco_module_rm.test.util; + +import static org.junit.Assert.assertNotNull; + +import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; +import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; +import org.alfresco.module.org_alfresco_module_rm.role.Role; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AuthorityService; +import org.springframework.context.ApplicationContext; + +/** + * Test utils class containing methods for managing user, groups and roles + * + * @author Ana Manolache + * @since 2.6 + */ +public class UserAndGroupsUtils +{ + protected FilePlanRoleService filePlanRoleService; + protected AuthorityService authorityService; + + /** + * @param applicationContext the application context + */ + public UserAndGroupsUtils(ApplicationContext applicationContext) + { + filePlanRoleService = (FilePlanRoleService) applicationContext.getBean("FilePlanRoleService"); + authorityService = (AuthorityService) applicationContext.getBean("AuthorityService"); + } + + /** + * Add a user to an RM role + * + * @param userName the username of the user to add to the role + * @param role the role to add the user to + */ + public void addUserToRole(NodeRef filePlan, String userName, RMRole role) + { + // Find the authority for the given role + Role roleObj = filePlanRoleService.getRole(filePlan, role.getGroupName()); + assertNotNull("Notification role " + role.getGroupName() + " could not be retrieved", roleObj); + String roleGroup = roleObj.getRoleGroupName(); + assertNotNull("Notification role group " + roleGroup + " can not be null.", roleGroup); + + // Add user to notification role group + authorityService.addAuthority(roleGroup, userName); + } + + /** + * An enum of RM Roles + */ + public enum RMRole + { + RM_ADMINISTRATOR("Administrator"), + RM_MANAGER("RecordsManager"), + RM_POWER_USER("PowerUser"), + RM_SECURITY_OFFICER("SecurityOfficer"), + RM_USER("User"); + + private String groupName; + + private RMRole(String groupName) + { + this.groupName = groupName; + } + + public String getGroupName() + { + return this.groupName; + } + } +}