mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-10 14:11:58 +00:00
ACS-2343 Add new method in searchAPI
This commit is contained in:
@@ -140,6 +140,24 @@ public class SearchAPI extends BaseAPI
|
||||
return getItemNames(rmSearch(username, password, "rm", query, searchFilterParamaters, sortby));
|
||||
}
|
||||
|
||||
public List<String> searchForNodeNamesAsUserWithWait(String username, String password, String query, String sortby,
|
||||
boolean includeCategories, boolean includeFolders ) throws InterruptedException
|
||||
{
|
||||
String searchFilterParameters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders),
|
||||
Boolean.toString(includeCategories));
|
||||
JSONObject jsonResults = rmSearch(username, password, "rm", query, searchFilterParameters, sortby);
|
||||
// Delay because JSON parsing not always completed yet
|
||||
for (int i = 0 ; i < 20; i++)
|
||||
{
|
||||
if (jsonResults.has("items"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
return getItemNames(jsonResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
@@ -710,15 +710,47 @@ public class BaseRMRestTest extends RestTest
|
||||
}
|
||||
}
|
||||
|
||||
String searchFilterParameters = MessageFormat.format(RM_DEFAULT_NODES_FILTERS, Boolean.toString(includeFolders),
|
||||
Boolean.toString(includeCategories));
|
||||
JSONObject jsonResults = rmSearch(user.getUsername(), user.getPassword(), "rm", term, searchFilterParameters, sortby);
|
||||
if (expectedResults != null && !expectedResults.isEmpty())
|
||||
results = searchApi.searchForNodeNamesAsUser(user.getUsername(), user.getPassword(), term, sortby,
|
||||
includeFolders, includeCategories);
|
||||
if (!results.isEmpty() && results.containsAll(expectedResults))
|
||||
{
|
||||
// Delay because JSON parsing not always completed yet
|
||||
Utility.sleep(1000, 20000, () -> assertTrue(searchResult.has("items")));
|
||||
break;
|
||||
}
|
||||
results = getItemNames(jsonResults);
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
// double wait time to not overdo solr search
|
||||
waitInMilliSeconds = waitInMilliSeconds * 2;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
// Poc code to see if waiting for JSON parsing to complete has any effect on intermittent error
|
||||
public List<String> searchForRMContentAsUserWithWait(UserModel user, String term, String sortby, boolean includeFolders,
|
||||
boolean includeCategories, List<String> expectedResults)
|
||||
{
|
||||
List<String> results = new ArrayList<>();
|
||||
// wait for solr indexing
|
||||
int counter = 0;
|
||||
int waitInMilliSeconds = 7000;
|
||||
while (counter < 4)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.wait(waitInMilliSeconds);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
// Restore interrupted state...
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
results = searchApi.searchForNodeNamesAsUserWithWait(user.getUsername(), user.getPassword(), term, sortby,
|
||||
includeFolders, includeCategories);
|
||||
if (!results.isEmpty() && results.containsAll(expectedResults))
|
||||
{
|
||||
break;
|
||||
|
Reference in New Issue
Block a user