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

126520 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
      122978 jvonka: RA-766: Update REST fwk - implement "include" query param (used by nodes & shared-links) and deprecate "select" (still used by tasks & cmm).


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126864 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Ancuta Morarasu
2016-05-11 11:58:26 +00:00
parent bb219d0916
commit 0f836e8090
13 changed files with 228 additions and 158 deletions

View File

@@ -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";

View File

@@ -655,14 +655,14 @@ public class NodesImpl implements Nodes
private Node getFolderOrDocumentFullInfo(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, Parameters parameters)
{
List<String> selectParam = new ArrayList<>();
selectParam.addAll(parameters.getSelectedProperties());
List<String> 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<String> selectParam, Map<String,UserInfo> 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<QName> 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<String> selectParam = parameters.getSelectedProperties();
final List<String> 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<QName> createQNames(List<String> qnameStrList)
{
String PREFIX = PARAM_SELECT_PROPERTIES+"/";
String PREFIX = PARAM_INCLUDE_PROPERTIES +"/";
List<QName> result = new ArrayList<>(qnameStrList.size());
for (String str : qnameStrList)

View File

@@ -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<String> selectParam = parameters.getSelectedProperties();
List<String> 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<QuickShareLink> qsLinks = new ArrayList<>(results.length());
List<String> selectParam = parameters.getSelectedProperties();
List<String> 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();

View File

@@ -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<T> clazz) throws InvalidArgumentException;
T getParameter(String parameterName, Class<T> 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<SortColumn> getSorting();
List<SortColumn> 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<String> the propertyNames
*/
public List<String> getSelectedProperties();
@Deprecated
List<String> getSelectedProperties();
/**
* A list of property names passed in the request using the json pointer syntax
* Specified by the "INCLUDE" request parameter.
* @return List<String> the propertyNames
*/
List<String> 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();
}

View File

@@ -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=");
@@ -237,6 +239,12 @@ public class Params implements Parameters
return recognizedParams.select;
}
@Override
public List<String> getInclude()
{
return recognizedParams.include;
}
@Override
public BasicContentInfo getContentInfo()
{
@@ -259,21 +267,30 @@ public class Params implements Parameters
private final Map<String, BeanPropertiesFilter> relationshipFilter;
private final Map<String, String[]> requestParameters;
private final Query query;
private final List<String> select;
private final List<String> include;
@Deprecated
private final List<String> select; // see include
private final List<SortColumn> sorting;
private final boolean includeSource;
@SuppressWarnings("unchecked")
public RecognizedParams(Map<String, String[]> requestParameters, Paging paging, BeanPropertiesFilter filter, Map<String, BeanPropertiesFilter> relationshipFilter, List<String> select,
public RecognizedParams(Map<String, String[]> requestParameters, Paging paging, BeanPropertiesFilter filter,
Map<String, BeanPropertiesFilter> relationshipFilter, List<String> include, List<String> select,
Query query, List<SortColumn> 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<String, BeanPropertiesFilter>) (relationshipFilter==null?Collections.emptyMap():relationshipFilter);
this.include = (List<String>) (include==null?Collections.emptyList():include);
this.select = (List<String>) (select==null?Collections.emptyList():select);
this.sorting = (List<SortColumn>) (sorting==null?Collections.emptyList():sorting);
this.includeSource = includeSource;
}

View File

@@ -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<String> KNOWN_PARAMS = Arrays.asList(
@@ -239,15 +241,32 @@ public class ResourceWebScriptHelper
* @return List<String> bean property names potentially using JSON Pointer syntax
*/
@SuppressWarnings("unchecked")
@Deprecated
public static List<String> 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<String> property names
* @param includeParam String
* @return List<String> bean property names potentially using JSON Pointer syntax
*/
@SuppressWarnings("unchecked")
public static List<String> getIncludeClause(String includeParam) throws InvalidArgumentException
{
return getClause(includeParam, "INCLUDE");
}
private static List<String> 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<String, BeanPropertiesFilter>
* @param params Params
* @param relatedResources Map<String, ResourceWithMetadata>
* @param uniqueEntityId String
* @return Map
@@ -629,7 +654,7 @@ public class ResourceWebScriptHelper
* the ExecutionResult object.
*
* @param api Api
* @param filters Map<String, BeanPropertiesFilter>
* @param params Params
* @param uniqueEntityId String
* @param resourceKey String
* @param resource ResourceWithMetadata
@@ -722,7 +747,8 @@ public class ResourceWebScriptHelper
Map<String, String[]> requestParams = getRequestParameters(req);
boolean includeSource = Boolean.valueOf(req.getParameter(ResourceWebScriptHelper.PARAM_INCLUDE_SOURCE_ENTITY));
List<String> theSelect = getSelectClause(req.getParameter(ResourceWebScriptHelper.PARAM_SELECT));
List<String> includedFields = getIncludeClause(req.getParameter(ResourceWebScriptHelper.PARAM_INCLUDE));
List<String> 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);
BeanPropertiesFilter filter = getFilter((fields != null ? fields : properties), includedFields);
return new RecognizedParams(requestParams, paging, filter, relationFilter, theSelect, whereQuery, sorting, includeSource);
return new RecognizedParams(requestParams, paging, filter, relationFilter, includedFields, selectFields, whereQuery, sorting, includeSource);
}
/**

View File

@@ -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<String, String> 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.
* <p>GET:</p>
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>?select=path}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>?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<String, String> params = Collections.singletonMap("select", "path");
//...nodes/nodeId?include=path
Map<String, String> 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<String, String> params = Collections.singletonMap("select", "path");
//...nodes/nodeId?include=path
Map<String, String> 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());

View File

@@ -183,7 +183,7 @@ public class SharedLinkApiTest extends AbstractBaseApiTest
// auth access to get shared link info - as user1
Map<String, String> params = Collections.singletonMap("select", "allowableOperations");
Map<String, String> 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());

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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");

View File

@@ -50,22 +50,22 @@ public class ParamsExtender extends Params
public static Params valueOf(Map<String, BeanPropertiesFilter> 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<String, String[]> 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));
}
}

View File

@@ -171,16 +171,28 @@ public class ResourceWebScriptHelperTests
assertTrue(theSort.get(0).asc);
}
@Test
public void getIncludeClauseTest()
{
getClauseTest("include");
}
@Test
public void getSelectClauseTest()
{
List<String> 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<String> 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<String> 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

View File

@@ -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<String> theSelect = ResourceWebScriptHelper.getSelectClause("name");
theFilter = ResourceWebScriptHelper.getFilter("age", theSelect);
// unit test filter with "include" taking precendence over "fields" filter
List<String> 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));

View File

@@ -223,7 +223,7 @@ public class ProcessesImplTest extends TestCase
private CollectionWithPagingInfo<ProcessInfo> 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<ProcessInfo> result = processes.getProcesses(parameters);