Merged HEAD (5.2) to 5.2.N (5.2.1)

126586 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      124792 jvonka: RA-767: Queries API - min 3 alphanumeric chars in search 'term' (pending requirement review)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126931 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 12:12:55 +00:00
parent 07d78c71c6
commit 5ab0af68ad
2 changed files with 35 additions and 1 deletions

View File

@@ -66,6 +66,9 @@ public class QueriesImpl implements Queries, InitializingBean
private final static String QUERY_LIVE_SEARCH_NODES = "live-search-nodes";
private final static int TERM_MIN_LEN = 3; // review: should this be configurable system-wide (&/or per-tenant in the cloud) ?
private final static Map<String,QName> MAP_PARAM_SORT_QNAME;
static
{
@@ -112,12 +115,33 @@ public class QueriesImpl implements Queries, InitializingBean
StringBuilder sb = new StringBuilder();
// TODO check min length, excluding quotes etc
String term = parameters.getParameter(PARAM_TERM);
if (term == null)
{
throw new InvalidArgumentException("Query 'term' not specified");
}
else
{
String s = term.trim();
int cnt = 0;
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if (Character.isLetterOrDigit(c))
{
cnt++;
if (cnt == TERM_MIN_LEN)
{
break;
}
}
}
if (cnt < TERM_MIN_LEN)
{
throw new InvalidArgumentException("Query 'term' is too short. Must have at least "+TERM_MIN_LEN+" alphanumeric chars");
}
}
String rootNodeId = parameters.getParameter(PARAM_ROOT_NODE_ID);
if (rootNodeId != null)