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 935dcc151c..82813b7556 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 @@ -121,6 +121,37 @@ public abstract class BaseAPI return results; } + /** + * Helper method to extract the property value for the given nodeRef and property name + * + * @param result + * @param nodeRef + * @param propertyName + * @return + */ + protected String getPropertyValue(JSONObject result, String nodeRef, String propertyName) + { + String propertValue = ""; + try + { + JSONArray items = result.getJSONArray("items"); + for (int i = 0; i < items.length(); i++) + { + JSONObject item = items.getJSONObject(i); + if(nodeRef.equals(item.getString("nodeRef"))) + { + propertValue = item.getJSONObject("properties").getString(propertyName); + } + } + } + catch (JSONException error) + { + throw new RuntimeException("Unable to parse result", error); + } + + return propertValue; + } + /** * Helper method to extract property values from request result and put them in map as a list that corresponds to a unique property value. * 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 809397ef6c..5fa460cf41 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 @@ -123,42 +123,41 @@ public class SearchAPI extends BaseAPI * Search as a user for nodes on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS and sorted * by sortby *
- * If more fine-grained control of search parameters is required, use rmSearch() directly. + * * @param username * @param password * @param query * @param sortby - * @return list of record names + * @return list of node names */ - public List searchForRecordsAsUser( - String username, String password, - String query, String sortby, - boolean includeCategories, boolean includeFolders) + public List searchForNodeNamesAsUser(String username, String password, String query, String sortby, + boolean includeCategories, boolean includeFolders) { - String searchFilterParamaters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders), Boolean.toString(includeCategories)); + String searchFilterParamaters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders), + Boolean.toString(includeCategories)); return getItemNames(rmSearch(username, password, "rm", query, searchFilterParamaters, sortby)); } /** - * Search as a user for content on site "rm" matching query, using SearchAPI.RM_DEFAULT_NODES_FILTERS and sorted - * by sortby - *
- * If more fine-grained control of search parameters is required, use rmSearch() directly. + * Search as a user for nodes on site "rm" matching query, using SearchAPI.RM_DEFAULT_RECORD_FILTERS and sorted + * by sortby and returns the property value for the given nodeRef and property name + * * @param username * @param password * @param query * @param sortby - * @return list of record names + * @param includeCategories + * @param includeFolders + * @return list of node properties */ - public List searchForRmContentAsUser( - String username, - String password, - String query, - String sortby) + public String searchForNodePropertyAsUser(String username, String password, String nodeRef, String propertyName, String query, String sortby, + boolean includeCategories, boolean includeFolders) { - return getItemNames(rmSearch(username, password, "rm", query, RM_DEFAULT_NODES_FILTERS, sortby)); + String searchFilterParamaters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders), + Boolean.toString(includeCategories)); + return getItemProperty(rmSearch(username, password, "rm", query, searchFilterParamaters, sortby), nodeRef, propertyName); } - + /** * Generic faceted search. * @param username @@ -228,12 +227,35 @@ 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 FileNotFoundException + * @throws JsonSyntaxException + * @throws JsonIOException * @throws RuntimeException for malformed search response */ + /** + * Helper method to extract list of names from search result. + * + * @param searchResult + * @param getProperties + * @return + */ private List getItemNames(JSONObject searchResult) { return getPropertyValues(searchResult, "name"); } + + /** + * Helper method to extract list of property values from search result for the given nodeRef. + * + * @param searchResult + * @param getProperties + * @return + */ + private String getItemProperty(JSONObject searchResult, String nodeRef, String propertyName) + { + return getPropertyValue(searchResult, nodeRef, propertyName); + } } 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 88600a2d45..bbf001ae3e 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 @@ -681,13 +681,15 @@ public class BaseRMRestTest extends RestTest } /** - * Returns records search results for the given search term - * + * Returns the list of node names returned by search results for the given search term + * * @param user * @param term * @param sortby + * @param includeFolders + * @param includeCategories * @param expectedResults - * @return + * @return List */ public List searchForRMContentAsUser(UserModel user, String term, String sortby, boolean includeFolders, boolean includeCategories, List expectedResults) @@ -708,8 +710,8 @@ public class BaseRMRestTest extends RestTest { } } - results = searchApi.searchForRecordsAsUser(user.getUsername(), user.getPassword(), term, sortby, - includeFolders, includeCategories); + results = searchApi.searchForNodeNamesAsUser(user.getUsername(), user.getPassword(), term, sortby, + includeFolders, includeCategories); if (!results.isEmpty() && results.containsAll(expectedResults)) { break; @@ -724,6 +726,54 @@ public class BaseRMRestTest extends RestTest return results; } + /** + * Returns the property value for the given property name and nodeRef of the search results + * + * @param user + * @param term + * @param nodeRef + * @param propertyName + * @param sortby + * @param includeFolders + * @param includeCategories + * @param expectedResults + * @return String + */ + public String searchForRMContentAsUser(UserModel user, String term, String nodeRef, String propertyName, + String sortby, boolean includeFolders, boolean includeCategories, String expectedResults) + { + String result = ""; + // wait for solr indexing + int counter = 0; + int waitInMilliSeconds = 6000; + while (counter < 3) + { + synchronized (this) + { + try + { + this.wait(waitInMilliSeconds); + } + catch (InterruptedException e) + { + } + } + result = searchApi.searchForNodePropertyAsUser(user.getUsername(), user.getPassword(), nodeRef, + propertyName, term, sortby, includeFolders, includeCategories); + if (!result.isEmpty() && result.contains(expectedResults)) + { + break; + } + else + { + counter++; + } + // double wait time to not overdo solr search + waitInMilliSeconds = (waitInMilliSeconds * 2); + } + return result; + } + /** * Helper method to return site document library content model *