From c26e0f8c3710befd95fbe612302e0f5226180ba9 Mon Sep 17 00:00:00 2001 From: jcule Date: Sat, 9 Sep 2017 10:05:54 +0100 Subject: [PATCH 01/12] RM-5416: API Tests for REST API for Folder Classification --- .../src/main/java/org/alfresco/rest/core/v0/BaseAPI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 1e88d4be45..52f46d15ea 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -324,7 +324,9 @@ public abstract class BaseAPI client.getApiUrl(), urlTemplateParams); client.close(); - + LOGGER.debug("REQUEST ***** ", requestUrl); + System.out.println("REQUEST ***** " + requestUrl); + System.out.println("REQUEST PARAMS ***** " + requestParams); try { return doRequest(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); From 1173c16d381859162a16488179f70803929e1ab0 Mon Sep 17 00:00:00 2001 From: jcule Date: Sat, 9 Sep 2017 11:44:01 +0100 Subject: [PATCH 02/12] RM-5416: API Tests for REST API for Folder Classification --- .../org/alfresco/rest/core/v0/BaseAPI.java | 192 ++++++------------ 1 file changed, 66 insertions(+), 126 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 52f46d15ea..93889e099e 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -24,6 +24,7 @@ * along with Alfresco. If not, see . * #L% */ + package org.alfresco.rest.core.v0; import java.io.IOException; @@ -83,12 +84,12 @@ public abstract class BaseAPI @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; - @Autowired + @Autowired private ContentService contentService; private static final String NODE_REF_WORKSPACE_SPACES_STORE = "workspace://SpacesStore/"; private static final String FILE_PLAN_PATH = "Sites/rm/documentLibrary"; - + /** * Helper method to extract list of properties values from result. * @@ -117,13 +118,15 @@ public abstract class BaseAPI } /** - * Helper method to extract property values from request result and put them in map as a list that corresponds to a unique property value. + * Helper method to extract property values from request result and put them in map as a list that corresponds to a + * unique property value. * * @param requestResult the request response * @return a map containing information about multiple properties values that correspond to a unique one * @throws RuntimeException for malformed response */ - protected Map> getPropertyValuesByUniquePropertyValue(JSONObject requestResult, String uniqueProperty, List otherProperties) + protected Map> getPropertyValuesByUniquePropertyValue(JSONObject requestResult, + String uniqueProperty, List otherProperties) { Map> valuesByUniqueProperty = new HashMap<>(); try @@ -154,9 +157,8 @@ public abstract class BaseAPI * * @param username the username * @param password the password - * @param path the path to the container eg. in case of a category it would be the category name, - * in case of a folder it would be /categoryName/folderName - * when trying to get File Plan, the path would be "" + * @param path the path to the container eg. in case of a category it would be the category name, in case of a + * folder it would be /categoryName/folderName when trying to get File Plan, the path would be "" * @return the container nodeRef */ public String getItemNodeRef(String username, String password, String path) @@ -169,7 +171,7 @@ public abstract class BaseAPI * * @param username the user's username * @param password its password - * @param path the object path + * @param path the object path * @return the object in case it exists, null if its does not exist */ protected CmisObject getObjectByPath(String username, String password, String path) @@ -178,7 +180,8 @@ public abstract class BaseAPI try { object = contentService.getCMISSession(username, password).getObjectByPath(path); - } catch (CmisObjectNotFoundException notFoundError) + } + catch (CmisObjectNotFoundException notFoundError) { return null; } @@ -193,23 +196,20 @@ public abstract class BaseAPI * @param parameters if the request has parameters * @return result object (see API reference for more details), null for any errors */ - protected JSONObject facetedRequest(String username, String password, List parameters, String requestURI) + protected JSONObject facetedRequest(String username, String password, List parameters, + String requestURI) { String requestURL; AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); if (parameters == null || parameters.isEmpty()) { - requestURL = MessageFormat.format( - requestURI, - client.getAlfrescoUrl()); + requestURL = MessageFormat.format(requestURI, client.getAlfrescoUrl()); } else { - requestURL = MessageFormat.format( - requestURI, - client.getAlfrescoUrl(), - URLEncodedUtils.format(parameters, "UTF-8")); + requestURL = MessageFormat.format(requestURI, client.getAlfrescoUrl(), + URLEncodedUtils.format(parameters, "UTF-8")); } client.close(); return doGetRequest(username, password, requestURL); @@ -217,21 +217,17 @@ public abstract class BaseAPI /** * Helper method for GET requests + * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doGetRequest(String adminUser, - String adminPassword, - String urlTemplate, - String ... urlTemplateParams) + protected JSONObject doGetRequest(String adminUser, String adminPassword, String urlTemplate, + String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format( - urlTemplate, - client.getApiUrl(), - urlTemplateParams); + String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); client.close(); try @@ -246,21 +242,17 @@ public abstract class BaseAPI /** * Helper method for Delete requests + * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doDeleteRequest(String adminUser, - String adminPassword, - String urlTemplate, - String ... urlTemplateParams) + protected JSONObject doDeleteRequest(String adminUser, String adminPassword, String urlTemplate, + String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format( - urlTemplate, - client.getApiUrl(), - urlTemplateParams); + String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); client.close(); try @@ -275,23 +267,18 @@ public abstract class BaseAPI /** * Helper method for PUT requests + * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doPutRequest(String adminUser, - String adminPassword, - JSONObject requestParams, - String urlTemplate, - String ... urlTemplateParams) + protected JSONObject doPutRequest(String adminUser, String adminPassword, JSONObject requestParams, + String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format( - urlTemplate, - client.getApiUrl(), - urlTemplateParams); + String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); client.close(); try @@ -306,27 +293,20 @@ public abstract class BaseAPI /** * Helper method for POST requests + * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doPostRequest(String adminUser, - String adminPassword, - JSONObject requestParams, - String urlTemplate, - String ... urlTemplateParams) + protected JSONObject doPostRequest(String adminUser, String adminPassword, JSONObject requestParams, + String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format( - urlTemplate, - client.getApiUrl(), - urlTemplateParams); + String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); client.close(); - LOGGER.debug("REQUEST ***** ", requestUrl); - System.out.println("REQUEST ***** " + requestUrl); - System.out.println("REQUEST PARAMS ***** " + requestParams); + try { return doRequest(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); @@ -340,23 +320,17 @@ public abstract class BaseAPI /** * Helper method for POST requests * - * @param adminUser user with administrative privileges - * @param adminPassword password for adminUser - * @param requestParams zero or more endpoint specific request parameters - * @param urlTemplate request URL template + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected boolean doPostJsonRequest(String adminUser, - String adminPassword, - JSONObject requestParams, - String urlTemplate, - String... urlTemplateParams) + protected boolean doPostJsonRequest(String adminUser, String adminPassword, JSONObject requestParams, + String urlTemplate, String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format( - urlTemplate, - client.getApiUrl(), - urlTemplateParams); + String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); client.close(); try @@ -371,6 +345,7 @@ public abstract class BaseAPI /** * Helper method for handling generic HTTP requests + * * @param requestType request type (a subclass of {@link HttpRequestBase}) * @param requestUrl URL the request is to be sent to * @param adminUser user with administrative privileges @@ -380,12 +355,8 @@ public abstract class BaseAPI * @throws IllegalAccessException for invalid requestType * @throws InstantiationException for invalid requestType */ - private JSONObject doRequest( - Class requestType, - String requestUrl, - String adminUser, - String adminPassword, - JSONObject requestParams) throws InstantiationException, IllegalAccessException + private JSONObject doRequest(Class requestType, String requestUrl, String adminUser, + String adminPassword, JSONObject requestParams) throws InstantiationException, IllegalAccessException { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); T request = requestType.newInstance(); @@ -426,7 +397,7 @@ public abstract class BaseAPI case HttpStatus.SC_INTERNAL_SERVER_ERROR: case HttpStatus.SC_BAD_REQUEST: - if (responseBody != null && responseBody.has(EXCEPTION_KEY)) + if (responseBody != null && responseBody.has(EXCEPTION_KEY)) { LOGGER.error("Request failed: " + responseBody.getString(EXCEPTION_KEY)); returnValues = responseBody; @@ -458,12 +429,8 @@ public abstract class BaseAPI return returnValues; } - private boolean doRequestJson( - Class requestType, - String requestUrl, - String adminUser, - String adminPassword, - JSONObject requestParams) throws InstantiationException, IllegalAccessException + private boolean doRequestJson(Class requestType, String requestUrl, String adminUser, + String adminPassword, JSONObject requestParams) throws InstantiationException, IllegalAccessException { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); T request = requestType.newInstance(); @@ -478,7 +445,8 @@ public abstract class BaseAPI ((HttpEntityEnclosingRequestBase) request).setEntity(new StringEntity(requestParams.toString())); } - return client.execute(adminUser, adminPassword, request).getStatusLine().getStatusCode() == HttpStatus.SC_OK; + return client.execute(adminUser, adminPassword, request).getStatusLine() + .getStatusCode() == HttpStatus.SC_OK; } catch (UnsupportedEncodingException | URISyntaxException error1) { @@ -497,36 +465,16 @@ public abstract class BaseAPI } /** - * Used to set RM items properties - * including records, categories and folders + * Used to set RM items properties including records, categories and folders */ public enum RMProperty { - NAME, - TITLE, - CONTENT, - DESCRIPTION, - AUTHOR, - PHYSICAL_SIZE, - NUMBER_OF_COPIES, - STORAGE_LOCATION, - SHELF, - BOX, - FILE, + NAME, TITLE, CONTENT, DESCRIPTION, AUTHOR, PHYSICAL_SIZE, NUMBER_OF_COPIES, STORAGE_LOCATION, SHELF, BOX, FILE, } public enum RETENTION_SCHEDULE { - NAME, - DESCRIPTION, - RETENTION_AUTHORITY, - RETENTION_INSTRUCTIONS, - RETENTION_PERIOD, - RETENTION_LOCATION, - RETENTION_PERIOD_PROPERTY, - RETENTION_GHOST, - RETENTION_ELIGIBLE_FIRST_EVENT, - RETENTION_EVENTS, + NAME, DESCRIPTION, RETENTION_AUTHORITY, RETENTION_INSTRUCTIONS, RETENTION_PERIOD, RETENTION_LOCATION, RETENTION_PERIOD_PROPERTY, RETENTION_GHOST, RETENTION_ELIGIBLE_FIRST_EVENT, RETENTION_EVENTS, } @@ -535,11 +483,8 @@ public abstract class BaseAPI */ public enum RM_ACTIONS { - EDIT_DISPOSITION_DATE("editDispositionActionAsOfDate"), - CUT_OFF("cutoff"), - UNDO_CUT_OFF("undoCutoff"), - TRANSFER("transfer"), - DESTROY("destroy"); + EDIT_DISPOSITION_DATE("editDispositionActionAsOfDate"), CUT_OFF("cutoff"), UNDO_CUT_OFF("undoCutoff"), TRANSFER( + "transfer"), DESTROY("destroy"); String action; private RM_ACTIONS(String action) @@ -555,39 +500,34 @@ public abstract class BaseAPI public enum PermissionType { - SET_READ, - REMOVE_READ, - SET_READ_AND_FILE, - REMOVE_READ_AND_FILE, + SET_READ, REMOVE_READ, SET_READ_AND_FILE, REMOVE_READ_AND_FILE, } /** * Util to return the property value from a map * * @param properties the map containing properties - * @param property to get value for + * @param property to get value for * @return the property value */ public > String getPropertyValue(Map properties, Enum property) { String value = properties.get(property); - if (value == null) - { - return ""; - } + if (value == null) { return ""; } return value; } /** * Retrieves the property value and decides if that gets to be added to the request * - * @param requestParams the request parameters + * @param requestParams the request parameters * @param propertyRequestValue the property name in the request, eg. "prop_cm_name" - * @param itemProperties map of item's properties values - * @param property the property in the property map to check value for + * @param itemProperties map of item's properties values + * @param property the property in the property map to check value for * @return the json object used in request with the property with its value added if that is not null or empty */ - protected > JSONObject addPropertyToRequest(JSONObject requestParams, String propertyRequestValue, Map itemProperties, Enum property) throws JSONException + protected > JSONObject addPropertyToRequest(JSONObject requestParams, String propertyRequestValue, + Map itemProperties, Enum property) throws JSONException { String propertyValue = getPropertyValue(itemProperties, property); @@ -603,9 +543,9 @@ public abstract class BaseAPI * * @param username the username with whom the delete is performed * @param password the user's password - * @param itemPath the path to the item eg. in case of a category it would be the "/" + category name, - * in case of a folder or subCategory it would be /categoryName/folderName or /categoryName/subCategoryName/ - * in case of a record /categoryName/folderName/recordName + * @param itemPath the path to the item eg. in case of a category it would be the "/" + category name, in case of a + * folder or subCategory it would be /categoryName/folderName or /categoryName/subCategoryName/ in case + * of a record /categoryName/folderName/recordName * @return true if the deletion has been successful */ protected boolean deleteItem(String username, String password, String itemPath) @@ -618,7 +558,7 @@ public abstract class BaseAPI return getObjectByPath(username, password, itemPath) == null; } - /** + /** * Retrieve the node ref spaces store value * * @return node ref spaces store From f51852e1efb965107c014b288fb35ebe4b0b5fba Mon Sep 17 00:00:00 2001 From: jcule Date: Sun, 17 Sep 2017 10:56:19 +0100 Subject: [PATCH 03/12] RM-5416: REST API Tests for Folder Classification - added tests for classified folders search --- .../java/org/alfresco/rest/v0/SearchAPI.java | 83 ++++++++++++------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 7bcfff7d48..10ef7062bf 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -24,13 +24,17 @@ * along with Alfresco. If not, see . * #L% */ + package org.alfresco.rest.v0; +import java.io.IOException; +import java.nio.charset.Charset; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.alfresco.dataprep.AlfrescoHttpClient; import org.alfresco.dataprep.AlfrescoHttpClientFactory; import org.alfresco.rest.core.v0.BaseAPI; import org.apache.http.NameValuePair; @@ -49,8 +53,13 @@ import org.springframework.stereotype.Component; @Component public class SearchAPI extends BaseAPI { + /** http client factory */ - @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; + @Autowired + private AlfrescoHttpClientFactory alfrescoHttpClientFactory; + + /** search API endpoint */ + private static final String SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/search?{1}"; /** faceted search API endpoint */ private static final String FACETED_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/faceted/rmsearch?{1}"; @@ -59,28 +68,26 @@ public class SearchAPI extends BaseAPI private static final String RM_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/{1}?{2}"; /** RM document search filters */ - private static final String RM_DEFAULT_RECORD_FILTERS = - "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; + private static final String RM_DEFAULT_RECORD_FILTERS = "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; /** * Perform search request on search endpoint as a user. *

* This method is applicable only to endpoints that support HTTP GET requests and return JSON body as response. + * * @param searchEndpoint * @param searchUser * @param searchPassword * @return search results as a {@link JSONObject}, please refer to API documentation for details */ - private JSONObject doSearch( - String searchEndpoint, - String searchUser, - String searchPassword) + private JSONObject doSearch(String searchEndpoint, String searchUser, String searchPassword) { - return facetedRequest(searchUser, searchPassword, null, searchEndpoint); + return facetedRequest(searchUser, searchPassword, null, searchEndpoint); } /** * Generic rm search. + * * @param username * @param password * @param site @@ -88,45 +95,36 @@ public class SearchAPI extends BaseAPI * @param filters * @return search results (see API reference for more details), null for any errors */ - public JSONObject rmSearch( - String username, - String password, - String site, - String query, - String filters) + public JSONObject rmSearch(String username, String password, String site, String query, String filters) { List searchParameters = new ArrayList(); searchParameters.add(new BasicNameValuePair("query", query)); searchParameters.add(new BasicNameValuePair("filters", filters)); - String requestURL = MessageFormat.format( - RM_SEARCH_ENDPOINT, - alfrescoHttpClientFactory.getObject().getAlfrescoUrl(), - (site != null) ? site : RM_SITE_ID, - URLEncodedUtils.format(searchParameters, "UTF-8")); + String requestURL = MessageFormat.format(RM_SEARCH_ENDPOINT, + alfrescoHttpClientFactory.getObject().getAlfrescoUrl(), (site != null) ? site : RM_SITE_ID, + URLEncodedUtils.format(searchParameters, "UTF-8")); return doSearch(requestURL, username, password); } /** - * Search as a user for records on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS - *
+ * Search as a user for records on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS
* If more fine-grained control of search parameters is required, use rmSearch() directly. + * * @param username * @param password * @param query * @return list of record names */ - public List searchForRecordsAsUser( - String username, - String password, - String query) + public List searchForRecordsAsUser(String username, String password, String query) { return getItemNames(rmSearch(username, password, "rm", query, RM_DEFAULT_RECORD_FILTERS)); } /** * Generic faceted search. + * * @param username * @param password * @param parameters @@ -139,6 +137,7 @@ public class SearchAPI extends BaseAPI /** * Execute faceted search for term. + * * @param searchUser * @param searchPassword * @param searchTerm @@ -146,14 +145,12 @@ public class SearchAPI extends BaseAPI */ public JSONObject facetedSearchForTerm(String searchUser, String searchPassword, String searchTerm) { - return facetedSearch( - searchUser, - searchPassword, - Arrays.asList(new BasicNameValuePair("term", searchTerm))); + return facetedSearch(searchUser, searchPassword, Arrays.asList(new BasicNameValuePair("term", searchTerm))); } /** * Helper method to search for documents as a user using faceted search. + * * @param username to search as * @param password for username * @param term search term @@ -161,11 +158,39 @@ public class SearchAPI extends BaseAPI */ public List searchForDocumentsAsUser(String username, String password, String term) { + return getItemNames(facetedSearchForTerm(username, password, term)); } + /** + * Helper method to search for documents or folders as a user using search. + * + * @param username to search as + * @param password for username + * @param term search term + * @return list of document names found + * @throws IOException + */ + public List searchForContentAsUser(String username, String password, String... searchParameters) + throws Exception + { + AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); + String requestURL = MessageFormat.format(SEARCH_ENDPOINT, client.getAlfrescoUrl()); + + List nameValuePairs = new ArrayList(); + for (String searchParameter : searchParameters) + { + nameValuePairs.add(new BasicNameValuePair("term", searchParameter)); + } + requestURL = MessageFormat.format(SEARCH_ENDPOINT, client.getAlfrescoUrl(), + URLEncodedUtils.format(nameValuePairs, Charset.forName("UTF-8"))); + Thread.sleep(20000); + return getItemNames(doGetRequest(username, password, requestURL)); + } + /** * Helper method to extract list of names from search result. + * * @param searchResult * @return list of document or record names in search result * @throws RuntimeException for malformed search response From 995b6a7911426e25267d0de4727d26537c49cea3 Mon Sep 17 00:00:00 2001 From: jcule Date: Sun, 17 Sep 2017 18:25:33 +0100 Subject: [PATCH 04/12] RM-5416: REST API Tests for Folder Classification - added tests for classified folders search --- .../src/main/java/org/alfresco/rest/v0/SearchAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 10ef7062bf..07b6a7c3b6 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -184,7 +184,7 @@ public class SearchAPI extends BaseAPI } requestURL = MessageFormat.format(SEARCH_ENDPOINT, client.getAlfrescoUrl(), URLEncodedUtils.format(nameValuePairs, Charset.forName("UTF-8"))); - Thread.sleep(20000); + Thread.sleep(15000); return getItemNames(doGetRequest(username, password, requestURL)); } From dd61bc3f8bb5fbe956b3864034528c84acd696dc Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 18 Sep 2017 21:09:13 +0300 Subject: [PATCH 05/12] RM-5416 - api tests for searching folders, record folders and record categories --- .../rm/community/base/BaseRMRestTest.java | 88 +++++++++++++++++++ 1 file changed, 88 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 38d4b2959d..d44649ba84 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,15 +33,22 @@ import static org.alfresco.rest.rm.community.base.TestData.RECORD_CATEGORY_TITLE 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.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.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; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; +import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; +import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_ADMIN; +import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryChildModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel; +import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile; import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.CREATED; @@ -51,6 +58,7 @@ import static org.testng.Assert.assertTrue; import java.util.List; +import org.alfresco.dataprep.ContentService; import org.alfresco.rest.RestTest; import org.alfresco.rest.core.RestAPIFactory; import org.alfresco.rest.rm.community.model.fileplan.FilePlan; @@ -65,8 +73,12 @@ import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainer; import org.alfresco.rest.rm.community.model.unfiledcontainer.UnfiledContainerChild; 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; import org.alfresco.rest.rm.community.requests.gscore.api.RecordsAPI; +import org.alfresco.rest.v0.RMRolesAndActionsAPI; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -92,6 +104,14 @@ public class BaseRMRestTest extends RestTest @Getter (value = PROTECTED) private DataUser dataUser; + @Autowired + @Getter (value = PROTECTED) + private ContentService contentService; + + @Autowired + @Getter (value = PROTECTED) + private RMRolesAndActionsAPI rmRolesAndActionsAPI; + /** * Asserts the given status code * @@ -468,4 +488,72 @@ public class BaseRMRestTest extends RestTest { return getFilePlanAsUser(getAdminUser(), componentId); } + + /** + * Recursively delete a folder + * + * @param siteModel + * @param folder + */ + public void deleteFolder(SiteModel siteModel, FolderModel folder) + { + contentService.deleteTree(getAdminUser().getUsername(), + getAdminUser().getPassword(), + siteModel.getId(), + folder.getName()); + } + + /** + * Create an electronic record + * + * @param parentId the id of the parent + * @param name the name of the record + * @return the created record + * @throws Exception + */ + public Record createElectronicRecord(String parentId, String name) throws Exception + { + RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(); + Record recordModel = Record.builder() + .name(name) + .nodeType(CONTENT_TYPE) + .build(); + return recordFolderAPI.createRecord(recordModel, parentId, getFile(IMAGE_FILE)); + } + + /** + * Delete a record folder + * + * @param recordFolderId the id of the record folder to delete + */ + public void deleteRecordFolder(String recordFolderId) + { + RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(); + recordFolderAPI.deleteRecordFolder(recordFolderId); + } + + /** + * Delete a record category + * + * @param recordCategoryId the id of the record category to delete + */ + public void deleteRecordCategory(String recordCategoryId) + { + RecordCategoryAPI recordCategoryAPI = restAPIFactory.getRecordCategoryAPI(); + recordCategoryAPI.deleteRecordCategory(recordCategoryId); + } + + /** + * Assign filling permission on a record category and give the user RM_USER role + * + * @param user the user to assign the permission to + * @param categoryId the id of the category to assign permissions for + * @throws Exception + */ + public void assignFillingPermissionsOnCategory(UserModel user, String categoryId) throws Exception + { + getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, PERMISSION_FILING); + rmRolesAndActionsAPI.assignUserToRole(dataUser.getAdminUser().getUsername(), + dataUser.getAdminUser().getPassword(), user.getUsername(), ROLE_RM_USER); + } } From 57ec2362f34ee757d7e2d9100ffc02fbc532b3c8 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 18 Sep 2017 21:25:27 +0300 Subject: [PATCH 06/12] RM-5416 - revert auto formatting of BaseAPI class --- .../org/alfresco/rest/core/v0/BaseAPI.java | 192 ++++++++++++------ 1 file changed, 126 insertions(+), 66 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 93889e099e..52f46d15ea 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -24,7 +24,6 @@ * along with Alfresco. If not, see . * #L% */ - package org.alfresco.rest.core.v0; import java.io.IOException; @@ -84,12 +83,12 @@ public abstract class BaseAPI @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; - @Autowired + @Autowired private ContentService contentService; private static final String NODE_REF_WORKSPACE_SPACES_STORE = "workspace://SpacesStore/"; private static final String FILE_PLAN_PATH = "Sites/rm/documentLibrary"; - + /** * Helper method to extract list of properties values from result. * @@ -118,15 +117,13 @@ public abstract class BaseAPI } /** - * Helper method to extract property values from request result and put them in map as a list that corresponds to a - * unique property value. + * Helper method to extract property values from request result and put them in map as a list that corresponds to a unique property value. * * @param requestResult the request response * @return a map containing information about multiple properties values that correspond to a unique one * @throws RuntimeException for malformed response */ - protected Map> getPropertyValuesByUniquePropertyValue(JSONObject requestResult, - String uniqueProperty, List otherProperties) + protected Map> getPropertyValuesByUniquePropertyValue(JSONObject requestResult, String uniqueProperty, List otherProperties) { Map> valuesByUniqueProperty = new HashMap<>(); try @@ -157,8 +154,9 @@ public abstract class BaseAPI * * @param username the username * @param password the password - * @param path the path to the container eg. in case of a category it would be the category name, in case of a - * folder it would be /categoryName/folderName when trying to get File Plan, the path would be "" + * @param path the path to the container eg. in case of a category it would be the category name, + * in case of a folder it would be /categoryName/folderName + * when trying to get File Plan, the path would be "" * @return the container nodeRef */ public String getItemNodeRef(String username, String password, String path) @@ -171,7 +169,7 @@ public abstract class BaseAPI * * @param username the user's username * @param password its password - * @param path the object path + * @param path the object path * @return the object in case it exists, null if its does not exist */ protected CmisObject getObjectByPath(String username, String password, String path) @@ -180,8 +178,7 @@ public abstract class BaseAPI try { object = contentService.getCMISSession(username, password).getObjectByPath(path); - } - catch (CmisObjectNotFoundException notFoundError) + } catch (CmisObjectNotFoundException notFoundError) { return null; } @@ -196,20 +193,23 @@ public abstract class BaseAPI * @param parameters if the request has parameters * @return result object (see API reference for more details), null for any errors */ - protected JSONObject facetedRequest(String username, String password, List parameters, - String requestURI) + protected JSONObject facetedRequest(String username, String password, List parameters, String requestURI) { String requestURL; AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); if (parameters == null || parameters.isEmpty()) { - requestURL = MessageFormat.format(requestURI, client.getAlfrescoUrl()); + requestURL = MessageFormat.format( + requestURI, + client.getAlfrescoUrl()); } else { - requestURL = MessageFormat.format(requestURI, client.getAlfrescoUrl(), - URLEncodedUtils.format(parameters, "UTF-8")); + requestURL = MessageFormat.format( + requestURI, + client.getAlfrescoUrl(), + URLEncodedUtils.format(parameters, "UTF-8")); } client.close(); return doGetRequest(username, password, requestURL); @@ -217,17 +217,21 @@ public abstract class BaseAPI /** * Helper method for GET requests - * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doGetRequest(String adminUser, String adminPassword, String urlTemplate, - String... urlTemplateParams) + protected JSONObject doGetRequest(String adminUser, + String adminPassword, + String urlTemplate, + String ... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); + String requestUrl = MessageFormat.format( + urlTemplate, + client.getApiUrl(), + urlTemplateParams); client.close(); try @@ -242,17 +246,21 @@ public abstract class BaseAPI /** * Helper method for Delete requests - * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doDeleteRequest(String adminUser, String adminPassword, String urlTemplate, - String... urlTemplateParams) + protected JSONObject doDeleteRequest(String adminUser, + String adminPassword, + String urlTemplate, + String ... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); + String requestUrl = MessageFormat.format( + urlTemplate, + client.getApiUrl(), + urlTemplateParams); client.close(); try @@ -267,18 +275,23 @@ public abstract class BaseAPI /** * Helper method for PUT requests - * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doPutRequest(String adminUser, String adminPassword, JSONObject requestParams, - String urlTemplate, String... urlTemplateParams) + protected JSONObject doPutRequest(String adminUser, + String adminPassword, + JSONObject requestParams, + String urlTemplate, + String ... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); + String requestUrl = MessageFormat.format( + urlTemplate, + client.getApiUrl(), + urlTemplateParams); client.close(); try @@ -293,20 +306,27 @@ public abstract class BaseAPI /** * Helper method for POST requests - * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param requestParams zero or more endpoint specific request parameters * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected JSONObject doPostRequest(String adminUser, String adminPassword, JSONObject requestParams, - String urlTemplate, String... urlTemplateParams) + protected JSONObject doPostRequest(String adminUser, + String adminPassword, + JSONObject requestParams, + String urlTemplate, + String ... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); + String requestUrl = MessageFormat.format( + urlTemplate, + client.getApiUrl(), + urlTemplateParams); client.close(); - + LOGGER.debug("REQUEST ***** ", requestUrl); + System.out.println("REQUEST ***** " + requestUrl); + System.out.println("REQUEST PARAMS ***** " + requestParams); try { return doRequest(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); @@ -320,17 +340,23 @@ public abstract class BaseAPI /** * Helper method for POST requests * - * @param adminUser user with administrative privileges - * @param adminPassword password for adminUser - * @param requestParams zero or more endpoint specific request parameters - * @param urlTemplate request URL template + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param requestParams zero or more endpoint specific request parameters + * @param urlTemplate request URL template * @param urlTemplateParams zero or more parameters used with urlTemplate */ - protected boolean doPostJsonRequest(String adminUser, String adminPassword, JSONObject requestParams, - String urlTemplate, String... urlTemplateParams) + protected boolean doPostJsonRequest(String adminUser, + String adminPassword, + JSONObject requestParams, + String urlTemplate, + String... urlTemplateParams) { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestUrl = MessageFormat.format(urlTemplate, client.getApiUrl(), urlTemplateParams); + String requestUrl = MessageFormat.format( + urlTemplate, + client.getApiUrl(), + urlTemplateParams); client.close(); try @@ -345,7 +371,6 @@ public abstract class BaseAPI /** * Helper method for handling generic HTTP requests - * * @param requestType request type (a subclass of {@link HttpRequestBase}) * @param requestUrl URL the request is to be sent to * @param adminUser user with administrative privileges @@ -355,8 +380,12 @@ public abstract class BaseAPI * @throws IllegalAccessException for invalid requestType * @throws InstantiationException for invalid requestType */ - private JSONObject doRequest(Class requestType, String requestUrl, String adminUser, - String adminPassword, JSONObject requestParams) throws InstantiationException, IllegalAccessException + private JSONObject doRequest( + Class requestType, + String requestUrl, + String adminUser, + String adminPassword, + JSONObject requestParams) throws InstantiationException, IllegalAccessException { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); T request = requestType.newInstance(); @@ -397,7 +426,7 @@ public abstract class BaseAPI case HttpStatus.SC_INTERNAL_SERVER_ERROR: case HttpStatus.SC_BAD_REQUEST: - if (responseBody != null && responseBody.has(EXCEPTION_KEY)) + if (responseBody != null && responseBody.has(EXCEPTION_KEY)) { LOGGER.error("Request failed: " + responseBody.getString(EXCEPTION_KEY)); returnValues = responseBody; @@ -429,8 +458,12 @@ public abstract class BaseAPI return returnValues; } - private boolean doRequestJson(Class requestType, String requestUrl, String adminUser, - String adminPassword, JSONObject requestParams) throws InstantiationException, IllegalAccessException + private boolean doRequestJson( + Class requestType, + String requestUrl, + String adminUser, + String adminPassword, + JSONObject requestParams) throws InstantiationException, IllegalAccessException { AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); T request = requestType.newInstance(); @@ -445,8 +478,7 @@ public abstract class BaseAPI ((HttpEntityEnclosingRequestBase) request).setEntity(new StringEntity(requestParams.toString())); } - return client.execute(adminUser, adminPassword, request).getStatusLine() - .getStatusCode() == HttpStatus.SC_OK; + return client.execute(adminUser, adminPassword, request).getStatusLine().getStatusCode() == HttpStatus.SC_OK; } catch (UnsupportedEncodingException | URISyntaxException error1) { @@ -465,16 +497,36 @@ public abstract class BaseAPI } /** - * Used to set RM items properties including records, categories and folders + * Used to set RM items properties + * including records, categories and folders */ public enum RMProperty { - NAME, TITLE, CONTENT, DESCRIPTION, AUTHOR, PHYSICAL_SIZE, NUMBER_OF_COPIES, STORAGE_LOCATION, SHELF, BOX, FILE, + NAME, + TITLE, + CONTENT, + DESCRIPTION, + AUTHOR, + PHYSICAL_SIZE, + NUMBER_OF_COPIES, + STORAGE_LOCATION, + SHELF, + BOX, + FILE, } public enum RETENTION_SCHEDULE { - NAME, DESCRIPTION, RETENTION_AUTHORITY, RETENTION_INSTRUCTIONS, RETENTION_PERIOD, RETENTION_LOCATION, RETENTION_PERIOD_PROPERTY, RETENTION_GHOST, RETENTION_ELIGIBLE_FIRST_EVENT, RETENTION_EVENTS, + NAME, + DESCRIPTION, + RETENTION_AUTHORITY, + RETENTION_INSTRUCTIONS, + RETENTION_PERIOD, + RETENTION_LOCATION, + RETENTION_PERIOD_PROPERTY, + RETENTION_GHOST, + RETENTION_ELIGIBLE_FIRST_EVENT, + RETENTION_EVENTS, } @@ -483,8 +535,11 @@ public abstract class BaseAPI */ public enum RM_ACTIONS { - EDIT_DISPOSITION_DATE("editDispositionActionAsOfDate"), CUT_OFF("cutoff"), UNDO_CUT_OFF("undoCutoff"), TRANSFER( - "transfer"), DESTROY("destroy"); + EDIT_DISPOSITION_DATE("editDispositionActionAsOfDate"), + CUT_OFF("cutoff"), + UNDO_CUT_OFF("undoCutoff"), + TRANSFER("transfer"), + DESTROY("destroy"); String action; private RM_ACTIONS(String action) @@ -500,34 +555,39 @@ public abstract class BaseAPI public enum PermissionType { - SET_READ, REMOVE_READ, SET_READ_AND_FILE, REMOVE_READ_AND_FILE, + SET_READ, + REMOVE_READ, + SET_READ_AND_FILE, + REMOVE_READ_AND_FILE, } /** * Util to return the property value from a map * * @param properties the map containing properties - * @param property to get value for + * @param property to get value for * @return the property value */ public > String getPropertyValue(Map properties, Enum property) { String value = properties.get(property); - if (value == null) { return ""; } + if (value == null) + { + return ""; + } return value; } /** * Retrieves the property value and decides if that gets to be added to the request * - * @param requestParams the request parameters + * @param requestParams the request parameters * @param propertyRequestValue the property name in the request, eg. "prop_cm_name" - * @param itemProperties map of item's properties values - * @param property the property in the property map to check value for + * @param itemProperties map of item's properties values + * @param property the property in the property map to check value for * @return the json object used in request with the property with its value added if that is not null or empty */ - protected > JSONObject addPropertyToRequest(JSONObject requestParams, String propertyRequestValue, - Map itemProperties, Enum property) throws JSONException + protected > JSONObject addPropertyToRequest(JSONObject requestParams, String propertyRequestValue, Map itemProperties, Enum property) throws JSONException { String propertyValue = getPropertyValue(itemProperties, property); @@ -543,9 +603,9 @@ public abstract class BaseAPI * * @param username the username with whom the delete is performed * @param password the user's password - * @param itemPath the path to the item eg. in case of a category it would be the "/" + category name, in case of a - * folder or subCategory it would be /categoryName/folderName or /categoryName/subCategoryName/ in case - * of a record /categoryName/folderName/recordName + * @param itemPath the path to the item eg. in case of a category it would be the "/" + category name, + * in case of a folder or subCategory it would be /categoryName/folderName or /categoryName/subCategoryName/ + * in case of a record /categoryName/folderName/recordName * @return true if the deletion has been successful */ protected boolean deleteItem(String username, String password, String itemPath) @@ -558,7 +618,7 @@ public abstract class BaseAPI return getObjectByPath(username, password, itemPath) == null; } - /** + /** * Retrieve the node ref spaces store value * * @return node ref spaces store From 2968872c0087ae77921abbf8de6741d09c52ff93 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 18 Sep 2017 21:27:53 +0300 Subject: [PATCH 07/12] RM-5416 - remove logging messages from BaseAPI class --- .../src/main/java/org/alfresco/rest/core/v0/BaseAPI.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java index 52f46d15ea..1e88d4be45 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/v0/BaseAPI.java @@ -324,9 +324,7 @@ public abstract class BaseAPI client.getApiUrl(), urlTemplateParams); client.close(); - LOGGER.debug("REQUEST ***** ", requestUrl); - System.out.println("REQUEST ***** " + requestUrl); - System.out.println("REQUEST PARAMS ***** " + requestParams); + try { return doRequest(HttpPost.class, requestUrl, adminUser, adminPassword, requestParams); From cf247b7c03a348f83948177be4c6ee0cb0b3d2ff Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 19 Sep 2017 09:06:27 +0300 Subject: [PATCH 08/12] RM-5416 - reverted auto formatting for SearchAPI --- .../java/org/alfresco/rest/v0/SearchAPI.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 07b6a7c3b6..2084a89370 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -68,26 +68,28 @@ public class SearchAPI extends BaseAPI private static final String RM_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/{1}?{2}"; /** RM document search filters */ - private static final String RM_DEFAULT_RECORD_FILTERS = "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; + private static final String RM_DEFAULT_RECORD_FILTERS = + "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; /** * Perform search request on search endpoint as a user. *

* This method is applicable only to endpoints that support HTTP GET requests and return JSON body as response. - * * @param searchEndpoint * @param searchUser * @param searchPassword * @return search results as a {@link JSONObject}, please refer to API documentation for details */ - private JSONObject doSearch(String searchEndpoint, String searchUser, String searchPassword) + private JSONObject doSearch( + String searchEndpoint, + String searchUser, + String searchPassword) { - return facetedRequest(searchUser, searchPassword, null, searchEndpoint); + return facetedRequest(searchUser, searchPassword, null, searchEndpoint); } /** * Generic rm search. - * * @param username * @param password * @param site @@ -95,36 +97,45 @@ public class SearchAPI extends BaseAPI * @param filters * @return search results (see API reference for more details), null for any errors */ - public JSONObject rmSearch(String username, String password, String site, String query, String filters) + public JSONObject rmSearch( + String username, + String password, + String site, + String query, + String filters) { List searchParameters = new ArrayList(); searchParameters.add(new BasicNameValuePair("query", query)); searchParameters.add(new BasicNameValuePair("filters", filters)); - String requestURL = MessageFormat.format(RM_SEARCH_ENDPOINT, - alfrescoHttpClientFactory.getObject().getAlfrescoUrl(), (site != null) ? site : RM_SITE_ID, - URLEncodedUtils.format(searchParameters, "UTF-8")); + String requestURL = MessageFormat.format( + RM_SEARCH_ENDPOINT, + alfrescoHttpClientFactory.getObject().getAlfrescoUrl(), + (site != null) ? site : RM_SITE_ID, + URLEncodedUtils.format(searchParameters, "UTF-8")); return doSearch(requestURL, username, password); } /** - * Search as a user for records on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS
+ * Search as a user for records on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS + *
* If more fine-grained control of search parameters is required, use rmSearch() directly. - * * @param username * @param password * @param query * @return list of record names */ - public List searchForRecordsAsUser(String username, String password, String query) + public List searchForRecordsAsUser( + String username, + String password, + String query) { return getItemNames(rmSearch(username, password, "rm", query, RM_DEFAULT_RECORD_FILTERS)); } /** * Generic faceted search. - * * @param username * @param password * @param parameters @@ -137,7 +148,6 @@ public class SearchAPI extends BaseAPI /** * Execute faceted search for term. - * * @param searchUser * @param searchPassword * @param searchTerm @@ -145,12 +155,14 @@ public class SearchAPI extends BaseAPI */ public JSONObject facetedSearchForTerm(String searchUser, String searchPassword, String searchTerm) { - return facetedSearch(searchUser, searchPassword, Arrays.asList(new BasicNameValuePair("term", searchTerm))); + return facetedSearch( + searchUser, + searchPassword, + Arrays.asList(new BasicNameValuePair("term", searchTerm))); } /** * Helper method to search for documents as a user using faceted search. - * * @param username to search as * @param password for username * @param term search term @@ -158,13 +170,12 @@ public class SearchAPI extends BaseAPI */ public List searchForDocumentsAsUser(String username, String password, String term) { - return getItemNames(facetedSearchForTerm(username, password, term)); } /** * Helper method to search for documents or folders as a user using search. - * + * * @param username to search as * @param password for username * @param term search term @@ -190,7 +201,6 @@ public class SearchAPI extends BaseAPI /** * Helper method to extract list of names from search result. - * * @param searchResult * @return list of document or record names in search result * @throws RuntimeException for malformed search response From a77f3571adbbea8303999badc1587a9c6ad32b62 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 19 Sep 2017 09:19:01 +0300 Subject: [PATCH 09/12] RM-5416 - reverted ClassificationAPI auto format --- .../src/main/java/org/alfresco/rest/v0/SearchAPI.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 2084a89370..236fbf058b 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -53,10 +53,8 @@ import org.springframework.stereotype.Component; @Component public class SearchAPI extends BaseAPI { - /** http client factory */ - @Autowired - private AlfrescoHttpClientFactory alfrescoHttpClientFactory; + @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; /** search API endpoint */ private static final String SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/search?{1}"; From cf3c343958f22ec771c28c472689e119aa0cc833 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 19 Sep 2017 11:02:29 +0300 Subject: [PATCH 10/12] RM-5416 - remove actual file from create electronic record method --- .../org/alfresco/rest/rm/community/base/BaseRMRestTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d44649ba84..83fddd7fe8 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 @@ -518,7 +518,7 @@ public class BaseRMRestTest extends RestTest .name(name) .nodeType(CONTENT_TYPE) .build(); - return recordFolderAPI.createRecord(recordModel, parentId, getFile(IMAGE_FILE)); + return recordFolderAPI.createRecord(recordModel, parentId); } /** From 51135a83c071d7837287ef79a86ddf1c2e843c57 Mon Sep 17 00:00:00 2001 From: jcule Date: Fri, 22 Sep 2017 10:04:30 +0100 Subject: [PATCH 11/12] RM-5416: REST API Tests for Folder Classification - removing the base class --- .../org/alfresco/rest/core/RMRestWrapper.java | 24 +++-- .../alfresco/rest/core/RestAPIFactory.java | 10 +- .../rm/community/base/BaseRMRestTest.java | 96 ++++++++++--------- 3 files changed, 75 insertions(+), 55 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java index 7a529e0633..f61fe3c751 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RMRestWrapper.java @@ -24,6 +24,7 @@ * along with Alfresco. If not, see . * #L% */ + package org.alfresco.rest.core; import com.jayway.restassured.builder.RequestSpecBuilder; @@ -34,6 +35,7 @@ import org.alfresco.rest.model.RestHtmlResponse; import org.alfresco.rest.model.RestSiteModel; import org.alfresco.rest.model.RestSiteModelsCollection; import org.alfresco.rest.requests.coreAPI.RestCoreAPI; +import org.alfresco.rest.requests.search.SearchAPI; import org.alfresco.rest.rm.community.requests.gscore.GSCoreAPI; import org.alfresco.utility.model.StatusModel; import org.alfresco.utility.model.UserModel; @@ -145,16 +147,24 @@ public class RMRestWrapper return restWrapper.withCoreAPI(); } + /** Get the Alfresco Search API. */ + public SearchAPI withSearchAPI() + { + return restWrapper.withSearchAPI(); + } + /** - * You can handle the request sent to server by calling this method. - * If for example you want to sent multipart form data you can use:

-     * restClient.configureRequestSpec()
-     *              .addMultiPart("filedata", Utility.getResourceTestDataFile("restapi-resource"))
-     *              .addFormParam("renditions", "doclib")
-     *              .addFormParam("autoRename", true);
+     * You can handle the request sent to server by calling this method. If for example you want to sent multipart form
+     * data you can use:
+     * 
+     * 
+     * restClient.configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("restapi-resource"))
+     *             .addFormParam("renditions", "doclib").addFormParam("autoRename", true);
      *
      * restClient.withCoreAPI().usingNode(ContentModel.my()).createNode();
-     * 
This will create the node using the multipart data defined. + *
+ * + * This will create the node using the multipart data defined. */ public RequestSpecBuilder configureRequestSpec() { diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index 710413fa33..bdbabe6eb2 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -24,6 +24,7 @@ * along with Alfresco. If not, see . * #L% */ + package org.alfresco.rest.core; import static lombok.AccessLevel.PROTECTED; @@ -32,6 +33,7 @@ import javax.annotation.Resource; import org.alfresco.rest.requests.Node; import org.alfresco.rest.requests.coreAPI.RestCoreAPI; +import org.alfresco.rest.requests.search.SearchAPI; import org.alfresco.rest.rm.community.requests.gscore.GSCoreAPI; import org.alfresco.rest.rm.community.requests.gscore.api.FilePlanAPI; import org.alfresco.rest.rm.community.requests.gscore.api.FilesAPI; @@ -65,7 +67,7 @@ import lombok.Setter; public class RestAPIFactory { @Autowired - @Getter (value = PROTECTED) + @Getter(value = PROTECTED) private DataUser dataUser; @Resource(name = "RMRestWrapper") @@ -85,6 +87,12 @@ public class RestAPIFactory return getRmRestWrapper().withCoreAPI(); } + private SearchAPI getSearchAPI(UserModel userModel) + { + getRmRestWrapper().authenticateUser(userModel != null ? userModel : getDataUser().getAdminUser()); + return getRmRestWrapper().withSearchAPI(); + } + public Node getNodeAPI(RepoTestModel model) throws Exception { return getCoreAPI(null).usingNode(model); 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 83fddd7fe8..5dee146514 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 @@ -24,6 +24,7 @@ * along with Alfresco. If not, see . * #L% */ + package org.alfresco.rest.rm.community.base; import static lombok.AccessLevel.PROTECTED; @@ -40,15 +41,11 @@ import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanCo import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_CONTAINER_TYPE; import static org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentType.UNFILED_RECORD_FOLDER_TYPE; import static org.alfresco.rest.rm.community.model.user.UserPermissions.PERMISSION_FILING; -import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_ADMIN; import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_USER; -import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.IMAGE_FILE; -import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createElectronicRecordModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryChildModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createRecordCategoryModel; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createTempFile; import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.createUnfiledContainerChildModel; -import static org.alfresco.rest.rm.community.utils.FilePlanComponentsUtil.getFile; import static org.alfresco.rest.rm.community.utils.RMSiteUtil.createStandardRMSiteModel; import static org.alfresco.utility.data.RandomData.getRandomAlphanumeric; import static org.springframework.http.HttpStatus.CREATED; @@ -97,19 +94,19 @@ import lombok.Getter; public class BaseRMRestTest extends RestTest { @Autowired - @Getter (value = PROTECTED) + @Getter(value = PROTECTED) private RestAPIFactory restAPIFactory; @Autowired - @Getter (value = PROTECTED) + @Getter(value = PROTECTED) private DataUser dataUser; @Autowired - @Getter (value = PROTECTED) + @Getter(value = PROTECTED) private ContentService contentService; @Autowired - @Getter (value = PROTECTED) + @Getter(value = PROTECTED) private RMRolesAndActionsAPI rmRolesAndActionsAPI; /** @@ -136,22 +133,22 @@ public class BaseRMRestTest extends RestTest @DataProvider(name = "validRootContainers") public String[][] getValidRootContainers() throws Exception { - return new String[][] - { - // an arbitrary record folder - { createCategoryFolderInFilePlan().getId(), RECORD_FOLDER_TYPE}, - // unfiled records root - { UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE}, - // an arbitrary unfiled records folder - { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(), UNFILED_RECORD_FOLDER_TYPE } - }; + return new String[][] { + // an arbitrary record folder + { createCategoryFolderInFilePlan().getId(), RECORD_FOLDER_TYPE }, + // unfiled records root + { UNFILED_RECORDS_CONTAINER_ALIAS, UNFILED_CONTAINER_TYPE }, + // an arbitrary unfiled records folder + { createUnfiledContainerChild(UNFILED_RECORDS_CONTAINER_ALIAS, + "Unfiled Folder " + getRandomAlphanumeric(), UNFILED_RECORD_FOLDER_TYPE).getId(), + UNFILED_RECORD_FOLDER_TYPE } }; } /** * @see org.alfresco.rest.RestTest#checkServerHealth() */ @Override - @BeforeClass (alwaysRun = true) + @BeforeClass(alwaysRun = true) public void checkServerHealth() throws Exception { // Create RM Site if not exist @@ -159,8 +156,7 @@ public class BaseRMRestTest extends RestTest } /** - * Helper method to create the RM Site via the POST request - * if the site doesn't exist + * Helper method to create the RM Site via the POST request if the site doesn't exist */ public void createRMSiteIfNotExists() throws Exception { @@ -224,10 +220,12 @@ public class BaseRMRestTest extends RestTest * @return The created category * @throws Exception on unsuccessful component creation */ - public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle) throws Exception + public RecordCategory createRootCategory(UserModel userModel, String categoryName, String categoryTitle) + throws Exception { RecordCategory recordCategoryModel = createRecordCategoryModel(categoryName, categoryTitle); - return getRestAPIFactory().getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, FILE_PLAN_ALIAS); + return getRestAPIFactory().getFilePlansAPI(userModel).createRootRecordCategory(recordCategoryModel, + FILE_PLAN_ALIAS); } /** @@ -240,10 +238,12 @@ public class BaseRMRestTest extends RestTest * @return The created {@link RecordCategoryChild} * @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)} */ - public RecordCategoryChild createRecordCategoryChild(UserModel user, String recordCategoryId, String name, String type) throws Exception + public RecordCategoryChild createRecordCategoryChild(UserModel user, String recordCategoryId, String name, + String type) throws Exception { RecordCategoryChild recordCategoryChildModel = createRecordCategoryChildModel(name, type); - return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordCategoryChildModel, recordCategoryId); + return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordCategoryChildModel, + recordCategoryId); } /** @@ -255,7 +255,8 @@ public class BaseRMRestTest extends RestTest * @return The created {@link RecordCategoryChild} * @throws Exception {@link RecordCategoryAPI#createRecordCategoryChild(RecordCategoryChild, String)} */ - public RecordCategoryChild createRecordCategoryChild(String recordCategoryId, String name, String type) throws Exception + public RecordCategoryChild createRecordCategoryChild(String recordCategoryId, String name, String type) + throws Exception { return createRecordCategoryChild(getAdminUser(), recordCategoryId, name, type); } @@ -298,7 +299,8 @@ public class BaseRMRestTest extends RestTest public RecordCategoryChild createFolder(UserModel user, String recordCategoryId, String name) throws Exception { RecordCategoryChild recordFolderModel = createRecordCategoryChildModel(name, RECORD_FOLDER_TYPE); - return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordFolderModel, recordCategoryId); + return getRestAPIFactory().getRecordCategoryAPI(user).createRecordCategoryChild(recordFolderModel, + recordCategoryId); } /** @@ -317,16 +319,18 @@ public class BaseRMRestTest extends RestTest /** * Helper method to create child unfiled record folder * - *@param user The user under whose privileges this structure is going to be created + * @param user The user under whose privileges this structure is going to be created * @param parentId The id of the parent folder * @param nodeType The child type * @return The created folder * @throws Exception on unsuccessful component creation */ - public UnfiledContainerChild createUnfiledRecordsFolderChild(UserModel user, String parentId, String childName, String nodeType) throws Exception + public UnfiledContainerChild createUnfiledRecordsFolderChild(UserModel user, String parentId, String childName, + String nodeType) throws Exception { UnfiledContainerChild childModel = createUnfiledContainerChildModel(childName, nodeType); - UnfiledContainerChild child = getRestAPIFactory().getUnfiledRecordFoldersAPI(user).createUnfiledRecordFolderChild(childModel, parentId); + UnfiledContainerChild child = getRestAPIFactory().getUnfiledRecordFoldersAPI(user) + .createUnfiledRecordFolderChild(childModel, parentId); assertStatusCode(CREATED); return child; @@ -340,7 +344,8 @@ public class BaseRMRestTest extends RestTest * @return The created folder * @throws Exception on unsuccessful component creation */ - public UnfiledContainerChild createUnfiledRecordsFolderChild(String parentId, String childName, String nodeType) throws Exception + public UnfiledContainerChild createUnfiledRecordsFolderChild(String parentId, String childName, String nodeType) + throws Exception { return createUnfiledRecordsFolderChild(getAdminUser(), parentId, childName, nodeType); } @@ -355,14 +360,16 @@ public class BaseRMRestTest extends RestTest * @return The created chid * @throws Exception on unsuccessful child creation */ - public UnfiledContainerChild createUnfiledContainerChild(UserModel user, String parentId, String childName, String nodeType) throws Exception + public UnfiledContainerChild createUnfiledContainerChild(UserModel user, String parentId, String childName, + String nodeType) throws Exception { UnfiledContainerChild child = null; UnfiledContainerChild childModel = createUnfiledContainerChildModel(childName, nodeType); if (FilePlanComponentType.CONTENT_TYPE.equals(nodeType)) { - child = getRestAPIFactory().getUnfiledContainersAPI(user).uploadRecord(childModel, parentId, createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME)); + child = getRestAPIFactory().getUnfiledContainersAPI(user).uploadRecord(childModel, parentId, + createTempFile(ELECTRONIC_RECORD_NAME, ELECTRONIC_RECORD_NAME)); } else { @@ -382,7 +389,8 @@ public class BaseRMRestTest extends RestTest * @return The created chid * @throws Exception on unsuccessful child creation */ - public UnfiledContainerChild createUnfiledContainerChild(String parentId, String childName, String nodeType) throws Exception + public UnfiledContainerChild createUnfiledContainerChild(String parentId, String childName, String nodeType) + throws Exception { return createUnfiledContainerChild(getAdminUser(), parentId, childName, nodeType); } @@ -397,11 +405,9 @@ public class BaseRMRestTest extends RestTest protected RecordFolder closeFolder(String folderId) throws Exception { RecordFolder recordFolderModel = RecordFolder.builder() - .properties(RecordFolderProperties.builder() - .isClosed(true) - .build()) - .build(); - RecordFolder updateRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolderModel, folderId); + .properties(RecordFolderProperties.builder().isClosed(true).build()).build(); + RecordFolder updateRecordFolder = getRestAPIFactory().getRecordFolderAPI().updateRecordFolder(recordFolderModel, + folderId); assertStatusCode(OK); return updateRecordFolder; @@ -497,10 +503,8 @@ public class BaseRMRestTest extends RestTest */ public void deleteFolder(SiteModel siteModel, FolderModel folder) { - contentService.deleteTree(getAdminUser().getUsername(), - getAdminUser().getPassword(), - siteModel.getId(), - folder.getName()); + contentService.deleteTree(getAdminUser().getUsername(), getAdminUser().getPassword(), siteModel.getId(), + folder.getName()); } /** @@ -514,10 +518,7 @@ public class BaseRMRestTest extends RestTest public Record createElectronicRecord(String parentId, String name) throws Exception { RecordFolderAPI recordFolderAPI = restAPIFactory.getRecordFolderAPI(); - Record recordModel = Record.builder() - .name(name) - .nodeType(CONTENT_TYPE) - .build(); + Record recordModel = Record.builder().name(name).nodeType(CONTENT_TYPE).build(); return recordFolderAPI.createRecord(recordModel, parentId); } @@ -554,6 +555,7 @@ public class BaseRMRestTest extends RestTest { getRestAPIFactory().getRMUserAPI().addUserPermission(categoryId, user, PERMISSION_FILING); rmRolesAndActionsAPI.assignUserToRole(dataUser.getAdminUser().getUsername(), - dataUser.getAdminUser().getPassword(), user.getUsername(), ROLE_RM_USER); + dataUser.getAdminUser().getPassword(), user.getUsername(), ROLE_RM_USER); } + } From d11d477d04e1f4f6b7abd1c6611f3171096be888 Mon Sep 17 00:00:00 2001 From: jcule Date: Fri, 22 Sep 2017 14:50:19 +0100 Subject: [PATCH 12/12] RM-5416: REST API Tests for Folder Classification - removing the v0 search --- .../java/org/alfresco/rest/v0/SearchAPI.java | 80 +++++-------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java index 236fbf058b..a465fc5c90 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/SearchAPI.java @@ -27,14 +27,11 @@ package org.alfresco.rest.v0; -import java.io.IOException; -import java.nio.charset.Charset; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.alfresco.dataprep.AlfrescoHttpClient; import org.alfresco.dataprep.AlfrescoHttpClientFactory; import org.alfresco.rest.core.v0.BaseAPI; import org.apache.http.NameValuePair; @@ -54,10 +51,8 @@ import org.springframework.stereotype.Component; public class SearchAPI extends BaseAPI { /** http client factory */ - @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; - - /** search API endpoint */ - private static final String SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/search?{1}"; + @Autowired + private AlfrescoHttpClientFactory alfrescoHttpClientFactory; /** faceted search API endpoint */ private static final String FACETED_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/faceted/rmsearch?{1}"; @@ -66,28 +61,26 @@ public class SearchAPI extends BaseAPI private static final String RM_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/{1}?{2}"; /** RM document search filters */ - private static final String RM_DEFAULT_RECORD_FILTERS = - "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; + private static final String RM_DEFAULT_RECORD_FILTERS = "records/true,undeclared/true,vital/false,folders/false,categories/false,frozen/false,cutoff/false"; /** * Perform search request on search endpoint as a user. *

* This method is applicable only to endpoints that support HTTP GET requests and return JSON body as response. + * * @param searchEndpoint * @param searchUser * @param searchPassword * @return search results as a {@link JSONObject}, please refer to API documentation for details */ - private JSONObject doSearch( - String searchEndpoint, - String searchUser, - String searchPassword) + private JSONObject doSearch(String searchEndpoint, String searchUser, String searchPassword) { - return facetedRequest(searchUser, searchPassword, null, searchEndpoint); + return facetedRequest(searchUser, searchPassword, null, searchEndpoint); } /** * Generic rm search. + * * @param username * @param password * @param site @@ -95,45 +88,36 @@ public class SearchAPI extends BaseAPI * @param filters * @return search results (see API reference for more details), null for any errors */ - public JSONObject rmSearch( - String username, - String password, - String site, - String query, - String filters) + public JSONObject rmSearch(String username, String password, String site, String query, String filters) { List searchParameters = new ArrayList(); searchParameters.add(new BasicNameValuePair("query", query)); searchParameters.add(new BasicNameValuePair("filters", filters)); - String requestURL = MessageFormat.format( - RM_SEARCH_ENDPOINT, - alfrescoHttpClientFactory.getObject().getAlfrescoUrl(), - (site != null) ? site : RM_SITE_ID, - URLEncodedUtils.format(searchParameters, "UTF-8")); + String requestURL = MessageFormat.format(RM_SEARCH_ENDPOINT, + alfrescoHttpClientFactory.getObject().getAlfrescoUrl(), (site != null) ? site : RM_SITE_ID, + URLEncodedUtils.format(searchParameters, "UTF-8")); return doSearch(requestURL, username, password); } /** - * Search as a user for records on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS - *
+ * Search as a user for records on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS
* If more fine-grained control of search parameters is required, use rmSearch() directly. + * * @param username * @param password * @param query * @return list of record names */ - public List searchForRecordsAsUser( - String username, - String password, - String query) + public List searchForRecordsAsUser(String username, String password, String query) { return getItemNames(rmSearch(username, password, "rm", query, RM_DEFAULT_RECORD_FILTERS)); } /** * Generic faceted search. + * * @param username * @param password * @param parameters @@ -146,6 +130,7 @@ public class SearchAPI extends BaseAPI /** * Execute faceted search for term. + * * @param searchUser * @param searchPassword * @param searchTerm @@ -153,14 +138,12 @@ public class SearchAPI extends BaseAPI */ public JSONObject facetedSearchForTerm(String searchUser, String searchPassword, String searchTerm) { - return facetedSearch( - searchUser, - searchPassword, - Arrays.asList(new BasicNameValuePair("term", searchTerm))); + return facetedSearch(searchUser, searchPassword, Arrays.asList(new BasicNameValuePair("term", searchTerm))); } /** * Helper method to search for documents as a user using faceted search. + * * @param username to search as * @param password for username * @param term search term @@ -171,34 +154,9 @@ public class SearchAPI extends BaseAPI return getItemNames(facetedSearchForTerm(username, password, term)); } - /** - * Helper method to search for documents or folders as a user using search. - * - * @param username to search as - * @param password for username - * @param term search term - * @return list of document names found - * @throws IOException - */ - public List searchForContentAsUser(String username, String password, String... searchParameters) - throws Exception - { - AlfrescoHttpClient client = alfrescoHttpClientFactory.getObject(); - String requestURL = MessageFormat.format(SEARCH_ENDPOINT, client.getAlfrescoUrl()); - - List nameValuePairs = new ArrayList(); - for (String searchParameter : searchParameters) - { - nameValuePairs.add(new BasicNameValuePair("term", searchParameter)); - } - requestURL = MessageFormat.format(SEARCH_ENDPOINT, client.getAlfrescoUrl(), - URLEncodedUtils.format(nameValuePairs, Charset.forName("UTF-8"))); - Thread.sleep(15000); - return getItemNames(doGetRequest(username, password, requestURL)); - } - /** * Helper method to extract list of names from search result. + * * @param searchResult * @return list of document or record names in search result * @throws RuntimeException for malformed search response