From 2742f702209b8129450803004933a62e3fa18ddf Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 5 Nov 2018 18:51:34 +0200 Subject: [PATCH 01/13] update tas rest api version to 5.2.0.12 (cherry picked from commit f76491b09fb9d2daff3387a4d19de32fd0dd179d) --- rm-automation/rm-automation-community-rest-api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index d45d244d80..31c2e1257b 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -15,7 +15,7 @@ 1.8 alfresco-rm-community-share alfresco-rm-community-repo - 5.2.0-10 + 5.2.0.12 2.0.0 From 76658f0206696fa6827a39d34bd55c9071a5f12d Mon Sep 17 00:00:00 2001 From: Tom Page Date: Wed, 20 Feb 2019 08:38:17 +0000 Subject: [PATCH 02/13] Update TAS rest api to the latest version from 5.2.0.X - 5.2.0.15 --- rm-automation/rm-automation-community-rest-api/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/pom.xml b/rm-automation/rm-automation-community-rest-api/pom.xml index 31c2e1257b..ca48d73c46 100644 --- a/rm-automation/rm-automation-community-rest-api/pom.xml +++ b/rm-automation/rm-automation-community-rest-api/pom.xml @@ -15,7 +15,7 @@ 1.8 alfresco-rm-community-share alfresco-rm-community-repo - 5.2.0.12 + 5.2.0.15 2.0.0 From 84aca54f31d2e1723c0b1b7ad17273c867ed6558 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 6 Nov 2018 09:04:24 +0200 Subject: [PATCH 03/13] adding search tests for the SQL support (cherry picked from commit 29f2ddf2203261f477464528a9f5b83a7679223c) # Conflicts: # rm-automation/rm-automation-enterprise-rest-api/pom.xml --- .../alfresco/rest/rm/community/base/BaseRMRestTest.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 aa65f8c967..428b338910 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 @@ -57,6 +57,7 @@ import java.util.stream.Collectors; import org.alfresco.dataprep.ContentService; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestAPIFactory; +import org.alfresco.rest.core.RestResponse; import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.model.fileplan.FilePlan; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType; @@ -76,6 +77,7 @@ import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; import org.alfresco.rest.search.RestRequestQueryModel; import org.alfresco.rest.search.SearchNodeModel; import org.alfresco.rest.search.SearchRequest; +import org.alfresco.rest.search.SearchSqlRequest; import org.alfresco.rest.v0.RMRolesAndActionsAPI; import org.alfresco.rest.v0.SearchAPI; import org.alfresco.utility.data.DataUser; @@ -796,4 +798,9 @@ public class BaseRMRestTest extends RestTest return documentLibrary; } + protected RestResponse searchSql(UserModel userModel, SearchSqlRequest searchSqlRequest) throws Exception + { + return restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(searchSqlRequest); + } + } From 2ab90aad6bb8d2e40f519cffa90365b40faf654f Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 15 Nov 2018 11:13:28 +0000 Subject: [PATCH 04/13] RM-6141 Update SQL tests to use correct users. Also hardcode the site id of the RM site to be "rm", so that we can use this when adding site members. (cherry picked from commit 92a6dcf8ae04151699b0b5a4bad79bc82f36ae71) # Conflicts: # rm-enterprise/pom.xml --- .../java/org/alfresco/rest/rm/community/model/site/RMSite.java | 3 ++- .../java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java index 7abae8755d..3fa3518be0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java @@ -53,8 +53,9 @@ public class RMSite extends RestSiteModel /** Private constructor allowing Lombok to include superclass fields in the builder. */ @Builder - private RMSite(String title, String description, RMSiteCompliance compliance) + private RMSite(String id, String title, String description, RMSiteCompliance compliance) { + this.setId(id); this.setTitle(title); this.setDescription(description); this.compliance = compliance; diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java index b3574a0fcb..bbea049fbb 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java @@ -60,7 +60,7 @@ public class RMSiteUtil */ public static RMSite createRMSiteModel(RMSiteCompliance compliance, String title, String description) { - return RMSite.builder().compliance(compliance).title(title).description(description).build(); + return RMSite.builder().id(RM_ID).compliance(compliance).title(title).description(description).build(); } /** From 23c98eaa082f0507b6911bd05e697fe07404df7f Mon Sep 17 00:00:00 2001 From: Tom Page Date: Thu, 15 Nov 2018 14:39:49 +0000 Subject: [PATCH 05/13] RM-6141 Revert change of how a user is a member of the RM site. The user should be an RM User, not a site manager. Also revert a couple of changes that were done to make this work. Minor tweaks to use constants rather than member variables. (cherry picked from commit b284ba90388ef360f5321826e292ec43bf2e5197) --- .../java/org/alfresco/rest/rm/community/model/site/RMSite.java | 3 +-- .../java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java index 3fa3518be0..7abae8755d 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/site/RMSite.java @@ -53,9 +53,8 @@ public class RMSite extends RestSiteModel /** Private constructor allowing Lombok to include superclass fields in the builder. */ @Builder - private RMSite(String id, String title, String description, RMSiteCompliance compliance) + private RMSite(String title, String description, RMSiteCompliance compliance) { - this.setId(id); this.setTitle(title); this.setDescription(description); this.compliance = compliance; diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java index bbea049fbb..b3574a0fcb 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java @@ -60,7 +60,7 @@ public class RMSiteUtil */ public static RMSite createRMSiteModel(RMSiteCompliance compliance, String title, String description) { - return RMSite.builder().id(RM_ID).compliance(compliance).title(title).description(description).build(); + return RMSite.builder().compliance(compliance).title(title).description(description).build(); } /** From b32f324c31b953ef55ed5aa46c96ed548b5ad2e6 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 19 Jun 2019 14:55:23 +0300 Subject: [PATCH 06/13] add the alfresco.port property --- .../src/main/resources/config.properties | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties b/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties index 8b94951ea5..727a2d00e7 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties +++ b/rm-automation/rm-automation-community-rest-api/src/main/resources/config.properties @@ -1,2 +1,3 @@ alfresco.server=localhost -rest.rmPath=alfresco/api/-default-/public/gs/versions/1 \ No newline at end of file +rest.rmPath=alfresco/api/-default-/public/gs/versions/1 +alfresco.port=8080 \ No newline at end of file From 9314432beb7d6644022a205d061f0ebfb51b2cc9 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 24 Jun 2019 10:16:20 +0300 Subject: [PATCH 07/13] test updates: minor refactoring and formatting fixes --- .../rest/rm/community/requests/gscore/GSCoreAPI.java | 2 +- .../org/alfresco/rest/rm/community/base/BaseRMRestTest.java | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java index 23f6655166..febd2b5427 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/GSCoreAPI.java @@ -113,7 +113,7 @@ public class GSCoreAPI extends RMModelRequest /** * Provides DSL on all REST calls under records/... API path * - * @return {@link FilePlanComponentAPI} + * @return {@link RecordsAPI} */ public RecordsAPI usingRecords() { 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 428b338910..dafa0abb2f 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 @@ -798,9 +798,4 @@ public class BaseRMRestTest extends RestTest return documentLibrary; } - protected RestResponse searchSql(UserModel userModel, SearchSqlRequest searchSqlRequest) throws Exception - { - return restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(searchSqlRequest); - } - } From 11a638c827e781838229b2b26aadb265557be772 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 2 Jul 2019 10:29:21 +0300 Subject: [PATCH 08/13] refactoring of the added rest api tests for SQL queries new tests added for sql queries for: record categories, record folders and records --- .../requests/gscore/api/RMUserAPI.java | 111 ++++++++++++------ .../rest/v0/RMRolesAndActionsAPI.java | 37 +++++- .../src/test/resources/log4j.properties | 7 ++ 3 files changed, 116 insertions(+), 39 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java index d24c53c614..2466211a55 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java @@ -84,6 +84,7 @@ public class RMUserAPI extends RMModelRequest /** * Assign RM role to user + * * @param userName User's username * @param userRole User's RM role, one of {@link UserRoles} roles * @throws Exception for failed requests @@ -97,29 +98,30 @@ public class RMUserAPI extends RMModelRequest // override v1 baseURI and basePath RequestSpecification spec = new RequestSpecBuilder() - .setBaseUri(client.getApiUrl()) - .setBasePath("/") - .build(); + .setBaseUri(client.getApiUrl()) + .setBasePath("/") + .build(); Response response = given() - .spec(spec) - .log().all() - .pathParam("role", userRole) - .pathParam("authority", userName) - .param("alf_ticket", client.getAlfTicket(adminUser.getUsername(), - adminUser.getPassword())) - .when() - .post("/rm/roles/{role}/authorities/{authority}") - .prettyPeek() - .andReturn(); + .spec(spec) + .log().all() + .pathParam("role", userRole) + .pathParam("authority", userName) + .param("alf_ticket", client.getAlfTicket(adminUser.getUsername(), + adminUser.getPassword())) + .when() + .post("/rm/roles/{role}/authorities/{authority}") + .prettyPeek() + .andReturn(); getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); } /** * Helper method to add permission on a component to user - * @param component The id of the file plan component on which permission should be given - * @param user {@link UserModel} for a user to be granted permission - * @param permission {@link UserPermissions} to be granted + * + * @param filePlanComponentId The id of the file plan component on which permission should be given + * @param user {@link UserModel} for a user to be granted permission + * @param permission {@link UserPermissions} to be granted */ public void addUserPermission(String filePlanComponentId, UserModel user, String permission) { @@ -129,34 +131,75 @@ public class RMUserAPI extends RMModelRequest AlfrescoHttpClient client = getAlfrescoHttpClient(); JsonObject bodyJson = buildObject() - .addArray("permissions") + .addArray("permissions") .addObject() - .add("authority", user.getUsername()) - .add("role", permission) - .end() - .getJson(); + .add("authority", (user != null ? user.getUsername() : null)) + .add("role", permission) + .end() + .getJson(); // override v1 baseURI and basePath RequestSpecification spec = new RequestSpecBuilder() - .setBaseUri(client.getApiUrl()) - .setBasePath("/") - .build(); + .setBaseUri(client.getApiUrl()) + .setBasePath("/") + .build(); // execute an "old-style" API call Response response = given() - .spec(spec) - .auth().basic(adminUser.getUsername(), adminUser.getPassword()) - .contentType(ContentType.JSON) - .body(bodyJson.toString()) - .pathParam("nodeId", filePlanComponentId) - .log().all() - .when() - .post("/node/workspace/SpacesStore/{nodeId}/rmpermissions") - .prettyPeek() - .andReturn(); + .spec(spec) + .auth().basic(adminUser.getUsername(), adminUser.getPassword()) + .contentType(ContentType.JSON) + .body(bodyJson.toString()) + .pathParam("nodeId", filePlanComponentId) + .log().all() + .when() + .post("/node/workspace/SpacesStore/{nodeId}/rmpermissions") + .prettyPeek() + .andReturn(); getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); } + /** + * Helper method to add permission on a component to user + * + * @param filePlanComponentId The id of the file plan component on which permission should be given + * @param permission {@link UserPermissions} to be granted + */ + public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited) + { + UserModel adminUser = getRmRestWrapper().getTestUser(); + + // get an "old-style" REST API client + AlfrescoHttpClient client = getAlfrescoHttpClient(); + + JsonObject bodyJson = buildObject() + .addArray("permissions") + .end() + .add("isInherited", isInherited) + .getJson(); + + // override v1 baseURI and basePath + RequestSpecification spec = new RequestSpecBuilder() + .setBaseUri(client.getApiUrl()) + .setBasePath("/") + .build(); + + // execute an "old-style" API call + Response response = given() + .spec(spec) + .auth().basic(adminUser.getUsername(), adminUser.getPassword()) + .contentType(ContentType.JSON) + .body(bodyJson.toString()) + .pathParam("nodeId", filePlanComponentId) + .log().all() + .when() + .post("/node/workspace/SpacesStore/{nodeId}/rmpermissions") + .prettyPeek() + .andReturn(); + getRmRestWrapper().setStatusCode(Integer.toString(response.getStatusCode())); + } + + /** * Creates a user with the given name using the old APIs * 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 6f07fcf3ab..3be051a3d2 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 @@ -48,6 +48,7 @@ import org.alfresco.dataprep.ContentService; import org.alfresco.dataprep.UserService; import org.alfresco.rest.core.v0.BaseAPI; import org.alfresco.rest.core.v0.RMEvents; +import org.alfresco.utility.Utility; import org.apache.chemistry.opencmis.client.api.CmisObject; import org.apache.commons.httpclient.HttpStatus; import org.apache.http.HttpResponse; @@ -73,6 +74,8 @@ import org.springframework.stereotype.Component; @Component public class RMRolesAndActionsAPI extends BaseAPI { + public static final String HOLDS_CONTAINER = "Holds"; + /** The URI to view the configured roles and capabilities. */ private static final String RM_ROLES = "{0}rma/admin/rmroles"; /** The URI for REST requests about a particular configured role. */ @@ -83,6 +86,8 @@ public class RMRolesAndActionsAPI extends BaseAPI private static final Logger LOGGER = LoggerFactory.getLogger(RMRolesAndActionsAPI.class); private static final String MOVE_ACTIONS_API = "action/rm-move-to/site/rm/documentLibrary/{0}"; private static final String CREATE_HOLDS_API = "{0}type/rma:hold/formprocessor"; + /** The URI to add items to hold.*/ + private static final String RM_HOLDS_API = "{0}rma/holds"; /** http client factory */ @Autowired @@ -447,9 +452,9 @@ public class RMRolesAndActionsAPI extends BaseAPI public HttpResponse createHold(String user, String password, String holdName, String reason, String description) { // if the hold already exists don't try to create it again - String holdsContainerPath = getFilePlanPath() + "/Holds"; - String fullHoldPath = holdsContainerPath + "/" + holdName; - CmisObject hold = getObjectByPath(user, password, fullHoldPath); + final String holdsContainerPath = Utility.buildPath(getFilePlanPath(), HOLDS_CONTAINER); + final String fullHoldPath = holdsContainerPath + holdName; + final CmisObject hold = getObjectByPath(user, password, fullHoldPath); if (hold != null) { return null; @@ -457,19 +462,41 @@ public class RMRolesAndActionsAPI extends BaseAPI // retrieve the Holds container nodeRef String parentNodeRef = getItemNodeRef(user, password, "/Holds"); - JSONObject requestParams = new JSONObject(); + final JSONObject requestParams = new JSONObject(); requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); requestParams.put("prop_cm_name", holdName); requestParams.put("prop_cm_description", description); requestParams.put("prop_rma_holdReason", reason); // Make the POST request and throw an assertion error if it fails. - HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API); + final HttpResponse httpResponse = doPostJsonRequest(user, password, SC_OK, requestParams, CREATE_HOLDS_API); assertNotNull("Expected object to have been created at " + fullHoldPath, getObjectByPath(user, password, fullHoldPath)); return httpResponse; } + /** + * Adds item (record/ record folder) to the hold + * + * @param user the user who adds the item to the hold + * @param password the user's password + * @param itemNodeRef the nodeRef of the item to be added to hold + * @param holdName the hold name + * @return The HTTP response + */ + public HttpResponse addItemToHold(String user, String password, String itemNodeRef, String holdName) + { + final JSONArray nodeRefs = new JSONArray().put(getNodeRefSpacesStore() + itemNodeRef); + final String holdNodeRef = getItemNodeRef(user, password, String.format("/%s/%s", HOLDS_CONTAINER, holdName)); + final JSONArray holds = new JSONArray().put(getNodeRefSpacesStore() + holdNodeRef); + final JSONObject requestParams = new JSONObject(); + requestParams.put("nodeRefs", nodeRefs); + requestParams.put("holds", holds); + + return doPostJsonRequest(user, password, SC_OK, requestParams, RM_HOLDS_API); + } + + /** * Updates metadata, can be used on records, folders and categories * diff --git a/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties b/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties new file mode 100644 index 0000000000..93c931c03c --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=info, console + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n + +log4j.logger.com.example=debug \ No newline at end of file From 9dddcdc1101ff1a3e08bc66625505a276c3f2cf7 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 3 Jul 2019 18:23:45 +0300 Subject: [PATCH 09/13] code review changes --- .../rest/rm/community/requests/gscore/api/RMUserAPI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java index 2466211a55..9671dfe7a6 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java @@ -89,7 +89,7 @@ public class RMUserAPI extends RMModelRequest * @param userRole User's RM role, one of {@link UserRoles} roles * @throws Exception for failed requests */ - public void assignRoleToUser(String userName, String userRole) throws Exception + public void assignRoleToUser(String userName, String userRole) { UserModel adminUser = getRmRestWrapper().getTestUser(); @@ -160,10 +160,10 @@ public class RMUserAPI extends RMModelRequest } /** - * Helper method to add permission on a component to user + * Helper method to set the inherited permission on a file plan component * - * @param filePlanComponentId The id of the file plan component on which permission should be given - * @param permission {@link UserPermissions} to be granted + * @param filePlanComponentId The id of the file plan component on which inherited permission should be set + * @param isInherited {@link UserPermissions} to be granted */ public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited) { From fce52415cbf62e4df2ce0a5af511332dc15c8191 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Thu, 4 Jul 2019 13:18:16 +0300 Subject: [PATCH 10/13] review updates --- .../rest/rm/community/requests/gscore/api/RMUserAPI.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java index 9671dfe7a6..5eaf86dcb3 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java @@ -160,10 +160,11 @@ public class RMUserAPI extends RMModelRequest } /** - * Helper method to set the inherited permission on a file plan component + * Helper method to set permission inheritance on a file plan component * * @param filePlanComponentId The id of the file plan component on which inherited permission should be set - * @param isInherited {@link UserPermissions} to be granted + * @param isInherited true if the permission is inherited + * false if the permission inheritance is disabled */ public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited) { From 1070562e079b69007991f043e8991d8b8a4e774f Mon Sep 17 00:00:00 2001 From: cagache Date: Tue, 23 Apr 2019 08:23:43 +0300 Subject: [PATCH 11/13] transform UserPermissions in enum; add helper methods to create users with rm role, permissions or clearance (cherry picked from commit 451eaaf679b5c734607726477c8de0168aa4b722) # Conflicts: # rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java # rm-automation/rm-automation-enterprise-rest-api/src/test/java/org/alfresco/rest/rm/enterprise/base/BaseRMEnterpriseRestTest.java # rm-automation/rm-automation-enterprise-rest-api/src/test/java/org/alfresco/rest/rm/enterprise/v0/classification/folder/RecordFolderClassificationTest.java --- .../community/model/user/UserPermissions.java | 15 ++- .../requests/gscore/api/FilesAPI.java | 6 +- .../requests/gscore/api/RMUserAPI.java | 10 +- .../alfresco/rest/v0/service/RoleService.java | 107 ++++++++++++++++-- .../rm/community/base/BaseRMRestTest.java | 39 +++++-- .../community/records/DeleteRecordTests.java | 7 +- .../community/records/UpdateRecordsTests.java | 9 +- .../rest/rm/community/utils/RMSiteUtil.java | 2 +- 8 files changed, 149 insertions(+), 46 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java index 1b9dfe5aba..7c237bd47c 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/user/UserPermissions.java @@ -32,9 +32,16 @@ package org.alfresco.rest.rm.community.model.user; * @author Kristijan Conkas * @since 2.6 */ -public class UserPermissions +public enum UserPermissions { - public static final String PERMISSION_FILING = "Filing"; - public static final String PERMISSION_READ_RECORDS = "ReadRecords"; - public static final String PERMISSION_FILE_RECORDS = "FileRecords"; + PERMISSION_FILING("Filing"), + PERMISSION_READ_RECORDS("ReadRecords"), + PERMISSION_FILE_RECORDS("FileRecords"); + + public final String permissionId; + + UserPermissions(String permissionId) + { + this.permissionId = permissionId; + } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java index 10da1e0570..18b91bd2cc 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java @@ -57,9 +57,8 @@ public class FilesAPI extends RMModelRequest * @param fileId The Id of a file to declare as record * @param parameters Request parameters, refer to API documentation for more details * @return The {@link Record} for created record - * @throws Exception for malformed JSON responses */ - public Record declareAsRecord(String fileId, String parameters) throws Exception + public Record declareAsRecord(String fileId, String parameters) { mandatoryString("fileId", fileId); @@ -76,9 +75,8 @@ public class FilesAPI extends RMModelRequest * * @param fileId The Id of a file to declare as record * @return The {@link Record} for created record - * @throws Exception for malformed JSON responses */ - public Record declareAsRecord(String fileId) throws Exception + public Record declareAsRecord(String fileId) { mandatoryString("fileId", fileId); diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java index 5eaf86dcb3..aa78902cae 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java @@ -87,7 +87,6 @@ public class RMUserAPI extends RMModelRequest * * @param userName User's username * @param userRole User's RM role, one of {@link UserRoles} roles - * @throws Exception for failed requests */ public void assignRoleToUser(String userName, String userRole) { @@ -118,12 +117,11 @@ public class RMUserAPI extends RMModelRequest /** * Helper method to add permission on a component to user - * * @param filePlanComponentId The id of the file plan component on which permission should be given - * @param user {@link UserModel} for a user to be granted permission - * @param permission {@link UserPermissions} to be granted + * @param user {@link UserModel} for a user to be granted permission + * @param permission {@link UserPermissions} to be granted */ - public void addUserPermission(String filePlanComponentId, UserModel user, String permission) + public void addUserPermission(String filePlanComponentId, UserModel user, UserPermissions permission) { UserModel adminUser = getRmRestWrapper().getTestUser(); @@ -134,7 +132,7 @@ public class RMUserAPI extends RMModelRequest .addArray("permissions") .addObject() .add("authority", (user != null ? user.getUsername() : null)) - .add("role", permission) + .add("role", permission.permissionId) .end() .getJson(); diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java index ccf2785cd8..a5bdff72c0 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java @@ -26,12 +26,22 @@ */ package org.alfresco.rest.v0.service; +import static lombok.AccessLevel.PROTECTED; +import static org.springframework.http.HttpStatus.OK; + import java.util.HashSet; import java.util.Set; +import lombok.Getter; +import org.alfresco.rest.core.RestAPIFactory; +import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; +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.model.SiteModel; +import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -45,11 +55,29 @@ import org.springframework.stereotype.Service; public class RoleService { @Autowired + @Getter (value = PROTECTED) private RMRolesAndActionsAPI rmRolesAndActionsAPI; @Autowired + @Getter (value = PROTECTED) private DataUser dataUser; + @Autowired + @Getter (value = PROTECTED) + private RestAPIFactory restAPIFactory; + + /** + * Get the capabilities for a role + * + * @param roleName the role name + * @return the list of capabilities + */ + public Set getRoleCapabilities(String roleName) + { + return getRmRolesAndActionsAPI().getCapabilitiesForRole(getDataUser().getAdminUser().getUsername(), + getDataUser().getAdminUser().getPassword(), roleName); + } + /** * Add capabilities to a role * @@ -58,12 +86,10 @@ public class RoleService */ public void addCapabilitiesToRole(UserRoles role, Set capabilities) { - Set roleCapabilities = new HashSet<>(); - roleCapabilities.addAll(rmRolesAndActionsAPI.getCapabilitiesForRole(dataUser.getAdminUser().getUsername(), - dataUser.getAdminUser().getPassword(), role.roleId)); - capabilities.stream().forEach(cap -> roleCapabilities.add(cap)); + Set roleCapabilities = new HashSet<>(getRoleCapabilities(role.roleId)); + roleCapabilities.addAll(capabilities); - rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), + getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(), role.roleId, role.displayName, roleCapabilities); } @@ -75,10 +101,75 @@ public class RoleService */ public void removeCapabilitiesFromRole(UserRoles role, Set capabilities) { - Set roleCapabilities = rmRolesAndActionsAPI.getCapabilitiesForRole(dataUser.getAdminUser().getUsername(), - dataUser.getAdminUser().getPassword(), role.roleId); + Set roleCapabilities = getRoleCapabilities(role.roleId); roleCapabilities.removeAll(capabilities); - rmRolesAndActionsAPI.updateRole(dataUser.getAdminUser().getUsername(), dataUser.getAdminUser().getPassword(), + getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(), role.roleId, role.displayName, roleCapabilities); } + + /** + * Assign permission on a record category and give the user RM role + * + * @param user the user to assign rm role and permissions + * @param categoryId the id of the category to assign permissions for + * @param userPermission the permissions to be assigned to the user + * @param userRole the rm role to be assigned to the user + */ + public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission, + String userRole) + { + getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission); + getRmRolesAndActionsAPI().assignRoleToUser(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(), + user.getUsername(), userRole); + } + + /** + * Helper method to create a test user with rm role + * + * @param userRole the rm role + * @return the created user model + */ + public UserModel createUserWithRMRole(String userRole) + { + final UserModel rmUser = getDataUser().createRandomTestUser(); + getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole); + getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK); + return rmUser; + } + + /** + * Helper method to create a test user with rm role and permissions over the record category + * + * @param userRole the rm role + * @param userPermission the permissions over the record category + * @param recordCategory the category on which user has permissions + * @return the created user model + */ + public UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory, + UserPermissions userPermission) + { + final UserModel rmUser = createUserWithRMRole(userRole); + getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission); + getRestAPIFactory().getRmRestWrapper().assertStatusCodeIs(OK); + return rmUser; + } + + /** + * Helper method to create a test user with rm role and permissions over the recordCategory and collaborator role + * in collaboration site + * + * @param siteModel collaboration site + * @param recordCategory the category on which permission should be given + * @param userRole the rm role + * @param userPermission the permissions over the recordCategory + * @return the created user model + */ + public UserModel createCollaboratorWithRMRoleAndPermission(SiteModel siteModel, RecordCategory recordCategory, + UserRoles userRole, UserPermissions userPermission) + { + final UserModel rmUser = createUserWithRMRoleAndCategoryPermission(userRole.roleId, recordCategory, + userPermission); + getDataUser().addUserToSite(rmUser, siteModel, UserRole.SiteCollaborator); + return rmUser; + } } 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 dafa0abb2f..de56972ccd 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 @@ -54,6 +54,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import lombok.Getter; import org.alfresco.dataprep.ContentService; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestAPIFactory; @@ -70,6 +71,7 @@ import org.alfresco.rest.rm.community.model.site.RMSite; import org.alfresco.rest.rm.community.model.transfercontainer.TransferContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; +import org.alfresco.rest.rm.community.model.user.UserPermissions; import org.alfresco.rest.rm.community.requests.gscore.api.RMSiteAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordCategoryAPI; import org.alfresco.rest.rm.community.requests.gscore.api.RecordFolderAPI; @@ -90,8 +92,6 @@ import org.springframework.http.HttpStatus; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; -import lombok.Getter; - /** * Base class for all GS REST API Tests * @@ -617,18 +617,34 @@ public class BaseRMRestTest extends RestTest } /** - * Assign filling permission on a record category and give the user RM_USER role + * Helper method to create a test user with rm role * - * @param user the user to assign the permission to - * @param categoryId the id of the category to assign permissions for - * @throws Exception + * @param userRole the rm role + * @return the created user model */ - public void assignFillingPermissionsOnCategory(UserModel user, String categoryId, - String userPermission, String userRole) throws Exception + protected UserModel createUserWithRMRole(String userRole) { - getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission); - rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(), - getAdminUser().getPassword(), user.getUsername(), userRole); + UserModel rmUser = getDataUser().createRandomTestUser(); + getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), userRole); + assertStatusCode(OK); + return rmUser; + } + + /** + * Helper method to create a test user with rm role and permissions over the record category + * + * @param userRole the rm role + * @param userPermission the permissions over the record category + * @param recordCategory the category on which user has permissions + * @return the created user model + */ + protected UserModel createUserWithRMRoleAndCategoryPermission(String userRole, RecordCategory recordCategory, + UserPermissions userPermission) + { + UserModel rmUser = createUserWithRMRole(userRole); + getRestAPIFactory().getRMUserAPI().addUserPermission(recordCategory.getId(), rmUser, userPermission); + assertStatusCode(OK); + return rmUser; } /** @@ -797,5 +813,4 @@ public class BaseRMRestTest extends RestTest documentLibrary.setNodeRef(nodes.get(0).onModel().getId()); return documentLibrary; } - } diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java index ef63360a39..387e263460 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/DeleteRecordTests.java @@ -236,15 +236,12 @@ public class DeleteRecordTests extends BaseRMRestTest public void userWithoutDeleteRecordsCapabilityCantDeleteRecord() throws Exception { // Create test user and add it with collaboration privileges - UserModel deleteUser = getDataUser().createRandomTestUser("delnoperm"); + // Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities + UserModel deleteUser = createUserWithRMRole(ROLE_RM_POWER_USER.roleId); getDataUser().addUserToSite(deleteUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), SiteCollaborator); String username = deleteUser.getUsername(); logger.info("Test user: " + username); - // Add RM role to user, RM Power User doesn't have the "Delete Record" capabilities - getRestAPIFactory().getRMUserAPI().assignRoleToUser(username, ROLE_RM_POWER_USER.roleId); - assertStatusCode(OK); - // Create random folder RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); logger.info("Random folder:" + recordFolder.getName()); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java index 2f8f3af510..c433c99dc6 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/UpdateRecordsTests.java @@ -234,15 +234,12 @@ public class UpdateRecordsTests extends BaseRMRestTest public void userWithEditMetadataCapsCanUpdateMetadata() throws Exception { RMUserAPI rmUserAPI = getRestAPIFactory().getRMUserAPI(); - // Create test user and add it with collab. privileges - UserModel updateUser = getDataUser().createRandomTestUser("updateuser"); + // Create test user and add it with collab. privileges. + // RM Security Officer is the lowest role with Edit Record Metadata capabilities + UserModel updateUser = createUserWithRMRole(ROLE_RM_SECURITY_OFFICER.roleId); updateUser.setUserRole(UserRole.SiteCollaborator); getDataUser().addUserToSite(updateUser, new SiteModel(getRestAPIFactory().getRMSiteAPI().getSite().getId()), UserRole.SiteCollaborator); - // RM Security Officer is the lowest role with Edit Record Metadata capabilities - rmUserAPI.assignRoleToUser(updateUser.getUsername(), ROLE_RM_SECURITY_OFFICER.roleId); - assertStatusCode(OK); - // Create random folder RecordCategoryChild recordFolder = createCategoryFolderInFilePlan(); logger.info("random folder:" + recordFolder.getName()); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java index b3574a0fcb..80062165ca 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/utils/RMSiteUtil.java @@ -66,7 +66,7 @@ public class RMSiteUtil /** * Creates an RM Site for the given compliance and default title and description * - * @param The RM site compliance + * @param compliance The RM site compliance * @return The {@link RMSite} with the given details */ private static RMSite createRMSiteModel(RMSiteCompliance compliance) From 2a9aca2ced6fb869cc1652a29e1c051b877e17cf Mon Sep 17 00:00:00 2001 From: cagache Date: Tue, 23 Apr 2019 12:15:38 +0300 Subject: [PATCH 12/13] transform UserPermissions in enum; add helper methods to create users with rm role, permissions or clearance (cherry picked from commit ebc860ea2abaf17124cb033225c5c3728dbe85e4) # Conflicts: # rm-automation/rm-automation-enterprise-rest-api/src/test/java/org/alfresco/rest/rm/enterprise/v0/classification/content/SetRMExemptionReasonTest.java --- .../community/requests/gscore/api/FilesAPI.java | 6 ++++-- .../rest/rm/community/base/BaseRMRestTest.java | 16 ++++++++++++++++ .../rm/community/base/DataProviderClass.java | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java index 18b91bd2cc..10da1e0570 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/FilesAPI.java @@ -57,8 +57,9 @@ public class FilesAPI extends RMModelRequest * @param fileId The Id of a file to declare as record * @param parameters Request parameters, refer to API documentation for more details * @return The {@link Record} for created record + * @throws Exception for malformed JSON responses */ - public Record declareAsRecord(String fileId, String parameters) + public Record declareAsRecord(String fileId, String parameters) throws Exception { mandatoryString("fileId", fileId); @@ -75,8 +76,9 @@ public class FilesAPI extends RMModelRequest * * @param fileId The Id of a file to declare as record * @return The {@link Record} for created record + * @throws Exception for malformed JSON responses */ - public Record declareAsRecord(String fileId) + public Record declareAsRecord(String fileId) throws Exception { mandatoryString("fileId", fileId); 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 48ec3e4cb6..86fc641882 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 @@ -616,6 +616,22 @@ public class BaseRMRestTest extends RestTest recordCategoryAPI.deleteRecordCategory(recordCategoryId); } + /** + * Assign permission on a record category and give the user RM role + * + * @param user the user to assign rm role and permissions + * @param categoryId the id of the category to assign permissions for + * @param userPermission the permissions to be assigned to the user + * @param userRole the rm role to be assigned to the user + */ + public void assignUserPermissionsOnCategoryAndRMRole(UserModel user, String categoryId, UserPermissions userPermission, + String userRole) + { + getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, userPermission); + rmRolesAndActionsAPI.assignRoleToUser(getAdminUser().getUsername(), getAdminUser().getPassword(), + user.getUsername(), userRole); + } + /** * Helper method to create a test user with rm role * diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java index b4b39f70b8..d437da677a 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/base/DataProviderClass.java @@ -105,7 +105,7 @@ public class DataProviderClass * @return file plan component alias */ @DataProvider - public static String[][] categoryTypes() + public static Object[][] categoryTypes() { return new String[][] { { FOLDER_TYPE }, From 5f4a5feb2a804efef025620e4e7cd977d8b57eb5 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Fri, 5 Jul 2019 12:50:19 +0300 Subject: [PATCH 13/13] fix sonar final warning --- .../requests/gscore/api/RMUserAPI.java | 12 +++++----- .../rest/v0/RMRolesAndActionsAPI.java | 22 ++++++++++--------- .../alfresco/rest/v0/service/RoleService.java | 4 ++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java index aa78902cae..6cd2b7d0d4 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/requests/gscore/api/RMUserAPI.java @@ -166,12 +166,12 @@ public class RMUserAPI extends RMModelRequest */ public void setUserPermissionInheritance(String filePlanComponentId, Boolean isInherited) { - UserModel adminUser = getRmRestWrapper().getTestUser(); + final UserModel adminUser = getRmRestWrapper().getTestUser(); // get an "old-style" REST API client - AlfrescoHttpClient client = getAlfrescoHttpClient(); + final AlfrescoHttpClient client = getAlfrescoHttpClient(); - JsonObject bodyJson = buildObject() + final JsonObject bodyJson = buildObject() .addArray("permissions") .end() .add("isInherited", isInherited) @@ -184,7 +184,7 @@ public class RMUserAPI extends RMModelRequest .build(); // execute an "old-style" API call - Response response = given() + final Response response = given() .spec(spec) .auth().basic(adminUser.getUsername(), adminUser.getPassword()) .contentType(ContentType.JSON) @@ -210,7 +210,7 @@ public class RMUserAPI extends RMModelRequest public boolean createUser(String userName, String userPassword, String userEmail) { UserModel adminUser = getRmRestWrapper().getTestUser(); - AlfrescoHttpClient client = getAlfrescoHttpClient(); + final AlfrescoHttpClient client = getAlfrescoHttpClient(); JsonObject body = buildObject() .add("userName", userName) @@ -220,7 +220,7 @@ public class RMUserAPI extends RMModelRequest .add("email", userEmail) .getJson(); - RequestSpecification spec = new RequestSpecBuilder() + final RequestSpecification spec = new RequestSpecBuilder() .setBaseUri(client.getApiUrl()) .setBasePath("/") .setAuth(basic(adminUser.getUsername(), adminUser.getPassword())) 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 5ca4b9c1ab..d57c16fabf 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 @@ -106,7 +106,8 @@ public class RMRolesAndActionsAPI extends BaseAPI public Set getConfiguredRoles(String adminUser, String adminPassword) { // Using "is=true" includes the in-place readers and writers. - JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject("data"); + final JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject + ("data"); return jsonObject.toMap().keySet(); } @@ -120,7 +121,8 @@ public class RMRolesAndActionsAPI extends BaseAPI */ public Set getCapabilitiesForRole(String adminUser, String adminPassword, String role) { - JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject("data"); + final JSONObject jsonObject = doGetRequest(adminUser, adminPassword, RM_ROLES + "?is=true").getJSONObject + ("data"); assertTrue("Could not find role '" + role + "' in " + jsonObject.keySet(), jsonObject.has(role)); return jsonObject.getJSONObject(role).getJSONObject("capabilities").keySet(); } @@ -136,10 +138,10 @@ public class RMRolesAndActionsAPI extends BaseAPI */ public void createRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set capabilities) { - JSONObject requestBody = new JSONObject(); + final JSONObject requestBody = new JSONObject(); requestBody.put("name", roleName); requestBody.put("displayLabel", roleDisplayLabel); - JSONArray capabilitiesArray = new JSONArray(); + final JSONArray capabilitiesArray = new JSONArray(); capabilities.forEach(capabilitiesArray::put); requestBody.put("capabilities", capabilitiesArray); doPostJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES); @@ -156,10 +158,10 @@ public class RMRolesAndActionsAPI extends BaseAPI */ public void updateRole(String adminUser, String adminPassword, String roleName, String roleDisplayLabel, Set capabilities) { - JSONObject requestBody = new JSONObject(); + final JSONObject requestBody = new JSONObject(); requestBody.put("name", roleName); requestBody.put("displayLabel", roleDisplayLabel); - JSONArray capabilitiesArray = new JSONArray(); + final JSONArray capabilitiesArray = new JSONArray(); capabilities.forEach(capabilitiesArray::put); requestBody.put("capabilities", capabilitiesArray); doPutJsonRequest(adminUser, adminPassword, HttpStatus.SC_OK, requestBody, RM_ROLES_ROLE, roleName); @@ -175,7 +177,7 @@ public class RMRolesAndActionsAPI extends BaseAPI public void deleteRole(String adminUser, String adminPassword, String roleName) { doDeleteRequest(adminUser, adminPassword, MessageFormat.format(RM_ROLES_ROLE, "{0}", roleName)); - boolean success = !getConfiguredRoles(adminUser, adminPassword).contains(roleName); + final boolean success = !getConfiguredRoles(adminUser, adminPassword).contains(roleName); assertTrue("Failed to delete role " + roleName + " with " + adminUser, success); } @@ -206,8 +208,8 @@ public class RMRolesAndActionsAPI extends BaseAPI */ public void assignRoleToUser(String adminUser, String adminPassword, String userName, String role) { - AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String reqURL = MessageFormat.format( + final AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); + final String reqURL = MessageFormat.format( RM_ROLES_AUTHORITIES, client.getApiUrl(), role, @@ -456,7 +458,7 @@ public class RMRolesAndActionsAPI extends BaseAPI return null; } // retrieve the Holds container nodeRef - String parentNodeRef = getItemNodeRef(user, password, "/Holds"); + final String parentNodeRef = getItemNodeRef(user, password, "/Holds"); final JSONObject requestParams = new JSONObject(); requestParams.put("alf_destination", getNodeRefSpacesStore() + parentNodeRef); diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java index a5bdff72c0..c37dcc8541 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/service/RoleService.java @@ -86,7 +86,7 @@ public class RoleService */ public void addCapabilitiesToRole(UserRoles role, Set capabilities) { - Set roleCapabilities = new HashSet<>(getRoleCapabilities(role.roleId)); + final Set roleCapabilities = new HashSet<>(getRoleCapabilities(role.roleId)); roleCapabilities.addAll(capabilities); getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(), @@ -101,7 +101,7 @@ public class RoleService */ public void removeCapabilitiesFromRole(UserRoles role, Set capabilities) { - Set roleCapabilities = getRoleCapabilities(role.roleId); + final Set roleCapabilities = getRoleCapabilities(role.roleId); roleCapabilities.removeAll(capabilities); getRmRolesAndActionsAPI().updateRole(getDataUser().getAdminUser().getUsername(), getDataUser().getAdminUser().getPassword(), role.roleId, role.displayName, roleCapabilities);