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/HEAD/root@126586 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:40:15 +00:00
parent d466175a15
commit e9b8d4542e
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 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; private final static Map<String,QName> MAP_PARAM_SORT_QNAME;
static static
{ {
@@ -112,12 +115,33 @@ public class QueriesImpl implements Queries, InitializingBean
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
// TODO check min length, excluding quotes etc
String term = parameters.getParameter(PARAM_TERM); String term = parameters.getParameter(PARAM_TERM);
if (term == null) if (term == null)
{ {
throw new InvalidArgumentException("Query 'term' not specified"); 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); String rootNodeId = parameters.getParameter(PARAM_ROOT_NODE_ID);
if (rootNodeId != null) if (rootNodeId != null)

View File

@@ -393,6 +393,16 @@ public class QueriesApiTest extends AbstractBaseApiTest
params.put(Queries.PARAM_ROOT_NODE_ID, myFolderNodeId); params.put(Queries.PARAM_ROOT_NODE_ID, myFolderNodeId);
getAll(URL_QUERIES_LSN, user1, paging, params, 400); getAll(URL_QUERIES_LSN, user1, paging, params, 400);
// -ve test - term too short
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, "ab");
getAll(URL_QUERIES_LSN, user1, paging, params, 400);
// -ve test - term is still too short
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, " \"a b *\" ");
getAll(URL_QUERIES_LSN, user1, paging, params, 400);
// -ve test - invalid sort field // -ve test - invalid sort field
params = new HashMap<>(2); params = new HashMap<>(2);
params.put(Queries.PARAM_TERM, testTerm); params.put(Queries.PARAM_TERM, testTerm);