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

129774 gjames: SEARCH-113: Moving more api logic to helper classes, using a "trait" style


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130165 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Gethin James
2016-09-06 14:14:29 +00:00
parent ff2ce9d706
commit bfd32ef859
26 changed files with 1555 additions and 1303 deletions

View File

@@ -37,6 +37,7 @@ import org.alfresco.rest.framework.core.exceptions.ApiException;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.tools.ResponseWriter;
import org.alfresco.rest.framework.webscripts.ApiWebScript;
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
import org.codehaus.jackson.JsonGenerationException;
@@ -48,7 +49,7 @@ import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
public class NetworkWebScriptGet extends ApiWebScript
public class NetworkWebScriptGet extends ApiWebScript implements ResponseWriter
{
private Networks networks;
private ResourceWebScriptHelper helper;
@@ -76,8 +77,8 @@ public class NetworkWebScriptGet extends ApiWebScript
{
// apply content type
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer()
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
@@ -91,7 +92,7 @@ public class NetworkWebScriptGet extends ApiWebScript
{
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
// done automatically by the api framework).
Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMembership);
Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMembership);
objectMapper.writeValue(generator, wrapped);
}
@@ -106,13 +107,13 @@ public class NetworkWebScriptGet extends ApiWebScript
}
}, true, true);
}
catch (ApiException | WebScriptException apiException)
catch (ApiException | WebScriptException apiException)
{
assistant.renderException(apiException, res);
renderException(apiException, res, assistant);
}
catch (RuntimeException runtimeException)
{
assistant.renderException(runtimeException, res);
renderException(runtimeException, res, assistant);
}
}
}

View File

@@ -39,6 +39,8 @@ import org.alfresco.rest.framework.jacksonextensions.JacksonHelper.Writer;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Paging;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.tools.RecognizedParamsExtractor;
import org.alfresco.rest.framework.tools.ResponseWriter;
import org.alfresco.rest.framework.webscripts.ApiWebScript;
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
import org.codehaus.jackson.JsonGenerationException;
@@ -56,7 +58,7 @@ import org.springframework.extensions.webscripts.WebScriptResponse;
* @author steveglover
*
*/
public class NetworksWebScriptGet extends ApiWebScript
public class NetworksWebScriptGet extends ApiWebScript implements RecognizedParamsExtractor, ResponseWriter
{
private Networks networks;
private ResourceWebScriptHelper helper;
@@ -82,12 +84,12 @@ public class NetworksWebScriptGet extends ApiWebScript
@Override
public Void execute() throws Throwable
{
final Paging paging = ResourceWebScriptHelper.findPaging(req);
final Paging paging = findPaging(req);
// apply content type
res.setContentType(Format.JSON.mimetype() + ";charset=UTF-8");
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer()
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
@@ -102,7 +104,7 @@ public class NetworksWebScriptGet extends ApiWebScript
{
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
// done automatically by the api framework).
Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMember);
Object wrapped = helper.processAdditionsToTheResponse(res, Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMember);
entities.add(wrapped);
}
@@ -114,13 +116,13 @@ public class NetworksWebScriptGet extends ApiWebScript
}
}, true, true);
}
catch (ApiException | WebScriptException apiException)
catch (ApiException | WebScriptException apiException)
{
assistant.renderException(apiException, res);
renderException(apiException, res, assistant);
}
catch (RuntimeException runtimeException)
{
assistant.renderException(runtimeException, res);
renderException(runtimeException, res, assistant);
}
}
}

View File

@@ -25,29 +25,30 @@
*/
package org.alfresco.rest.api;
import java.io.IOException;
import java.io.IOException;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.alfresco.repo.web.scripts.TenantWebScriptServletRuntime;
import org.alfresco.rest.framework.tools.ApiAssistant;
import org.alfresco.rest.framework.tools.ApiAssistant;
import org.alfresco.rest.framework.tools.ResponseWriter;
import org.springframework.extensions.config.ServerProperties;
import org.springframework.extensions.surf.util.URLDecoder;
import org.springframework.extensions.webscripts.*;
import org.springframework.extensions.webscripts.*;
import org.springframework.extensions.webscripts.servlet.ServletAuthenticatorFactory;
public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime
public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServletRuntime implements ResponseWriter
{
private static final Pattern CMIS_URI_PATTERN = Pattern.compile(".*/cmis/versions/[0-9]+\\.[0-9]+/.*");
private ApiAssistant apiAssistant;
private ApiAssistant apiAssistant;
public PublicApiTenantWebScriptServletRuntime(RuntimeContainer container, ServletAuthenticatorFactory authFactory, HttpServletRequest req,
HttpServletResponse res, ServerProperties serverProperties, ApiAssistant apiAssistant)
HttpServletResponse res, ServerProperties serverProperties, ApiAssistant apiAssistant)
{
super(container, authFactory, req, res, serverProperties);
this.apiAssistant = apiAssistant;
this.apiAssistant = apiAssistant;
}
/* (non-Javadoc)
@@ -130,24 +131,24 @@ public class PublicApiTenantWebScriptServletRuntime extends TenantWebScriptServl
{
return "PublicApiTenantServletRuntime";
}
@Override
protected void renderErrorResponse(Match match, Throwable exception, WebScriptRequest request, WebScriptResponse response) {
//If its cmis or not an exception then use the default behaviour
if (CMIS_URI_PATTERN.matcher(req.getRequestURI()).matches() || !(exception instanceof Exception))
{
super.renderErrorResponse(match, exception, request, response);
}
else
{
try {
apiAssistant.renderException((Exception)exception, response);
} catch (IOException e) {
logger.error("Internal error", e);
throw new WebScriptException("Internal error", e);
}
}
}
@Override
protected void renderErrorResponse(Match match, Throwable exception, WebScriptRequest request, WebScriptResponse response) {
//If its cmis or not an exception then use the default behaviour
if (CMIS_URI_PATTERN.matcher(req.getRequestURI()).matches() || !(exception instanceof Exception))
{
super.renderErrorResponse(match, exception, request, response);
}
else
{
try {
renderException((Exception)exception, response, apiAssistant);
} catch (IOException e) {
logger.error("Internal error", e);
throw new WebScriptException("Internal error", e);
}
}
}
}

View File

@@ -32,6 +32,7 @@ import org.alfresco.rest.api.model.Person;
import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.tools.RecognizedParamsExtractor;
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
/**
@@ -44,9 +45,9 @@ public interface Queries
{
// General
static String PARAM_TERM = "term";
static String PARAM_ORDERBY = ResourceWebScriptHelper.PARAM_ORDERBY;
static String PARAM_FIELDS = ResourceWebScriptHelper.PARAM_FILTER_FIELDS;
static String PARAM_INCLUDE = ResourceWebScriptHelper.PARAM_INCLUDE;
static String PARAM_ORDERBY = RecognizedParamsExtractor.PARAM_ORDERBY;
static String PARAM_FIELDS = RecognizedParamsExtractor.PARAM_FILTER_FIELDS;
static String PARAM_INCLUDE = RecognizedParamsExtractor.PARAM_INCLUDE;
// Node query
static String PARAM_ROOT_NODE_ID = "rootNodeId";

View File

@@ -57,7 +57,7 @@ import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rest.framework.resource.parameters.where.Query;
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper;
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
import org.alfresco.rest.framework.tools.RecognizedParamsExtractor;
import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -107,7 +107,7 @@ import java.util.Set;
*
* @since publicapi1.0
*/
public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
public class QuickShareLinksImpl implements QuickShareLinks, RecognizedParamsExtractor, InitializingBean
{
private static final Log logger = LogFactory.getLog(QuickShareLinksImpl.class);
@@ -404,7 +404,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean
// hmm ... can we simplify ?
String filterStatusCreated = "(" + Renditions.PARAM_STATUS + "='" + Rendition.RenditionStatus.CREATED + "')";
Query whereQuery = ResourceWebScriptHelper.getWhereClause(filterStatusCreated);
Query whereQuery = getWhereClause(filterStatusCreated);
Params.RecognizedParams recParams = new Params.RecognizedParams(null, null, null, null, null, null, whereQuery, null, false);
Parameters params = Params.valueOf(recParams, null, null, null);