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

126608 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      125032 jvonka: RA-767: Queries API - bug fixes (and updated tests)
      - optional rootNodeId should allow well-known aliases (-root-,-my-,-shared-)
      - investigate and 'fix' apparent underlying issue with '.' which causes 500 in FTS query parser, eg. abc.txt


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126953 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 12:20:23 +00:00
parent be9428619b
commit 366ed0fce0
4 changed files with 58 additions and 14 deletions

View File

@@ -191,6 +191,8 @@ public interface Nodes
NodeRef validateNode(StoreRef storeRef, String nodeId);
NodeRef validateNode(String nodeId);
NodeRef validateNode(NodeRef nodeRef);
NodeRef validateOrLookupNode(String nodeId, String path);
boolean nodeMatches(NodeRef nodeRef, Set<QName> expectedTypes, Set<QName> excludedTypes);
/**

View File

@@ -600,7 +600,7 @@ public class NodesImpl implements Nodes
return nodeService.getPrimaryParent(nodeRef).getParentRef();
}
protected NodeRef validateOrLookupNode(String nodeId, String path)
public NodeRef validateOrLookupNode(String nodeId, String path)
{
NodeRef parentNodeRef;

View File

@@ -158,11 +158,12 @@ public class QueriesImpl implements Queries, InitializingBean
String rootNodeId = parameters.getParameter(PARAM_ROOT_NODE_ID);
if (rootNodeId != null)
{
sb.append("PATH:\"").append(getQNamePath(rootNodeId)).append("//*\" AND (");
NodeRef nodeRef = nodes.validateOrLookupNode(rootNodeId, null);
sb.append("PATH:\"").append(getQNamePath(nodeRef.getId())).append("//*\" AND (");
}
// this will be expanded via query template
sb.append(QT_FIELD+":").append(term);
// this will be expanded via query template (+ default field name)
sb.append(term);
if (rootNodeId != null)
{
@@ -195,8 +196,9 @@ public class QueriesImpl implements Queries, InitializingBean
sp.setQuery(sb.toString());
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
// query template / field
// query template / default field name
sp.addQueryTemplate(QT_FIELD, "%(cm:name cm:title cm:description TEXT TAG)");
sp.setDefaultFieldName(QT_FIELD);
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);

View File

@@ -170,13 +170,13 @@ public class QueriesApiTest extends AbstractBaseApiTest
String f1Id = createFolder(user1, myFolderNodeId, "folder 1").getId();
String f2Id = createFolder(user1, myFolderNodeId, "folder 2").getId();
String f3Id = createFolder(user1, myFolderNodeId, "folder 3").getId();
String name = "name";
String title = "title";
String descrip = "descrip";
String folderNameSuffix = " "+testTerm+" folder";
String txtSuffix = ".txt";
Map<String,String> idNameMap = new HashMap<>();
@@ -187,7 +187,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
String contentText = "f1 " + testTerm + " test document " + user1 + " document " + i;
String num = String.format("%05d", nameIdx);
String docName = name+num+name;
String docName = name+num+name+txtSuffix;
Map<String,String> docProps = new HashMap<>(2);
docProps.put("cm:title", title+num+title);
@@ -208,7 +208,7 @@ public class QueriesApiTest extends AbstractBaseApiTest
String contentText = "f2 " + testTerm + " test document";
String num = String.format("%05d", nameIdx);
String docName = name+num+name;
String docName = name+num+name+txtSuffix;
Map<String, String> props = new HashMap<>(2);
props.put("cm:title", title+num+title);
@@ -284,7 +284,31 @@ public class QueriesApiTest extends AbstractBaseApiTest
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f3NodeIds, null);
// Search hits based on FTS (content) - with folder 2 as the root node (for path-based / in-tree search)
// Search - with -root- as the root node (for path-based / in-tree search)
params = new HashMap<>(2);
params.put(Queries.PARAM_TERM, testTerm);
params.put(Queries.PARAM_ROOT_NODE_ID, Nodes.PATH_ROOT);
response = getAll(URL_QUERIES_LSN, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, allIds, null);
// Search - with -shared- as the root node (for path-based / in-tree search)
params = new HashMap<>(2);
params.put(Queries.PARAM_TERM, testTerm);
params.put(Queries.PARAM_ROOT_NODE_ID, Nodes.PATH_SHARED);
response = getAll(URL_QUERIES_LSN, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(0, nodes.size());
// Search - with folder 1 as root node (for path-based / in-tree search)
params = new HashMap<>(2);
params.put(Queries.PARAM_TERM, testTerm);
params.put(Queries.PARAM_ROOT_NODE_ID, f1Id);
response = getAll(URL_QUERIES_LSN, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f1NodeIds, null);
// Search - with folder 2 as the root node (for path-based / in-tree search)
params = new HashMap<>(2);
params.put(Queries.PARAM_TERM, testTerm);
params.put(Queries.PARAM_ROOT_NODE_ID, f2Id);
@@ -292,13 +316,13 @@ public class QueriesApiTest extends AbstractBaseApiTest
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f2NodeIds, null);
// Search hits based on FTS (content) - with folder 1 as root node (for path-based / in-tree search)
// Search - with -my- as the root node (for path-based / in-tree search)
params = new HashMap<>(2);
params.put(Queries.PARAM_TERM, testTerm);
params.put(Queries.PARAM_ROOT_NODE_ID, f1Id);
params.put(Queries.PARAM_TERM, name+"*");
params.put(Queries.PARAM_ROOT_NODE_ID, Nodes.PATH_MY);
response = getAll(URL_QUERIES_LSN, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
checkNodeIds(nodes, f1NodeIds, null);
checkNodeIds(nodes, allIds, null);
// Search hits based on cm:name
String term = name+String.format("%05d", 1)+name;
@@ -315,10 +339,26 @@ public class QueriesApiTest extends AbstractBaseApiTest
}
else
{
assertEquals(term, node.getName());
assertEquals(term+txtSuffix, node.getName());
}
}
// search for name with . (eg. ".txt") without double quotes
term = name+String.format("%05d", 1)+name+txtSuffix;
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, term);
response = getAll(URL_QUERIES_LSN, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
// search for name with . (eg. ".txt") with double quotes
term = name+String.format("%05d", 1)+name+txtSuffix;
params = new HashMap<>(1);
params.put(Queries.PARAM_TERM, "\""+term+"\"");
response = getAll(URL_QUERIES_LSN, user1, paging, params, 200);
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(2, nodes.size());
// Search hits based on cm:title
term = title+String.format("%05d", 2)+title;
params = new HashMap<>(2);