mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged searchapi (5.2.1) to 5.2.N (5.2.1)
129777 gjames: Reformatted to Alfresco standards git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130168 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.framework.tools;
|
||||
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
@@ -74,16 +75,18 @@ public interface RecognizedParamsExtractor
|
||||
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(
|
||||
PARAM_RELATIONS, PARAM_FILTER_PROPERTIES, PARAM_FILTER_FIELDS,PARAM_PAGING_SKIP,PARAM_PAGING_MAX,
|
||||
PARAM_ORDERBY, PARAM_WHERE, PARAM_SELECT, PARAM_INCLUDE_SOURCE_ENTITY);
|
||||
public static final List<String> KNOWN_PARAMS = Arrays
|
||||
.asList(PARAM_RELATIONS, PARAM_FILTER_PROPERTIES, PARAM_FILTER_FIELDS, PARAM_PAGING_SKIP, PARAM_PAGING_MAX, PARAM_ORDERBY,
|
||||
PARAM_WHERE, PARAM_SELECT, PARAM_INCLUDE_SOURCE_ENTITY);
|
||||
|
||||
default Log rpeLogger() {
|
||||
default Log rpeLogger()
|
||||
{
|
||||
return LogFactory.getLog(this.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the formal set of params that any rest service could potentially have passed in as request params
|
||||
*
|
||||
* @param req WebScriptRequest
|
||||
* @return RecognizedParams a POJO containing the params for use with the Params objects
|
||||
*/
|
||||
@@ -112,38 +115,27 @@ public interface RecognizedParamsExtractor
|
||||
|
||||
BeanPropertiesFilter filter = getFilter((fields != null ? fields : properties), includedFields);
|
||||
|
||||
return new Params.RecognizedParams(requestParams, paging, filter, relationFilter, includedFields, selectFields, whereQuery, sorting, includeSource);
|
||||
return new Params.RecognizedParams(requestParams, paging, filter, relationFilter, includedFields, selectFields, whereQuery, sorting,
|
||||
includeSource);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes the web request and looks for a "fields" parameter (otherwise deprecated "properties" parameter).
|
||||
*
|
||||
* Parses the parameter and produces a list of bean properties to use as a filter A
|
||||
* SimpleBeanPropertyFilter it returned that uses the bean properties. If no
|
||||
* filter param is set then a default BeanFilter is returned that will never
|
||||
* filter fields (ie. Returns all bean properties).
|
||||
*
|
||||
* If selectList is provided then it will take precedence (ie. be included) over the fields/properties filter
|
||||
* for top-level entries (bean properties).
|
||||
*
|
||||
* For example, this will return entries from both select & properties, eg.
|
||||
*
|
||||
* select=abc,def&properties=id,name,ghi
|
||||
*
|
||||
* Note: it should be noted that API-generic "fields" clause does not currently work for sub-entries.
|
||||
*
|
||||
* Hence, even if the API-specific "select" clause allows selection of a sub-entries this cannot be used
|
||||
* with "fields" filtering. For example, an API-specific method may implement and return "abc/blah", eg.
|
||||
*
|
||||
* select=abc/blah
|
||||
*
|
||||
* However the following will not return "abc/blah" if used with fields filtering, eg.
|
||||
*
|
||||
* select=abc/blah&fields=id,name,ghi
|
||||
*
|
||||
* If fields filtering is desired then it would require "abc" to be selected and returned as a whole, eg.
|
||||
*
|
||||
* select=abc&fields=id,name,ghi
|
||||
*
|
||||
* @param filterParams
|
||||
@@ -178,9 +170,9 @@ public interface RecognizedParamsExtractor
|
||||
return BeanPropertiesFilter.ALLOW_ALL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes the "select" parameter and turns it into a List<String> property names
|
||||
*
|
||||
* @param selectParam String
|
||||
* @return bean property names potentially using JSON Pointer syntax
|
||||
*/
|
||||
@@ -193,6 +185,7 @@ public interface RecognizedParamsExtractor
|
||||
|
||||
/**
|
||||
* Takes the "include" parameter and turns it into a List<String> property names
|
||||
*
|
||||
* @param includeParam String
|
||||
* @return bean property names potentially using JSON Pointer syntax
|
||||
*/
|
||||
@@ -204,15 +197,18 @@ public interface RecognizedParamsExtractor
|
||||
|
||||
/**
|
||||
* Gets the clause specificed in paramName
|
||||
*
|
||||
* @param param
|
||||
* @param paramName
|
||||
* @return bean property names potentially using JSON Pointer syntax
|
||||
*/
|
||||
default List<String> getClause(String param, String paramName)
|
||||
{
|
||||
if (param == null) return Collections.emptyList();
|
||||
if (param == null)
|
||||
return Collections.emptyList();
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
CommonTree selectedPropsTree = WhereCompiler.compileSelectClause(param);
|
||||
if (selectedPropsTree instanceof CommonErrorNode)
|
||||
{
|
||||
@@ -227,7 +223,8 @@ public interface RecognizedParamsExtractor
|
||||
if (children != null && !children.isEmpty())
|
||||
{
|
||||
List<String> properties = new ArrayList<String>(children.size());
|
||||
for (Tree child : children) {
|
||||
for (Tree child : children)
|
||||
{
|
||||
properties.add(child.getText());
|
||||
}
|
||||
return properties;
|
||||
@@ -252,14 +249,17 @@ public interface RecognizedParamsExtractor
|
||||
|
||||
/**
|
||||
* Takes the "where" parameter and turns it into a Java Object that can be used for querying
|
||||
*
|
||||
* @param whereParam String
|
||||
* @return Query a parsed version of the where clause, represented in Java
|
||||
*/
|
||||
default Query getWhereClause(String whereParam) throws InvalidQueryException
|
||||
{
|
||||
if (whereParam == null) return QueryImpl.EMPTY;
|
||||
if (whereParam == null)
|
||||
return QueryImpl.EMPTY;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
CommonTree whereTree = WhereCompiler.compileWhereClause(whereParam);
|
||||
if (whereTree instanceof CommonErrorNode)
|
||||
{
|
||||
@@ -267,9 +267,13 @@ public interface RecognizedParamsExtractor
|
||||
throw new InvalidQueryException(whereTree);
|
||||
}
|
||||
return new QueryImpl(whereTree);
|
||||
} catch (RewriteCardinalityException re) { //Catch any error so it doesn't get thrown up the stack
|
||||
}
|
||||
catch (RewriteCardinalityException re)
|
||||
{ //Catch any error so it doesn't get thrown up the stack
|
||||
rpeLogger().info("Unhandled Error parsing the WHERE clause: " + re);
|
||||
} catch (RecognitionException e) {
|
||||
}
|
||||
catch (RecognitionException e)
|
||||
{
|
||||
whereParam += ", " + WhereCompiler.resolveMessage(e);
|
||||
rpeLogger().info("Error parsing the WHERE clause: " + whereParam);
|
||||
}
|
||||
@@ -282,6 +286,7 @@ public interface RecognizedParamsExtractor
|
||||
* The format is a comma seperated list of "columnName sortDirection",
|
||||
* e.g. "name DESC, age ASC". It is not case sensitive and the sort direction is optional
|
||||
* It default to sort ASCENDING.
|
||||
*
|
||||
* @param sortParams - String passed in on the request
|
||||
* @return - the sort columns or an empty list if the params were invalid.
|
||||
*/
|
||||
@@ -308,7 +313,8 @@ public interface RecognizedParamsExtractor
|
||||
}
|
||||
else
|
||||
{
|
||||
rpeLogger().debug("Invalid sort order definition ("+sortDef+"). Valid values are "+SortColumn.ASCENDING+" or "+SortColumn.DESCENDING+".");
|
||||
rpeLogger().debug("Invalid sort order definition (" + sortDef + "). Valid values are " + SortColumn.ASCENDING + " or "
|
||||
+ SortColumn.DESCENDING + ".");
|
||||
}
|
||||
}
|
||||
sortedColumns.add(new SortColumn(columnName, SortColumn.ASCENDING.equals(sortOrder)));
|
||||
@@ -356,10 +362,8 @@ public interface RecognizedParamsExtractor
|
||||
return Paging.valueOf(skipped, max);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes the web request and looks for a "fields" parameter (otherwise deprecated "properties" parameter).
|
||||
*
|
||||
* Parses the parameter and produces a list of bean properties to use as a filter A
|
||||
* SimpleBeanPropertyFilter it returned that uses the bean properties. If no
|
||||
* filter param is set then a default BeanFilter is returned that will never
|
||||
@@ -414,7 +418,6 @@ public interface RecognizedParamsExtractor
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds all request parameters that aren't already know about (eg. not paging or filter params)
|
||||
* and returns them for use.
|
||||
|
@@ -23,6 +23,7 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.framework.tools;
|
||||
|
||||
import org.alfresco.rest.framework.core.exceptions.ApiException;
|
||||
@@ -93,10 +94,9 @@ public interface RequestReader
|
||||
}
|
||||
}
|
||||
|
||||
default Log rrLogger() {
|
||||
default Log rrLogger()
|
||||
{
|
||||
return LogFactory.getLog(this.getClass());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -23,6 +23,7 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.rest.framework.tools;
|
||||
|
||||
import org.alfresco.rest.framework.Api;
|
||||
@@ -90,12 +91,14 @@ public interface ResponseWriter
|
||||
|
||||
final WithResponse DEFAULT_SUCCESS = new WithResponse(Status.STATUS_OK, DEFAULT_JSON_CONTENT, CACHE_NEVER);
|
||||
|
||||
default Log resWriterLogger() {
|
||||
default Log resWriterLogger()
|
||||
{
|
||||
return LogFactory.getLog(this.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the response headers with any information we know about the content
|
||||
*
|
||||
* @param res WebScriptResponse
|
||||
* @param contentInfo Content Information
|
||||
*/
|
||||
@@ -134,7 +137,6 @@ public interface ResponseWriter
|
||||
/**
|
||||
* The response status must be set before the response is written by Jackson (which will by default close and commit the response).
|
||||
* In a r/w txn, web script buffered responses ensure that it doesn't really matter but for r/o txns this is important.
|
||||
*
|
||||
* If you set content information via the contentInfo object and ALSO the headers then "headers" will win because they are
|
||||
* set last.
|
||||
*
|
||||
@@ -153,7 +155,8 @@ public interface ResponseWriter
|
||||
{
|
||||
for (Map.Entry<String, List<String>> header : headers.entrySet())
|
||||
{
|
||||
for (int i=0; i < header.getValue().size(); i++) {
|
||||
for (int i = 0; i < header.getValue().size(); i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
//If its the first one then set the header overwriting.
|
||||
@@ -171,6 +174,7 @@ public interface ResponseWriter
|
||||
|
||||
/**
|
||||
* Sets the response using the WithResponse object
|
||||
*
|
||||
* @param res
|
||||
* @param withResponse
|
||||
*/
|
||||
@@ -181,11 +185,14 @@ public interface ResponseWriter
|
||||
|
||||
/**
|
||||
* Renders a JSON error response
|
||||
*
|
||||
* @param errorResponse The error
|
||||
* @param res web script response
|
||||
* @throws IOException
|
||||
*/
|
||||
default void renderErrorResponse(final ErrorResponse errorResponse, final WebScriptResponse res, final JacksonHelper jsonHelper) throws IOException {
|
||||
default void renderErrorResponse(final ErrorResponse errorResponse, final WebScriptResponse res, final JacksonHelper jsonHelper)
|
||||
throws IOException
|
||||
{
|
||||
|
||||
String logId = "";
|
||||
|
||||
@@ -197,13 +204,8 @@ public interface ResponseWriter
|
||||
|
||||
String stackMessage = I18NUtil.getMessage(DefaultExceptionResolver.STACK_MESSAGE_ID);
|
||||
|
||||
final ErrorResponse errorToWrite = new ErrorResponse(errorResponse.getErrorKey(),
|
||||
errorResponse.getStatusCode(),
|
||||
errorResponse.getBriefSummary(),
|
||||
stackMessage,
|
||||
logId,
|
||||
errorResponse.getAdditionalState(),
|
||||
DefaultExceptionResolver.ERROR_URL);
|
||||
final ErrorResponse errorToWrite = new ErrorResponse(errorResponse.getErrorKey(), errorResponse.getStatusCode(),
|
||||
errorResponse.getBriefSummary(), stackMessage, logId, errorResponse.getAdditionalState(), DefaultExceptionResolver.ERROR_URL);
|
||||
|
||||
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);
|
||||
|
||||
@@ -225,14 +227,15 @@ public interface ResponseWriter
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders an exception to the output stream as Json.
|
||||
*
|
||||
* @param exception
|
||||
* @param response
|
||||
* @throws IOException
|
||||
*/
|
||||
default void renderException(final Exception exception, final WebScriptResponse response, final ApiAssistant assistant) throws IOException {
|
||||
default void renderException(final Exception exception, final WebScriptResponse response, final ApiAssistant assistant) throws IOException
|
||||
{
|
||||
renderErrorResponse(assistant.resolveException(exception), response, assistant.getJsonHelper());
|
||||
}
|
||||
|
||||
@@ -243,8 +246,7 @@ public interface ResponseWriter
|
||||
* @param toSerialize result of an execution
|
||||
* @throws IOException
|
||||
*/
|
||||
default void renderJsonResponse(final WebScriptResponse res, final Object toSerialize, final JacksonHelper jsonHelper)
|
||||
throws IOException
|
||||
default void renderJsonResponse(final WebScriptResponse res, final Object toSerialize, final JacksonHelper jsonHelper) throws IOException
|
||||
{
|
||||
jsonHelper.withWriter(res.getOutputStream(), new JacksonHelper.Writer()
|
||||
{
|
||||
|
Reference in New Issue
Block a user