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/HEAD/root@126520 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:19:16 +00:00
parent f5212b0c8c
commit a2541568a8
13 changed files with 282 additions and 158 deletions

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.resource.parameters;
import java.util.List;
@@ -7,7 +25,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;
@@ -24,7 +41,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.
@@ -36,7 +53,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.
@@ -44,21 +61,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.
@@ -66,13 +83,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.
@@ -87,24 +104,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

@@ -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.resource.parameters;
import java.io.InputStream;
@@ -33,7 +51,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)
@@ -51,7 +69,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)
@@ -145,6 +163,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=");
@@ -211,6 +231,12 @@ public class Params implements Parameters
{
return recognizedParams.select;
}
@Override
public List<String> getInclude()
{
return recognizedParams.include;
}
@Override
public BasicContentInfo getContentInfo()
@@ -234,21 +260,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

@@ -82,7 +82,6 @@ import org.springframework.http.HttpMethod;
*/
public class ResourceWebScriptHelper
{
private static Log logger = LogFactory.getLog(ResourceWebScriptHelper.class);
public static final String PARAM_RELATIONS = "relations";
@@ -95,7 +94,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(
@@ -231,15 +233,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())
@@ -255,13 +274,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);
}
/**
@@ -595,7 +620,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
@@ -621,7 +646,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
@@ -714,7 +739,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);
@@ -727,9 +753,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);
}
/**