diff --git a/source/java/org/alfresco/rest/api/Nodes.java b/source/java/org/alfresco/rest/api/Nodes.java index 7ec10c8fd8..7cccee8739 100644 --- a/source/java/org/alfresco/rest/api/Nodes.java +++ b/source/java/org/alfresco/rest/api/Nodes.java @@ -197,10 +197,10 @@ public interface Nodes 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_INCLUDE_PROPERTIES = "properties"; + String PARAM_INCLUDE_PATH = "path"; + String PARAM_INCLUDE_ASPECTNAMES = "aspectNames"; + String PARAM_INCLUDE_ISLINK = "isLink"; String PARAM_ISFOLDER = "isFolder"; String PARAM_ISFILE = "isFile"; diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index 2fce06290f..4f0284fe15 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -655,14 +655,14 @@ public class NodesImpl implements Nodes private Node getFolderOrDocumentFullInfo(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, Parameters parameters) { - List selectParam = new ArrayList<>(); - selectParam.addAll(parameters.getSelectedProperties()); + List includeParam = new ArrayList<>(); + includeParam.addAll(parameters.getInclude()); // Add basic info for single get (above & beyond minimal that is used for listing collections) - selectParam.add(PARAM_SELECT_ASPECTNAMES); - selectParam.add(PARAM_SELECT_PROPERTIES); + includeParam.add(PARAM_INCLUDE_ASPECTNAMES); + includeParam.add(PARAM_INCLUDE_PROPERTIES); - return getFolderOrDocument(nodeRef, parentNodeRef, nodeTypeQName, selectParam, null); + return getFolderOrDocument(nodeRef, parentNodeRef, nodeTypeQName, includeParam, null); } private Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List selectParam, Map mapUserInfo) @@ -673,7 +673,7 @@ public class NodesImpl implements Nodes } PathInfo pathInfo = null; - if (selectParam.contains(PARAM_SELECT_PATH)) + if (selectParam.contains(PARAM_INCLUDE_PATH)) { pathInfo = lookupPathInfo(nodeRef); } @@ -719,12 +719,12 @@ public class NodesImpl implements Nodes node.setProperties(mapFromNodeProperties(properties, selectParam, mapUserInfo)); } - if (selectParam.contains(PARAM_SELECT_ASPECTNAMES)) + if (selectParam.contains(PARAM_INCLUDE_ASPECTNAMES)) { node.setAspectNames(mapFromNodeAspects(nodeService.getAspects(nodeRef))); } - if (selectParam.contains(PARAM_SELECT_ISLINK)) + if (selectParam.contains(PARAM_INCLUDE_ISLINK)) { boolean isLink = isSubClass(nodeTypeQName, ContentModel.TYPE_LINK); node.setIsLink(isLink); @@ -852,7 +852,7 @@ public class NodesImpl implements Nodes { List selectedProperties; - if ((selectParam.size() == 0) || selectParam.contains(PARAM_SELECT_PROPERTIES)) + if ((selectParam.size() == 0) || selectParam.contains(PARAM_INCLUDE_PROPERTIES)) { // return all properties selectedProperties = new ArrayList<>(nodeProps.size()); @@ -929,7 +929,7 @@ public class NodesImpl implements Nodes throw new InvalidArgumentException("NodeId of folder is expected: " + parentNodeRef.getId()); } - final List selectParam = parameters.getSelectedProperties(); + final List includeParam = parameters.getInclude(); boolean includeFolders = true; boolean includeFiles = true; @@ -1038,7 +1038,7 @@ public class NodesImpl implements Nodes FileInfo fInfo = page.get(index); // minimal info by default (unless "select"ed otherwise) - return getFolderOrDocument(fInfo.getNodeRef(), parentNodeRef, fInfo.getType(), selectParam, mapUserInfo); + return getFolderOrDocument(fInfo.getNodeRef(), parentNodeRef, fInfo.getType(), includeParam, mapUserInfo); } @Override @@ -1051,7 +1051,7 @@ public class NodesImpl implements Nodes Node sourceEntity = null; if (parameters.includeSource()) { - sourceEntity = getFolderOrDocument(parentNodeRef, null, null, selectParam, mapUserInfo); + sourceEntity = getFolderOrDocument(parentNodeRef, null, null, includeParam, mapUserInfo); } @@ -1913,7 +1913,7 @@ public class NodesImpl implements Nodes */ protected List createQNames(List qnameStrList) { - String PREFIX = PARAM_SELECT_PROPERTIES+"/"; + String PREFIX = PARAM_INCLUDE_PROPERTIES +"/"; List result = new ArrayList<>(qnameStrList.size()); for (String str : qnameStrList) diff --git a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java index 3937965e0f..f4854b475a 100644 --- a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java +++ b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java @@ -78,9 +78,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.surf.util.I18NUtil; -import org.springframework.extensions.webscripts.WebScriptException; -import javax.servlet.http.HttpServletResponse; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -184,7 +182,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean { public QuickShareLink doWork() throws Exception { - return getQuickShareInfo(sharedId, noAuth, parameters.getSelectedProperties()); + return getQuickShareInfo(sharedId, noAuth, parameters.getInclude()); } }, networkTenantDomain); } @@ -309,7 +307,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean boolean noAuth = (AuthenticationUtil.getRunAsUser() == null); - List selectParam = parameters.getSelectedProperties(); + List includeParam = parameters.getInclude(); for (QuickShareLink qs : nodeIds) { @@ -336,7 +334,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean try { QuickShareDTO qsDto = quickShareService.shareContent(nodeRef); - result.add(getQuickShareInfo(qsDto.getId(), noAuth, selectParam)); + result.add(getQuickShareInfo(qsDto.getId(), noAuth, includeParam)); } catch (InvalidNodeRefException inre) { @@ -444,12 +442,12 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean List qsLinks = new ArrayList<>(results.length()); - List selectParam = parameters.getSelectedProperties(); + List includeParam = parameters.getInclude(); for (ResultSetRow row : results) { NodeRef nodeRef = row.getNodeRef(); - qsLinks.add(getQuickShareInfo(nodeRef, false, selectParam)); + qsLinks.add(getQuickShareInfo(nodeRef, false, includeParam)); } results.close(); diff --git a/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java b/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java index f6f1662fc2..0166d1ceb9 100644 --- a/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java +++ b/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java @@ -32,7 +32,6 @@ import org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter; import org.alfresco.rest.framework.resource.content.BasicContentInfo; import org.alfresco.rest.framework.resource.parameters.where.Query; import org.apache.poi.ss.formula.functions.T; -import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.WebScriptRequest; @@ -49,7 +48,7 @@ public interface Parameters * @param parameterName String * @return String The Parameter value */ - public String getParameter(String parameterName); + String getParameter(String parameterName); /** * Gets a single request parameter passed in by the user. @@ -61,7 +60,7 @@ public interface Parameters * @return The Parameter value * @throws InvalidArgumentException */ - public T getParameter(String parameterName, Class clazz) throws InvalidArgumentException; + T getParameter(String parameterName, Class clazz) throws InvalidArgumentException; /** * Returns a representation of the Paging of collections of resources, with skip count and max items. @@ -69,21 +68,21 @@ public interface Parameters * Specified by the "skipCount" and "maxItems" request parameters. * @return Paging Paging information */ - public Paging getPaging(); + Paging getPaging(); /** * Returns a List of {@link SortColumn} for sorting properties. * Specified by the "orderBy" request parameter. * @return List of {@link SortColumn} */ - public List getSorting(); + List getSorting(); /** * Returns a {@link BeanPropertiesFilter} for filtering out properties. * Specified by the "properties" request parameter. * @return BeanPropertiesFilter {@link BeanPropertiesFilter} */ - public BeanPropertiesFilter getFilter(); + BeanPropertiesFilter getFilter(); /** * Indicates if the specified property was requested. @@ -91,13 +90,13 @@ public interface Parameters * Specified as part of the url request. * @return true if the propertyName was specified as part of the url request */ - public boolean hasBinaryProperty(String propertyName); + boolean hasBinaryProperty(String propertyName); /** * Gets the name of the property that was requested. * @return String the propertyName */ - public String getBinaryProperty(); + String getBinaryProperty(); /** * Indicates if the source entity should be includes in the request. @@ -112,24 +111,32 @@ public interface Parameters * Specified by the "WHERE" request parameter. * @return Query {@link Query} */ - public Query getQuery(); + Query getQuery(); /** * A list of property names passed in the request using the json pointer syntax * Specified by the "SELECT" request parameter. * @return List the propertyNames */ - public List getSelectedProperties(); + @Deprecated + List getSelectedProperties(); + + /** + * A list of property names passed in the request using the json pointer syntax + * Specified by the "INCLUDE" request parameter. + * @return List the propertyNames + */ + List getInclude(); /** * Gets the basic information about content, typically taken from a HTTPServletRequest. * @return BasicContentInfo the content info */ - public BasicContentInfo getContentInfo(); + BasicContentInfo getContentInfo(); /** * Gets access to the entire webscript request. * @return WebScriptRequest */ - public WebScriptRequest getRequest(); + WebScriptRequest getRequest(); } diff --git a/source/java/org/alfresco/rest/framework/resource/parameters/Params.java b/source/java/org/alfresco/rest/framework/resource/parameters/Params.java index 3ddea7484a..ffc99b759c 100644 --- a/source/java/org/alfresco/rest/framework/resource/parameters/Params.java +++ b/source/java/org/alfresco/rest/framework/resource/parameters/Params.java @@ -58,7 +58,7 @@ public class Params implements Parameters private final WebScriptRequest request; //Constants - private static final RecognizedParams NULL_PARAMS = new RecognizedParams(null, null, null, null, null, null, null, false); + private static final RecognizedParams NULL_PARAMS = new RecognizedParams(null, null, null, null, null, null, null, null, false); private static final BasicContentInfo DEFAULT_CONTENT_INFO = new ContentInfoImpl(MimetypeMap.MIMETYPE_BINARY, "UTF-8", -1, null); protected Params(String entityId, String relationshipId, Object passedIn, InputStream stream, String addressedProperty, RecognizedParams recognizedParams, BasicContentInfo contentInfo, WebScriptRequest request) @@ -76,7 +76,7 @@ public class Params implements Parameters public static Params valueOf(BeanPropertiesFilter paramFilter, String entityId, WebScriptRequest request) { - return new Params(entityId, null, null, null, null, new RecognizedParams(null, null, paramFilter, null, null, null, null, false), null, request); + return new Params(entityId, null, null, null, null, new RecognizedParams(null, null, paramFilter, null, null, null, null, null, false), null, request); } public static Params valueOf(String entityId, String relationshipId, WebScriptRequest request) @@ -170,6 +170,8 @@ public class Params implements Parameters builder.append(this.recognizedParams.query); builder.append(", sorting="); builder.append(this.recognizedParams.sorting); + builder.append(", include="); + builder.append(this.recognizedParams.include); builder.append(", select="); builder.append(this.recognizedParams.select); builder.append(", filter="); @@ -236,6 +238,12 @@ public class Params implements Parameters { return recognizedParams.select; } + + @Override + public List getInclude() + { + return recognizedParams.include; + } @Override public BasicContentInfo getContentInfo() @@ -259,21 +267,30 @@ public class Params implements Parameters private final Map relationshipFilter; private final Map requestParameters; private final Query query; - private final List select; + + private final List include; + @Deprecated + private final List select; // see include + private final List sorting; private final boolean includeSource; @SuppressWarnings("unchecked") - public RecognizedParams(Map requestParameters, Paging paging, BeanPropertiesFilter filter, Map relationshipFilter, List select, + public RecognizedParams(Map requestParameters, Paging paging, BeanPropertiesFilter filter, + Map relationshipFilter, List include, List select, Query query, List sorting, boolean includeSource) { super(); + this.requestParameters = requestParameters; this.paging = paging==null?Paging.DEFAULT:paging; this.filter = filter==null?BeanPropertiesFilter.ALLOW_ALL:filter; this.query = query==null?QueryImpl.EMPTY:query; this.relationshipFilter = (Map) (relationshipFilter==null?Collections.emptyMap():relationshipFilter); + + this.include = (List) (include==null?Collections.emptyList():include); this.select = (List) (select==null?Collections.emptyList():select); + this.sorting = (List) (sorting==null?Collections.emptyList():sorting); this.includeSource = includeSource; } diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java index c82ab9e293..79a5c1058e 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java @@ -90,7 +90,6 @@ import org.springframework.http.HttpMethod; */ public class ResourceWebScriptHelper { - private static Log logger = LogFactory.getLog(ResourceWebScriptHelper.class); public static final String PARAM_RELATIONS = "relations"; @@ -103,7 +102,10 @@ public class ResourceWebScriptHelper public static final String PARAM_PAGING_MAX = "maxItems"; public static final String PARAM_ORDERBY = "orderBy"; public static final String PARAM_WHERE = "where"; + public static final String PARAM_SELECT = "select"; + + public static final String PARAM_INCLUDE = "include"; public static final String PARAM_INCLUDE_SOURCE_ENTITY = "includeSource"; public static final List KNOWN_PARAMS = Arrays.asList( @@ -239,15 +241,32 @@ public class ResourceWebScriptHelper * @return List bean property names potentially using JSON Pointer syntax */ @SuppressWarnings("unchecked") + @Deprecated public static List getSelectClause(String selectParam) throws InvalidArgumentException { - if (selectParam == null) return Collections.emptyList(); + return getClause(selectParam, "SELECT"); + } + + /** + * Takes the "include" parameter and turns it into a List property names + * @param includeParam String + * @return List bean property names potentially using JSON Pointer syntax + */ + @SuppressWarnings("unchecked") + public static List getIncludeClause(String includeParam) throws InvalidArgumentException + { + return getClause(includeParam, "INCLUDE"); + } + + private static List getClause(String param, String paramName) + { + if (param == null) return Collections.emptyList(); try { - CommonTree selectedPropsTree = WhereCompiler.compileSelectClause(selectParam); + CommonTree selectedPropsTree = WhereCompiler.compileSelectClause(param); if (selectedPropsTree instanceof CommonErrorNode) { - logger.debug("Error parsing the SELECT clause "+selectedPropsTree); + logger.debug("Error parsing the "+paramName+" clause "+selectedPropsTree); throw new InvalidSelectException(selectedPropsTree); } if (selectedPropsTree.getChildCount() == 0 && !selectedPropsTree.getText().isEmpty()) @@ -263,13 +282,19 @@ public class ResourceWebScriptHelper } return properties; } - } catch (RewriteCardinalityException re) { //Catch any error so it doesn't get thrown up the stack - logger.debug("Unhandled Error parsing the SELECT clause: "+re); - } catch (RecognitionException e) { - logger.debug("Error parsing the SELECT clause: "+selectParam); } + catch (RewriteCardinalityException re) + { + //Catch any error so it doesn't get thrown up the stack + logger.debug("Unhandled Error parsing the "+paramName+" clause: "+re); + } + catch (RecognitionException e) + { + logger.debug("Error parsing the \"+paramName+\" clause: "+param); + } + //Default to throw out an invalid query - throw new InvalidSelectException(selectParam); + throw new InvalidSelectException(param); } /** @@ -603,7 +628,7 @@ public class ResourceWebScriptHelper * the ExecutionResult object. * * @param api Api - * @param filters Map + * @param params Params * @param relatedResources Map * @param uniqueEntityId String * @return Map @@ -629,7 +654,7 @@ public class ResourceWebScriptHelper * the ExecutionResult object. * * @param api Api - * @param filters Map + * @param params Params * @param uniqueEntityId String * @param resourceKey String * @param resource ResourceWithMetadata @@ -722,7 +747,8 @@ public class ResourceWebScriptHelper Map requestParams = getRequestParameters(req); boolean includeSource = Boolean.valueOf(req.getParameter(ResourceWebScriptHelper.PARAM_INCLUDE_SOURCE_ENTITY)); - List theSelect = getSelectClause(req.getParameter(ResourceWebScriptHelper.PARAM_SELECT)); + List includedFields = getIncludeClause(req.getParameter(ResourceWebScriptHelper.PARAM_INCLUDE)); + List selectFields = getSelectClause(req.getParameter(ResourceWebScriptHelper.PARAM_SELECT)); String fields = req.getParameter(ResourceWebScriptHelper.PARAM_FILTER_FIELDS); String properties = req.getParameter(ResourceWebScriptHelper.PARAM_FILTER_PROPERTIES); @@ -735,9 +761,9 @@ public class ResourceWebScriptHelper } } - BeanPropertiesFilter filter = getFilter((fields != null ? fields : properties), theSelect); - - return new RecognizedParams(requestParams, paging, filter, relationFilter, theSelect, whereQuery, sorting, includeSource); + BeanPropertiesFilter filter = getFilter((fields != null ? fields : properties), includedFields); + + return new RecognizedParams(requestParams, paging, filter, relationFilter, includedFields, selectFields, whereQuery, sorting, includeSource); } /** 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 ed7811d322..a66c4777a2 100644 --- a/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/NodeApiTest.java @@ -366,7 +366,7 @@ public class NodeApiTest extends AbstractBaseApiTest assertNotNull(node.getContent().getEncoding()); assertTrue(node.getContent().getSizeInBytes() > 0); - // request without select + // request without "include" Map params = new HashMap<>(); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); @@ -378,9 +378,9 @@ public class NodeApiTest extends AbstractBaseApiTest assertNull("There shouldn't be a 'aspectNames' object in the response.", n.getAspectNames()); } - // request with select - example 1 + // request with include - example 1 params = new HashMap<>(); - params.put("select", "isLink"); + params.put("include", "isLink"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); for (Node n : nodes) @@ -388,9 +388,9 @@ public class NodeApiTest extends AbstractBaseApiTest assertNotNull("There should be a 'isLink' object in the response.", n.getIsLink()); } - // request with select - example 2 + // request with include - example 2 params = new HashMap<>(); - params.put("select", "aspectNames,properties, path,isLink"); + params.put("include", "aspectNames,properties, path,isLink"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); for (Node n : nodes) @@ -401,9 +401,9 @@ public class NodeApiTest extends AbstractBaseApiTest assertNotNull("There should be a 'aspectNames' object in the response.", n.getAspectNames()); } - // request specific property via select + // request specific property via include params = new HashMap<>(); - params.put("select", "cm:lastThumbnailModification"); + params.put("include", "cm:lastThumbnailModification"); params.put("orderBy", "isFolder DESC,modifiedAt DESC"); response = getAll(myChildrenUrl, user1, paging, params, 200); nodes = jacksonUtil.parseEntries(response.getJsonResponse(), Document.class); @@ -522,7 +522,7 @@ public class NodeApiTest extends AbstractBaseApiTest /** * Tests get node with path information. *

GET:

- * {@literal :/alfresco/api//public/alfresco/versions/1/nodes/?select=path} + * {@literal :/alfresco/api//public/alfresco/versions/1/nodes/?include=path} */ @Test public void testGetPathElements_DocLib() throws Exception @@ -559,8 +559,8 @@ public class NodeApiTest extends AbstractBaseApiTest // Grant userTwoN1 permission for folderC permissionService.setPermission(folderC_Ref, userTwoN1.getId(), PermissionService.CONSUMER, true); - //...nodes/nodeId?select=path - Map params = Collections.singletonMap("select", "path"); + //...nodes/nodeId?include=path + Map params = Collections.singletonMap("include", "path"); HttpResponse response = getSingle(NodesEntityResource.class, userOneN1.getId(), content1_Id, params, 200); Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); PathInfo path = node.getPath(); @@ -673,8 +673,8 @@ public class NodeApiTest extends AbstractBaseApiTest d1.expected(documentResp); // get node info + path - //...nodes/nodeId?select=path - Map params = Collections.singletonMap("select", "path"); + //...nodes/nodeId?include=path + Map params = Collections.singletonMap("include", "path"); response = getSingle(NodesEntityResource.class, user1, content1Id, params, 200); documentResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); @@ -760,7 +760,7 @@ public class NodeApiTest extends AbstractBaseApiTest assertEquals(user1, node.getName()); assertTrue(node.getIsFolder()); assertFalse(node.getIsFile()); - assertNull(node.getPath()); // note: path can be optionally "select"'ed - see separate test + assertNull(node.getPath()); // note: path can be optionally "include"'ed - see separate test response = getSingle(NodesEntityResource.class, user1, Nodes.PATH_SHARED, null, 200); node = jacksonUtil.parseEntry(response.getJsonResponse(), Node.class); @@ -814,7 +814,7 @@ public class NodeApiTest extends AbstractBaseApiTest // Default encoding assertEquals("UTF-8", contentInfo.getEncoding()); // Check there is no path info returned. - // The path info should only be returned when it is requested via a select statement. + // The path info should only be returned when it is requested via a include statement. assertNull(document.getPath()); // Retrieve the uploaded file @@ -850,7 +850,7 @@ public class NodeApiTest extends AbstractBaseApiTest assertEquals("quick-1.pdf", document.getName()); // upload the same file again, and request the path info to be present in the response - response = post(getChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), "?select=path", reqBody.getContentType(), 201); + response = post(getChildrenUrl(Nodes.PATH_MY), user1, reqBody.getBody(), "?include=path", reqBody.getContentType(), 201); document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); // Check the upload response assertEquals("quick-2.pdf", document.getName()); @@ -2151,7 +2151,7 @@ public class NodeApiTest extends AbstractBaseApiTest File pdfFile = getResourceFile("quick.pdf"); payload = new BinaryPayload(pdfFile, MimetypeMap.MIMETYPE_PDF, "ISO-8859-1"); - response = putBinary(url + "?select=path", user1, payload, null, null, 200); + response = putBinary(url + "?include=path", user1, payload, null, null, 200); docResp = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class); assertEquals(docName, docResp.getName()); assertNotNull(docResp.getContent()); diff --git a/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java b/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java index c229f1ae49..9c3dd1f33c 100644 --- a/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/SharedLinkApiTest.java @@ -183,7 +183,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest // auth access to get shared link info - as user1 - Map params = Collections.singletonMap("select", "allowableOperations"); + Map params = Collections.singletonMap("include", "allowableOperations"); response = getSingle(QuickShareLinkEntityResource.class, user1, sharedId, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); @@ -197,7 +197,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertNull(resp.getAllowableOperations()); // auth access to get shared link info - as user2 - params = Collections.singletonMap("select", "allowableOperations"); + params = Collections.singletonMap("include", "allowableOperations"); response = getSingle(QuickShareLinkEntityResource.class, user2, sharedId, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); @@ -211,21 +211,21 @@ public class SharedLinkApiTest extends AbstractBaseApiTest assertEquals(1, resp.getAllowableOperations().size()); assertEquals("delete", resp.getAllowableOperations().get(0)); - // allowable operations not selected + // allowable operations not included response = getSingle(QuickShareLinkEntityResource.class, user2, sharedId, null, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertNull(resp.getAllowableOperations()); // unauth access to get shared link info - params = Collections.singletonMap("select", "allowableOperations"); // note: this will be ignore for unauth access + params = Collections.singletonMap("include", "allowableOperations"); // note: this will be ignore for unauth access response = getSingle(QuickShareLinkEntityResource.class, null, sharedId, params, 200); resp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), QuickShareLink.class); assertEquals(sharedId, resp.getId()); assertEquals(docName1, resp.getName()); assertNull(resp.getNodeId()); // nodeId not returned - assertNull(resp.getAllowableOperations()); // select is ignored + assertNull(resp.getAllowableOperations()); // include is ignored assertNull(resp.getModifiedByUser().getId()); // userId not returned assertEquals(user1+" "+user1, resp.getModifiedByUser().getDisplayName()); diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/AbstractContextTest.java b/source/test-java/org/alfresco/rest/framework/tests/core/AbstractContextTest.java index f50ebd1840..71ae1f8755 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/AbstractContextTest.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/AbstractContextTest.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2005-2016 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ package org.alfresco.rest.framework.tests.core; import static org.mockito.Matchers.any; @@ -51,7 +69,7 @@ public abstract class AbstractContextTest JacksonHelper jsonHelper; static Params NOT_USED = Params.valueOf("notUsed", null, mock(WebScriptRequest.class)); - static final Params.RecognizedParams NULL_PARAMS = new Params.RecognizedParams(null, null, null, null, null, null, null, false); + static final Params.RecognizedParams NULL_PARAMS = new Params.RecognizedParams(null, null, null, null, null, null, null, null, false); static final WithResponse callBack = new WithResponse(Status.STATUS_OK, ApiWebScript.DEFAULT_JSON_CONTENT,ApiWebScript.CACHE_NEVER); static Api api = Api.valueOf("alfrescomock", "private", "1"); diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/ParamsExtender.java b/source/test-java/org/alfresco/rest/framework/tests/core/ParamsExtender.java index 9be8786920..00d37bd6ea 100755 --- a/source/test-java/org/alfresco/rest/framework/tests/core/ParamsExtender.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/ParamsExtender.java @@ -50,22 +50,22 @@ public class ParamsExtender extends Params public static Params valueOf(Map rFilter, String entityId) { - return new ParamsExtender(entityId, null, null, null, null, new Params.RecognizedParams(null, null, null, rFilter, null, null, null, false)); + return new ParamsExtender(entityId, null, null, null, null, new Params.RecognizedParams(null, null, null, rFilter, null, null, null, null, false)); } public static Params valueOf(boolean includeSource, String entityId) { - return new ParamsExtender(entityId, null, null, null, null, new Params.RecognizedParams(null, null, null, null, null, null, null, includeSource)); + return new ParamsExtender(entityId, null, null, null, null, new Params.RecognizedParams(null, null, null, null, null, null, null, null, includeSource)); } public static Params valueOf(Paging paging, String entityId) { - return new ParamsExtender(entityId, null, null, null, null, new Params.RecognizedParams(null, paging, null, null, null, null, null, false)); + return new ParamsExtender(entityId, null, null, null, null, new Params.RecognizedParams(null, paging, null, null, null, null, null, null, false)); } public static Params valueOf(Map params) { - return new ParamsExtender(null, null, null, null, null, new Params.RecognizedParams(params, null, null, null, null, null, null, false)); + return new ParamsExtender(null, null, null, null, null, new Params.RecognizedParams(params, null, null, null, null, null, null, null, false)); } } diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/ResourceWebScriptHelperTests.java b/source/test-java/org/alfresco/rest/framework/tests/core/ResourceWebScriptHelperTests.java index 9e2ce5eb49..a6a73164d8 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/ResourceWebScriptHelperTests.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/ResourceWebScriptHelperTests.java @@ -171,16 +171,28 @@ public class ResourceWebScriptHelperTests assertTrue(theSort.get(0).asc); } + @Test + public void getIncludeClauseTest() + { + getClauseTest("include"); + } + @Test public void getSelectClauseTest() { - List theSelect = ResourceWebScriptHelper.getSelectClause(null); - assertNotNull(theSelect); - assertFalse("Null passed in so nothing in the Select.",theSelect.size() > 0); + getClauseTest("select"); + } + + // at the moment select and include are parsed the same way, hence common/shared test + private void getClauseTest(String paramName) + { + List theClause = getClause(paramName, null); + assertNotNull(theClause); + assertFalse("Null passed in so nothing in the "+paramName, theClause.size() > 0); try { - theSelect = ResourceWebScriptHelper.getSelectClause(",,,"); + theClause = getClause(paramName, ",,,"); fail("Should throw an InvalidSelectException"); } catch (InvalidSelectException error) @@ -190,7 +202,7 @@ public class ResourceWebScriptHelperTests try { - theSelect = ResourceWebScriptHelper.getSelectClause("(,,,"); + theClause = getClause(paramName, "(,,,"); fail("Should throw an InvalidSelectException"); } catch (InvalidSelectException error) @@ -200,7 +212,7 @@ public class ResourceWebScriptHelperTests try { - theSelect = ResourceWebScriptHelper.getSelectClause("(,,,)"); + theClause = getClause(paramName, "(,,,)"); fail("Should throw an InvalidSelectException"); } catch (InvalidSelectException error) @@ -210,7 +222,7 @@ public class ResourceWebScriptHelperTests try { - theSelect = ResourceWebScriptHelper.getSelectClause("x/,z"); + theClause = getClause(paramName, "x/,z"); fail("Should throw an InvalidSelectException"); } catch (InvalidArgumentException error) @@ -220,7 +232,7 @@ public class ResourceWebScriptHelperTests try { - theSelect = ResourceWebScriptHelper.getSelectClause("/x'n,/z"); + theClause = getClause(paramName, "/x'n,/z"); fail("Should throw an InvalidSelectException"); } catch (InvalidArgumentException error) @@ -230,7 +242,7 @@ public class ResourceWebScriptHelperTests try { - theSelect = ResourceWebScriptHelper.getSelectClause("/foo/0"); + theClause = getClause(paramName, "/foo/0"); fail("Should throw an InvalidSelectException. Legal identifiers must start with a letter not zero"); } catch (InvalidArgumentException error) @@ -240,7 +252,7 @@ public class ResourceWebScriptHelperTests try { - theSelect = ResourceWebScriptHelper.getSelectClause("/"); + theClause = getClause(paramName, "/"); fail("Should throw an InvalidSelectException. No identifier specified."); } catch (InvalidArgumentException error) @@ -248,56 +260,71 @@ public class ResourceWebScriptHelperTests //this is correct } - theSelect = ResourceWebScriptHelper.getSelectClause("king/kong"); - assertTrue("has a valid select",theSelect.size() == 1); - assertEquals("king/kong",theSelect.get(0)); + theClause = getClause(paramName, "king/kong"); + assertTrue("has a valid "+paramName, theClause.size() == 1); + assertEquals("king/kong",theClause.get(0)); - theSelect = ResourceWebScriptHelper.getSelectClause("x,y"); - assertTrue("has a valid select",theSelect.size() == 2); - assertEquals("x",theSelect.get(0)); - assertEquals("y",theSelect.get(1)); + theClause = getClause(paramName, "x,y"); + assertTrue("has a valid "+paramName, theClause.size() == 2); + assertEquals("x",theClause.get(0)); + assertEquals("y",theClause.get(1)); - theSelect = ResourceWebScriptHelper.getSelectClause("x,/z"); - assertTrue("has a valid select",theSelect.size() == 2); - assertEquals("x",theSelect.get(0)); - assertEquals("/z",theSelect.get(1)); + theClause = getClause(paramName, "x,/z"); + assertTrue("has a valid "+paramName, theClause.size() == 2); + assertEquals("x",theClause.get(0)); + assertEquals("/z",theClause.get(1)); - theSelect = ResourceWebScriptHelper.getSelectClause("/b"); - assertTrue("has a valid select",theSelect.size() == 1); - assertEquals("/b",theSelect.get(0)); + theClause = getClause(paramName, "/b"); + assertTrue("has a valid "+paramName, theClause.size() == 1); + assertEquals("/b",theClause.get(0)); - theSelect = ResourceWebScriptHelper.getSelectClause("/be,/he"); - assertTrue("has a valid select",theSelect.size() == 2); - assertEquals("/be",theSelect.get(0)); - assertEquals("/he",theSelect.get(1)); + theClause = getClause(paramName, "/be,/he"); + assertTrue("has a valid "+paramName, theClause.size() == 2); + assertEquals("/be",theClause.get(0)); + assertEquals("/he",theClause.get(1)); - theSelect = ResourceWebScriptHelper.getSelectClause("/king/kong"); - assertTrue("has a valid select",theSelect.size() == 1); - assertEquals("/king/kong",theSelect.get(0)); + theClause = getClause(paramName, "/king/kong"); + assertTrue("has a valid "+paramName, theClause.size() == 1); + assertEquals("/king/kong",theClause.get(0)); - theSelect = ResourceWebScriptHelper.getSelectClause("/name,/person/age"); - assertTrue("has a valid select",theSelect.size() == 2); - assertEquals("/name",theSelect.get(0)); - assertEquals("/person/age",theSelect.get(1)); + theClause = getClause(paramName, "/name,/person/age"); + assertTrue("has a valid "+paramName, theClause.size() == 2); + assertEquals("/name",theClause.get(0)); + assertEquals("/person/age",theClause.get(1)); - theSelect = ResourceWebScriptHelper.getSelectClause("/foo"); - assertTrue("has a valid select",theSelect.size() == 1); - assertEquals("/foo",theSelect.get(0)); + theClause = getClause(paramName, "/foo"); + assertTrue("has a valid select",theClause.size() == 1); + assertEquals("/foo",theClause.get(0)); - theSelect = ResourceWebScriptHelper.getSelectClause("/foo/anArray/x"); - assertTrue("has a valid select",theSelect.size() == 1); - assertEquals("/foo/anArray/x",theSelect.get(0)); + theClause = getClause(paramName, "/foo/anArray/x"); + assertTrue("has a valid "+paramName, theClause.size() == 1); + assertEquals("/foo/anArray/x",theClause.get(0)); - theSelect = ResourceWebScriptHelper.getSelectClause("/foo/anArray/x,/person/age,/eggs/bacon/sausage,/p"); - assertTrue("has a valid select",theSelect.size() == 4); - assertEquals("/foo/anArray/x",theSelect.get(0)); - assertEquals("/person/age",theSelect.get(1)); - assertEquals("/eggs/bacon/sausage",theSelect.get(2)); - assertEquals("/p",theSelect.get(3)); + theClause = getClause(paramName, "/foo/anArray/x,/person/age,/eggs/bacon/sausage,/p"); + assertTrue("has a valid "+paramName, theClause.size() == 4); + assertEquals("/foo/anArray/x",theClause.get(0)); + assertEquals("/person/age",theClause.get(1)); + assertEquals("/eggs/bacon/sausage",theClause.get(2)); + assertEquals("/p",theClause.get(3)); - theSelect = ResourceWebScriptHelper.getSelectClause("/foo/_bar "); - assertTrue("has a valid select",theSelect.size() == 1); - assertEquals("/foo/_bar",theSelect.get(0)); + theClause = getClause(paramName, "/foo/_bar "); + assertTrue("has a valid "+paramName, theClause.size() == 1); + assertEquals("/foo/_bar",theClause.get(0)); + } + + private List getClause(String paramName, String paramValue) + { + if (paramName.equalsIgnoreCase("include")) + { + return ResourceWebScriptHelper.getIncludeClause(paramValue); + } + else if (paramName.equalsIgnoreCase("select")) + { + return ResourceWebScriptHelper.getSelectClause(paramValue); + } + + fail("Unexpected clause: "+paramName); + return null; } @Test diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java b/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java index fca2b15cb0..14848705e4 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java @@ -28,39 +28,26 @@ package org.alfresco.rest.framework.tests.core; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import org.alfresco.repo.content.MimetypeMap; -import org.alfresco.repo.transaction.RetryingTransactionHelper; -import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.rest.api.tests.util.MultiPartBuilder; import org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData; import org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest; import org.alfresco.rest.framework.Api; -import org.alfresco.rest.framework.core.ResourceDictionaryBuilder; -import org.alfresco.rest.framework.core.ResourceLookupDictionary; import org.alfresco.rest.framework.core.ResourceWithMetadata; import org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException; import org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter; import org.alfresco.rest.framework.jacksonextensions.ExecutionResult; -import org.alfresco.rest.framework.jacksonextensions.JacksonHelper; import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer; -import org.alfresco.rest.framework.resource.EntityResource; -import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read; import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById; import org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.content.BinaryProperty; -import org.alfresco.rest.framework.resource.content.BinaryResource; -import org.alfresco.rest.framework.resource.content.ContentInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Paging; import org.alfresco.rest.framework.resource.parameters.Params; @@ -73,7 +60,6 @@ import org.alfresco.rest.framework.tests.api.mocks3.SlimGoat; import org.alfresco.rest.framework.webscripts.AbstractResourceWebScript; import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.GUID; import org.alfresco.util.TempFileProvider; import org.apache.commons.lang.StringUtils; @@ -85,21 +71,12 @@ import org.codehaus.jackson.schema.JsonSchema; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; import org.springframework.extensions.webscripts.Format; -import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptResponse; import org.springframework.extensions.webscripts.servlet.FormData; import org.springframework.http.HttpMethod; import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.io.ByteArrayOutputStream; import java.io.File; @@ -474,9 +451,9 @@ public class SerializeTests extends AbstractContextTest assertEquals("The name should be 'Dolly'", "Dolly", entry.getString("name")); assertTrue("The age should be 3", entry.getInt("age") == 3); - // unit test filter with select taking precendence - List theSelect = ResourceWebScriptHelper.getSelectClause("name"); - theFilter = ResourceWebScriptHelper.getFilter("age", theSelect); + // unit test filter with "include" taking precendence over "fields" filter + List theInclude = ResourceWebScriptHelper.getIncludeClause("name"); + theFilter = ResourceWebScriptHelper.getFilter("age", theInclude); res = new ExecutionResult(new Sheep("bob"),theFilter); out = writeResponse(res); jsonRsp = new JSONObject(new JSONTokener(out)); diff --git a/source/test-java/org/alfresco/rest/test/workflow/api/impl/ProcessesImplTest.java b/source/test-java/org/alfresco/rest/test/workflow/api/impl/ProcessesImplTest.java index 1c619f0c96..eff4aa603f 100644 --- a/source/test-java/org/alfresco/rest/test/workflow/api/impl/ProcessesImplTest.java +++ b/source/test-java/org/alfresco/rest/test/workflow/api/impl/ProcessesImplTest.java @@ -223,7 +223,7 @@ public class ProcessesImplTest extends TestCase private CollectionWithPagingInfo queryActiveProcessesAndAssertResult(int skipCount, int maxItems) { Query query = ResourceWebScriptHelper.getWhereClause(QUERY_STATUS_ACTIVE); - Parameters parameters = Params.valueOf(new RecognizedParams(null, Paging.valueOf(skipCount, maxItems), null, null, null, query, null, false), null, null, null); + Parameters parameters = Params.valueOf(new RecognizedParams(null, Paging.valueOf(skipCount, maxItems), null, null, null, null, query, null, false), null, null, null); CollectionWithPagingInfo result = processes.getProcesses(parameters);