From b1239711871f5b796d6e1cedea640539b6dafe48 Mon Sep 17 00:00:00 2001 From: jcule Date: Sat, 9 Sep 2017 10:05:54 +0100 Subject: [PATCH 01/20] 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 b3e8d59f50cd96767ab4b0a7eb6688203d1e090f Mon Sep 17 00:00:00 2001 From: jcule Date: Sat, 9 Sep 2017 11:44:01 +0100 Subject: [PATCH 02/20] 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 9222483aeddec061eba446ca3d38f3987b951000 Mon Sep 17 00:00:00 2001 From: jcule Date: Sun, 17 Sep 2017 10:56:19 +0100 Subject: [PATCH 03/20] 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 c7b106cff4ff69e48f5ee75feca1358d3cdd55b0 Mon Sep 17 00:00:00 2001 From: jcule Date: Sun, 17 Sep 2017 18:25:33 +0100 Subject: [PATCH 04/20] 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 84eb116fd89a856ed7318b1a930434cc55f3dca4 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 18 Sep 2017 21:09:13 +0300 Subject: [PATCH 05/20] 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 c9a501052aa3bf2e6593253ff4e4a80fad33f92c Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 18 Sep 2017 21:25:27 +0300 Subject: [PATCH 06/20] 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 a9648f3f9af5f10cd2abe30edb5ec2ef01bbc9e2 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Mon, 18 Sep 2017 21:27:53 +0300 Subject: [PATCH 07/20] 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 ad94127b192744aa87e615dccea7961c2adf8796 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 19 Sep 2017 09:06:27 +0300 Subject: [PATCH 08/20] 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 8af8501585a0e8f4c68e60da72c9b32379dd897f Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 19 Sep 2017 09:19:01 +0300 Subject: [PATCH 09/20] 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 e5efa212c30b2684fc8c65fd211a4c33328d0669 Mon Sep 17 00:00:00 2001 From: Ana Bozianu Date: Tue, 19 Sep 2017 11:02:29 +0300 Subject: [PATCH 10/20] 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 49616d4019aec721558b3307cd7406ac79fdaf54 Mon Sep 17 00:00:00 2001 From: jcule Date: Fri, 22 Sep 2017 10:04:30 +0100 Subject: [PATCH 11/20] 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 c4cfea44a73e0ac40fcb334cfb04bb9f28dc74d0 Mon Sep 17 00:00:00 2001 From: jcule Date: Fri, 22 Sep 2017 14:50:19 +0100 Subject: [PATCH 12/20] 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 From 790e2263619d1a8d4787bf0bad79430dd0dc5275 Mon Sep 17 00:00:00 2001 From: Jelena Cule Date: Mon, 25 Sep 2017 11:11:10 +0100 Subject: [PATCH 13/20] Revert "Merge branch 'feature/RM-5416_REST_API_Tests_for_Folder_Classification_1' into 'master'" This reverts merge request !569 --- .../org/alfresco/rest/core/RMRestWrapper.java | 24 +-- .../alfresco/rest/core/RestAPIFactory.java | 10 +- .../java/org/alfresco/rest/v0/SearchAPI.java | 49 +++--- .../rm/community/base/BaseRMRestTest.java | 154 ++++-------------- 4 files changed, 69 insertions(+), 168 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 f61fe3c751..7a529e0633 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,7 +24,6 @@ * along with Alfresco. If not, see . * #L% */ - package org.alfresco.rest.core; import com.jayway.restassured.builder.RequestSpecBuilder; @@ -35,7 +34,6 @@ 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; @@ -147,24 +145,16 @@ 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 bdbabe6eb2..710413fa33 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,7 +24,6 @@ * along with Alfresco. If not, see . * #L% */ - package org.alfresco.rest.core; import static lombok.AccessLevel.PROTECTED; @@ -33,7 +32,6 @@ 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; @@ -67,7 +65,7 @@ import lombok.Setter; public class RestAPIFactory { @Autowired - @Getter(value = PROTECTED) + @Getter (value = PROTECTED) private DataUser dataUser; @Resource(name = "RMRestWrapper") @@ -87,12 +85,6 @@ 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/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 a465fc5c90..7bcfff7d48 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,7 +24,6 @@ * along with Alfresco. If not, see . * #L% */ - package org.alfresco.rest.v0; import java.text.MessageFormat; @@ -51,8 +50,7 @@ import org.springframework.stereotype.Component; public class SearchAPI extends BaseAPI { /** http client factory */ - @Autowired - private AlfrescoHttpClientFactory alfrescoHttpClientFactory; + @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; /** faceted search API endpoint */ private static final String FACETED_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/faceted/rmsearch?{1}"; @@ -61,26 +59,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 @@ -88,36 +88,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 @@ -130,7 +139,6 @@ public class SearchAPI extends BaseAPI /** * Execute faceted search for term. - * * @param searchUser * @param searchPassword * @param searchTerm @@ -138,12 +146,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 @@ -156,7 +166,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 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 5dee146514..38d4b2959d 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,7 +24,6 @@ * along with Alfresco. If not, see . * #L% */ - package org.alfresco.rest.rm.community.base; import static lombok.AccessLevel.PROTECTED; @@ -34,14 +33,11 @@ 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_USER; 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; @@ -55,7 +51,6 @@ 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; @@ -70,12 +65,8 @@ 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; @@ -94,21 +85,13 @@ 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) - private ContentService contentService; - - @Autowired - @Getter(value = PROTECTED) - private RMRolesAndActionsAPI rmRolesAndActionsAPI; - /** * Asserts the given status code * @@ -133,22 +116,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 @@ -156,7 +139,8 @@ 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 { @@ -220,12 +204,10 @@ 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); } /** @@ -238,12 +220,10 @@ 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,8 +235,7 @@ 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); } @@ -299,8 +278,7 @@ 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); } /** @@ -319,18 +297,16 @@ 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; @@ -344,8 +320,7 @@ 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); } @@ -360,16 +335,14 @@ 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 { @@ -389,8 +362,7 @@ 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); } @@ -405,9 +377,11 @@ 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; @@ -494,68 +468,4 @@ 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); - } - - /** - * 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 02219969b2b1cada63effe291e5539230a27f702 Mon Sep 17 00:00:00 2001 From: Oana Nechiforescu Date: Tue, 26 Sep 2017 14:50:28 +0300 Subject: [PATCH 14/20] First commit just the test and new API empty trashcan method. --- .../org/alfresco/rest/v0/UserTrashcanAPI.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/UserTrashcanAPI.java diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/UserTrashcanAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/UserTrashcanAPI.java new file mode 100644 index 0000000000..7179ea71c2 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/UserTrashcanAPI.java @@ -0,0 +1,56 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.v0; + +import org.alfresco.rest.core.v0.BaseAPI; +import org.springframework.stereotype.Component; + +/** + * Helper methods for performing actions on user trashcan + * + * @author Oana Nechiforescu + * @since 2.6 + */ +@Component +public class UserTrashcanAPI extends BaseAPI +{ + private static final String EMPTY_TRASHCAN = "{0}archive/workspace/SpacesStore"; + + /** + * Clears the trashcan for the current user + * + * @param username the username + * @param password the password + * + * @return true if the request succeeded, false if not + */ + public boolean emptyTrashcan(String username, String password) + { + return doDeleteRequest(username, password, EMPTY_TRASHCAN) != null; + } + +} From b19b5e8be1866a2a9c359a22f3e0e2d92e1a73b5 Mon Sep 17 00:00:00 2001 From: Oana Nechiforescu Date: Tue, 26 Sep 2017 14:51:13 +0300 Subject: [PATCH 15/20] Commit 2, test changes to use the new API method. --- .../src/main/java/org/alfresco/rest/v0/SearchAPI.java | 3 ++- 1 file changed, 2 insertions(+), 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 7bcfff7d48..176b51d2d8 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 @@ -50,7 +50,8 @@ import org.springframework.stereotype.Component; public class SearchAPI extends BaseAPI { /** http client factory */ - @Autowired private AlfrescoHttpClientFactory alfrescoHttpClientFactory; + @Autowired + private AlfrescoHttpClientFactory alfrescoHttpClientFactory; /** faceted search API endpoint */ private static final String FACETED_SEARCH_ENDPOINT = "{0}alfresco/s/slingshot/rmsearch/faceted/rmsearch?{1}"; From 6b54bd082f7f0cbb3c26ada31f66b84d57909889 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Mon, 25 Sep 2017 22:45:32 +0300 Subject: [PATCH 16/20] create relationships with v0 API requests --- .../org/alfresco/rest/core/v0/BaseAPI.java | 27 +++- .../rest/v0/CustomDefinitionsAPI.java | 137 ++++++++++++++++++ 2 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java 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 9e6e90063e..19a5db90ac 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 @@ -87,7 +87,7 @@ public abstract class BaseAPI @Autowired private ContentService contentService; - private static final String NODE_REF_WORKSPACE_SPACES_STORE = "workspace://SpacesStore/"; + protected static final String NODE_REF_WORKSPACE_SPACES_STORE = "workspace://SpacesStore/"; private static final String FILE_PLAN_PATH = "/Sites/rm/documentLibrary"; /** @@ -640,4 +640,29 @@ public abstract class BaseAPI { return FILE_PLAN_PATH; } + + /** + * Used to set RM items properties + * including records, categories and folders + */ + public enum CUSTOM_DEFINITIONS + { + ATTACHMENT("Attachment"), + MESSAGE("Message"), + NEXT_VERSION("Next Version"), + RENDITION("Rendition"); + String definition; + + private CUSTOM_DEFINITIONS(String definition) + { + this.definition = definition; + } + + public String getDefinition() + { + return definition; + } + + } + } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java new file mode 100644 index 0000000000..6a29ae5b09 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java @@ -0,0 +1,137 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.v0; + +import java.text.MessageFormat; + +import org.alfresco.rest.core.v0.BaseAPI; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * Methods to make API requests using v0 API on Records Management Custom Model Reference Definitions + * + * @author Rodica Sutu + * @since 2.6 + */ +@Component +public class CustomDefinitionsAPI extends BaseAPI +{ + /** + * custom references endpoint + */ + private static final String CUSTOM_REFERENCE_API_ENDPOINT = "{0}rma/admin/customreferencedefinitions"; + + /** + * create reference endpoint + */ + private static final String CREATE_RELATIONSHIP_API_ENDPOINT = "{0}node/{1}/customreferences"; + + // logger + private static final Logger LOGGER = LoggerFactory.getLogger(CustomDefinitionsAPI.class); + + /** + * Helper method to get custom references definitions + * + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param customDefinition custom reference definition name + */ + + public String getCustomReferencesId(String adminUser, String adminPassword, String customDefinition) + { + + JSONObject getResponse = doGetRequest(adminUser, adminPassword, CUSTOM_REFERENCE_API_ENDPOINT); + if (getResponse != null) + try + { + JSONArray customDefinitions = getResponse.getJSONObject("data").getJSONArray("customReferences"); + for (int i = 0; i < customDefinitions.length(); i++) + { + JSONObject item = customDefinitions.getJSONObject(i); + if (customDefinition.equalsIgnoreCase(item.has("source") ? item.getString("source") : null) || + customDefinition.equalsIgnoreCase(item.has("target") ? item.getString("target") : null) || + customDefinition.equalsIgnoreCase(item.has("label") ? item.getString("label") : null) + ) + { + return item.getString("refId"); + } + } + + } + catch (JSONException error) + { + LOGGER.error("Unable to get the refId for the custom reference definition " + customDefinition); + } + return null; + } + + /** + * Helper method to add custom reference instance to the specified record node + * + * @param adminUser user with administrative privileges + * @param adminPassword password for adminUser + * @param recordNodeIdFrom node ref to set a custom reference + * @param recordNodeIdto node ref of the to record + * @return true if creating relationship was successful, + * falseotherwise + */ + public boolean createRelationship( + String adminUser, + String adminPassword, + String recordNodeIdFrom, + String recordNodeIdto, + CUSTOM_DEFINITIONS relationshipType) + { + try + { + //create the request body + JSONObject requestParams = new JSONObject(); + requestParams.put("recordNodeIdto", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdto); + requestParams.put("refId", getCustomReferencesId(adminUser, adminPassword, relationshipType + .getDefinition())); + //send the API request to create the relationship + JSONObject setRelationshipStatus = doPostRequest(adminUser, adminPassword, requestParams, + MessageFormat.format(CREATE_RELATIONSHIP_API_ENDPOINT, "{0}", NODE_PREFIX + recordNodeIdFrom)); + //check the response + if (setRelationshipStatus != null) + { + return setRelationshipStatus.getBoolean("success"); + } + } + catch (JSONException error) + { + LOGGER.error("Unable to extract response parameter", error); + } + return false; + } + +} From da50858cfc8a38ef30d4d588c203d5dc6637b33d Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 26 Sep 2017 09:51:15 +0300 Subject: [PATCH 17/20] fix the java docs --- .../src/main/java/org/alfresco/rest/core/v0/BaseAPI.java | 5 +---- 1 file changed, 1 insertion(+), 4 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 19a5db90ac..125fba650f 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 @@ -642,8 +642,7 @@ public abstract class BaseAPI } /** - * Used to set RM items properties - * including records, categories and folders + * List of existing records management custom references. */ public enum CUSTOM_DEFINITIONS { @@ -662,7 +661,5 @@ public abstract class BaseAPI { return definition; } - } - } From 30959017ee4cd644267348ed7354b398b7e53024 Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Tue, 26 Sep 2017 16:41:16 +0300 Subject: [PATCH 18/20] fix the request body sent when creating relationships --- .../main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.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/CustomDefinitionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java index 6a29ae5b09..257ac05bb7 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java @@ -115,7 +115,7 @@ public class CustomDefinitionsAPI extends BaseAPI { //create the request body JSONObject requestParams = new JSONObject(); - requestParams.put("recordNodeIdto", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdto); + requestParams.put("toNode", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdto); requestParams.put("refId", getCustomReferencesId(adminUser, adminPassword, relationshipType .getDefinition())); //send the API request to create the relationship From 9e5f53bd09a76df1c3ffa9b3e0ea194cf3aafead Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 27 Sep 2017 09:17:54 +0300 Subject: [PATCH 19/20] review comments changes --- .../org/alfresco/rest/core/v0/BaseAPI.java | 22 ------- .../model/custom/CustomDefinitions.java | 63 +++++++++++++++++++ .../rest/v0/CustomDefinitionsAPI.java | 50 ++++++++++----- 3 files changed, 98 insertions(+), 37 deletions(-) create mode 100644 rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/custom/CustomDefinitions.java 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 125fba650f..c4844156aa 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 @@ -640,26 +640,4 @@ public abstract class BaseAPI { return FILE_PLAN_PATH; } - - /** - * List of existing records management custom references. - */ - public enum CUSTOM_DEFINITIONS - { - ATTACHMENT("Attachment"), - MESSAGE("Message"), - NEXT_VERSION("Next Version"), - RENDITION("Rendition"); - String definition; - - private CUSTOM_DEFINITIONS(String definition) - { - this.definition = definition; - } - - public String getDefinition() - { - return definition; - } - } } diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/custom/CustomDefinitions.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/custom/CustomDefinitions.java new file mode 100644 index 0000000000..5e94f25d91 --- /dev/null +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/model/custom/CustomDefinitions.java @@ -0,0 +1,63 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2017 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * - + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.rest.rm.community.model.custom; + +/** + * List of existing records management custom references. + * + * @author Rodica Sutu + * @since 2.6 + */ +public enum CustomDefinitions +{ + ATTACHMENT("Attachment"), + MESSAGE("Message"), + NEXT_VERSION("Next Version"), + RENDITION("Rendition"); + /** + * The name of custom reference. + */ + private String definition; + + /** + * Private constructor. + */ + CustomDefinitions(String definition) + { + this.definition = definition; + } + + /** + * Get the name of the custom reference. + * + * @return The value of custom reference. + */ + public String getDefinition() + { + return definition; + } +} diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java index 257ac05bb7..fd2ab72a1b 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java @@ -29,6 +29,7 @@ package org.alfresco.rest.v0; import java.text.MessageFormat; import org.alfresco.rest.core.v0.BaseAPI; +import org.alfresco.rest.rm.community.model.custom.CustomDefinitions; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -55,35 +56,52 @@ public class CustomDefinitionsAPI extends BaseAPI */ private static final String CREATE_RELATIONSHIP_API_ENDPOINT = "{0}node/{1}/customreferences"; - // logger + /** + * logger + */ private static final Logger LOGGER = LoggerFactory.getLogger(CustomDefinitionsAPI.class); /** - * Helper method to get custom references definitions + * Helper method to get the reference id for a custom reference * * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param customDefinition custom reference definition name + * @return reference id if the customDefinition is found + * null otherwise + * */ - - public String getCustomReferencesId(String adminUser, String adminPassword, String customDefinition) + public String getCustomReferenceId(String adminUser, String adminPassword, String customDefinition) { JSONObject getResponse = doGetRequest(adminUser, adminPassword, CUSTOM_REFERENCE_API_ENDPOINT); if (getResponse != null) + { try { JSONArray customDefinitions = getResponse.getJSONObject("data").getJSONArray("customReferences"); for (int i = 0; i < customDefinitions.length(); i++) { JSONObject item = customDefinitions.getJSONObject(i); - if (customDefinition.equalsIgnoreCase(item.has("source") ? item.getString("source") : null) || - customDefinition.equalsIgnoreCase(item.has("target") ? item.getString("target") : null) || - customDefinition.equalsIgnoreCase(item.has("label") ? item.getString("label") : null) - ) + boolean hasSource = customDefinition.equalsIgnoreCase( + item.has("source") ? item.getString("source") : null + ); + + boolean hasTarget = customDefinition.equalsIgnoreCase( + item.has("target") ? item.getString("target") : null + ); + + boolean hasLabel = customDefinition.equalsIgnoreCase( + item.has("label") ? item.getString("label") : null + ); + if ( hasSource || hasTarget || hasLabel) { return item.getString("refId"); } + else + { + return null; + } } } @@ -91,6 +109,7 @@ public class CustomDefinitionsAPI extends BaseAPI { LOGGER.error("Unable to get the refId for the custom reference definition " + customDefinition); } + } return null; } @@ -100,23 +119,24 @@ public class CustomDefinitionsAPI extends BaseAPI * @param adminUser user with administrative privileges * @param adminPassword password for adminUser * @param recordNodeIdFrom node ref to set a custom reference - * @param recordNodeIdto node ref of the to record - * @return true if creating relationship was successful, - * falseotherwise + * @param recordNodeIdTo node ref of the to record + * @param relationshipType relation type to be created + * @return true if creating relationship was successful, + * false otherwise */ public boolean createRelationship( String adminUser, String adminPassword, String recordNodeIdFrom, - String recordNodeIdto, - CUSTOM_DEFINITIONS relationshipType) + String recordNodeIdTo, + CustomDefinitions relationshipType) { try { //create the request body JSONObject requestParams = new JSONObject(); - requestParams.put("toNode", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdto); - requestParams.put("refId", getCustomReferencesId(adminUser, adminPassword, relationshipType + requestParams.put("toNode", NODE_REF_WORKSPACE_SPACES_STORE + recordNodeIdTo); + requestParams.put("refId", getCustomReferenceId(adminUser, adminPassword, relationshipType .getDefinition())); //send the API request to create the relationship JSONObject setRelationshipStatus = doPostRequest(adminUser, adminPassword, requestParams, From 9e18aa7f0c7d8b25d10996d1f3e456a4b090623b Mon Sep 17 00:00:00 2001 From: Rodica Sutu Date: Wed, 27 Sep 2017 15:59:29 +0300 Subject: [PATCH 20/20] fix the failure introduced with the last commit --- .../main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java index fd2ab72a1b..0529374f83 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/v0/CustomDefinitionsAPI.java @@ -98,10 +98,6 @@ public class CustomDefinitionsAPI extends BaseAPI { return item.getString("refId"); } - else - { - return null; - } } }