diff --git a/source/java/org/alfresco/rest/api/Nodes.java b/source/java/org/alfresco/rest/api/Nodes.java index dde2fd15eb..7ec10c8fd8 100644 --- a/source/java/org/alfresco/rest/api/Nodes.java +++ b/source/java/org/alfresco/rest/api/Nodes.java @@ -43,15 +43,13 @@ import org.springframework.extensions.webscripts.servlet.FormData; /** * File Folder (Nodes) API * - * @author steveglover * @author janv + * @author Jamal Kaabi-Mofrad + * @author Gethin James + * @author steveglover */ public interface Nodes { - String PATH_ROOT = "-root-"; - String PATH_MY = "-my-"; - String PATH_SHARED = "-shared-"; - /** * Get the node representation for the given node. * @@ -186,4 +184,35 @@ public interface Nodes * @return true if the type of the given nodeRef is a sub-class of another class, otherwise false */ boolean isSubClass(NodeRef nodeRef, QName ofClassQName, boolean validateNodeRef); + + /** + * API Constants - query parameters, etc + */ + + String PATH_ROOT = "-root-"; + String PATH_MY = "-my-"; + String PATH_SHARED = "-shared-"; + + String PARAM_RELATIVE_PATH = "relativePath"; + String PARAM_AUTO_RENAME = "autoRename"; + String PARAM_PERMANENT = "permanent"; + + String PARAM_SELECT_PROPERTIES = "properties"; + String PARAM_SELECT_PATH = "path"; + String PARAM_SELECT_ASPECTNAMES = "aspectNames"; + String PARAM_SELECT_ISLINK = "isLink"; + + String PARAM_ISFOLDER = "isFolder"; + String PARAM_ISFILE = "isFile"; + + String PARAM_INCLUDE_SUBTYPES = "INCLUDESUBTYPES"; + + String PARAM_NAME = "name"; + String PARAM_CREATEDAT = "createdAt"; + String PARAM_MODIFIEDAT = "modifiedAt"; + String PARAM_CREATEBYUSER = "createdByUser"; + String PARAM_MODIFIEDBYUSER = "modifiedByUser"; + String PARAM_MIMETYPE = "mimeType"; + String PARAM_SIZEINBYTES = "sizeInBytes"; + String PARAM_NODETYPE = "nodeType"; } diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 6cc51d44e8..eb33b725f7 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -145,15 +145,6 @@ public class NodesImpl implements Nodes DOCUMENT, FOLDER } - private final static String PARAM_RELATIVE_PATH = "relativePath"; - private final static String PARAM_AUTO_RENAME = "autoRename"; - private final static String PARAM_PERMANENT = "permanent"; - - private final static String PARAM_SELECT_PROPERTIES = "properties"; - private final static String PARAM_SELECT_PATH = "path"; - private final static String PARAM_SELECT_ASPECTNAMES = "aspectNames"; - private final static String PARAM_SELECT_ISLINK = "isLink"; - private NodeService nodeService; private DictionaryService dictionaryService; private FileFolderService fileFolderService; @@ -256,20 +247,6 @@ public class NodesImpl implements Nodes ContentModel.PROP_LOCK_OWNER, ContentModel.PROP_WORKING_COPY_OWNER); - private final static String PARAM_ISFOLDER = "isFolder"; - private final static String PARAM_ISCONTENT = "isContent"; - - private final static String PARAM_INCLUDE_SUBTYPES = "INCLUDESUBTYPES"; - - private final static String PARAM_NAME = "name"; - private final static String PARAM_CREATEDAT = "createdAt"; - private final static String PARAM_MODIFIEDAT = "modifiedAt"; - private final static String PARAM_CREATEBYUSER = "createdByUser"; - private final static String PARAM_MODIFIEDBYUSER = "modifiedByUser"; - private final static String PARAM_MIMETYPE = "mimeType"; - private final static String PARAM_SIZEINBYTES = "sizeInBytes"; - private final static String PARAM_NODETYPE = "nodeType"; - private final static Map MAP_PARAM_QNAME; static { @@ -290,7 +267,7 @@ public class NodesImpl implements Nodes // list children filtering (via where clause) private final static Set LIST_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES = - new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER, PARAM_ISCONTENT, PARAM_NODETYPE})); + new HashSet<>(Arrays.asList(new String[] {PARAM_ISFOLDER, PARAM_ISFILE, PARAM_NODETYPE})); /* * Validates that node exists. @@ -963,11 +940,11 @@ public class NodesImpl implements Nodes QueryHelper.walk(q, propertyWalker); Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class); - Boolean isContent = propertyWalker.getProperty(PARAM_ISCONTENT, WhereClauseParser.EQUALS, Boolean.class); + Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class); - if ((isFolder != null) && (isContent != null)) + if ((isFolder != null) && (isFile != null)) { - includeFiles = isContent; + includeFiles = isFile; includeFolders = isFolder; } else if (isFolder != null) @@ -975,10 +952,10 @@ public class NodesImpl implements Nodes includeFiles = !isFolder; includeFolders = isFolder; } - else if (isContent != null) + else if (isFile != null) { - includeFiles = isContent; - includeFolders = !isContent; + includeFiles = isFile; + includeFolders = !isFile; } String nodeTypeStr = propertyWalker.getProperty(PARAM_NODETYPE, WhereClauseParser.EQUALS, String.class); diff --git a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java index 3708813fb2..0fb54fda1e 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -416,7 +416,7 @@ public class NodeApiTest extends AbstractBaseApiTest // filtering, via where clause - folders only params = new LinkedHashMap<>(); - params.put("where", "(isFolder=true)"); + params.put("where", "("+Nodes.PARAM_ISFOLDER+"=true)"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); assertEquals(2, nodes.size()); @@ -431,7 +431,7 @@ public class NodeApiTest extends AbstractBaseApiTest // filtering, via where clause - content only params = new LinkedHashMap<>(); - params.put("where", "(isContent=true)"); + params.put("where", "("+Nodes.PARAM_ISFILE+"=true)"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); @@ -441,20 +441,20 @@ public class NodeApiTest extends AbstractBaseApiTest // list children via relativePath - params = Collections.singletonMap("relativePath", folder1); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); assertEquals(contentF1_Id, nodes.get(0).getId()); - params = Collections.singletonMap("relativePath", "User Homes/" + user1 + "/" + folder2); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/" + folder2); response = getAll(rootChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); assertEquals(1, nodes.size()); assertEquals(contentF2_Id, nodes.get(0).getId()); // -ve test - Invalid QName (Namespace prefix cm... is not mapped to a namespace URI) for the orderBy parameter. - params = Collections.singletonMap("orderBy", "isFolder DESC,cm" + System.currentTimeMillis() + ":modified DESC"); + params = Collections.singletonMap("orderBy", Nodes.PARAM_ISFOLDER+" DESC,cm" + System.currentTimeMillis() + ":modified DESC"); getAll(myChildrenUrl, user1, paging, params, 400); paging = getPaging(0, 10); @@ -470,19 +470,19 @@ public class NodeApiTest extends AbstractBaseApiTest getAll(getChildrenUrl(myFilesNodeRef), user2, paging, 403); // -ve test - try to list children using relative path to unknown node - params = Collections.singletonMap("relativePath", "User Homes/" + user1 + "/unknown"); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user1 + "/unknown"); getAll(rootChildrenUrl, user1, paging, params, 404); // -ve test - try to list children using relative path to node for which user does not have read permission - params = Collections.singletonMap("relativePath", "User Homes/" + user2); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "User Homes/" + user2); getAll(rootChildrenUrl, user1, paging, params, 403); // -ve test - try to list children using relative path to node that is of wrong type (ie. not a folder/container) - params = Collections.singletonMap("relativePath", folder1 + "/" + contentF1); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, folder1 + "/" + contentF1); getAll(myChildrenUrl, user1, paging, params, 400); // -ve test - list folder children for non-folder node with relative path should return 400 - params = Collections.singletonMap("relativePath", "/unknown"); + params = Collections.singletonMap(Nodes.PARAM_RELATIVE_PATH, "/unknown"); getAll(getChildrenUrl(contentNodeRef), user1, paging, params, 400); }