From a489a4708e8bc10a8f6405aee86d31e003e84404 Mon Sep 17 00:00:00 2001 From: Ancuta Morarasu Date: Wed, 11 May 2016 11:42:15 +0000 Subject: [PATCH] Merged HEAD (5.2) to 5.2.N (5.2.1) 126485 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122596 gjames: RA-211: Post-processing (carefully) embedded/related resources git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126829 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../resource/actions/ActionExecutor.java | 3 +- .../webscripts/AbstractResourceWebScript.java | 20 ++---------- .../webscripts/ResourceWebScriptHelper.java | 32 ++++++++++--------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/source/java/org/alfresco/rest/framework/resource/actions/ActionExecutor.java b/source/java/org/alfresco/rest/framework/resource/actions/ActionExecutor.java index c8055afcee..57e74aa3d7 100644 --- a/source/java/org/alfresco/rest/framework/resource/actions/ActionExecutor.java +++ b/source/java/org/alfresco/rest/framework/resource/actions/ActionExecutor.java @@ -44,9 +44,8 @@ public interface ActionExecutor extends HttpMethodSupport * Invokes the resource with the Params * @param resource ResourceWithMetadata * @param params Params - * @param boolean should we use a readonly transaction. */ @SuppressWarnings("rawtypes") - public Object execute(ResourceWithMetadata resource, Params params, WebScriptResponse res, boolean isReadOnly); + public Object executeAction(ResourceWithMetadata resource, Params params) throws Throwable; } diff --git a/source/java/org/alfresco/rest/framework/webscripts/AbstractResourceWebScript.java b/source/java/org/alfresco/rest/framework/webscripts/AbstractResourceWebScript.java index 986dda1a37..e25a5aa676 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/AbstractResourceWebScript.java +++ b/source/java/org/alfresco/rest/framework/webscripts/AbstractResourceWebScript.java @@ -98,11 +98,10 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements final Map templateVars = req.getServiceMatch().getTemplateVars(); final ResourceWithMetadata resource = locator.locateResource(api,templateVars, httpMethod); final Params params = paramsExtractor.extractParams(resource.getMetaData(),req); - final ActionExecutor executor = findExecutor(httpMethod, params, resource, req.getContentType()); final boolean isReadOnly = HttpMethod.GET==httpMethod; //This execution usually takes place in a Retrying Transaction (see subclasses) - final Object toSerialize = executor.execute(resource, params, res, isReadOnly); + final Object toSerialize = execute(resource, params, res, isReadOnly); //Outside the transaction. if (toSerialize != null) @@ -150,7 +149,6 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements } } - @Override public Object execute(final ResourceWithMetadata resource, final Params params, final WebScriptResponse res, boolean isReadOnly) { final String entityCollectionName = ResourceInspector.findEntityCollectionNameName(resource.getMetaData()); @@ -172,7 +170,7 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements }, isReadOnly, true); } - protected abstract Object executeAction(ResourceWithMetadata resource, Params params) throws Throwable; + public abstract Object executeAction(ResourceWithMetadata resource, Params params) throws Throwable; protected void streamResponse(final WebScriptRequest req, final WebScriptResponse res, BinaryResource resource) throws IOException { @@ -232,20 +230,6 @@ public abstract class AbstractResourceWebScript extends ApiWebScript implements }); } - /** - * Finds the action executor to execute actions on. - * @param httpMethod - the http method - * @param params Params - * @param resource ResourceWithMetadata - * @param contentType Request content type - * @return ActionExecutor the action executor - */ - public ActionExecutor findExecutor(HttpMethod httpMethod, Params params, ResourceWithMetadata resource, String contentType) - { - //Ignore all params and return this - return this; - } - public void setLocator(ResourceLocator locator) { this.locator = locator; diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java index 61ef255204..8c10425da6 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java @@ -55,9 +55,7 @@ import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; 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.resource.SerializablePagedCollection; import org.alfresco.rest.framework.resource.actions.ActionExecutor; -import org.alfresco.rest.framework.resource.content.ContentInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.InvalidSelectException; import org.alfresco.rest.framework.resource.parameters.Paging; @@ -486,7 +484,7 @@ public class ResourceWebScriptHelper if (objectToWrap instanceof CollectionWithPagingInfo) { CollectionWithPagingInfo collectionToWrap = (CollectionWithPagingInfo) objectToWrap; - Object sourceEntity = executeIncludedSource(res, api, params, entityCollectionName, collectionToWrap); + Object sourceEntity = executeIncludedSource(api, params, entityCollectionName, collectionToWrap); Collection resultCollection = new ArrayList(collectionToWrap.getCollection().size()); if (!collectionToWrap.getCollection().isEmpty()) { @@ -510,7 +508,7 @@ public class ResourceWebScriptHelper Map> embeddded = ResourceInspector.findEmbeddedResources(objectToWrap.getClass()); if (embeddded != null && !embeddded.isEmpty()) { - Map results = executeEmbeddedResources(res, api, params,objectToWrap, embeddded); + Map results = executeEmbeddedResources(api, params,objectToWrap, embeddded); execRes.addEmbedded(results); } @@ -518,7 +516,7 @@ public class ResourceWebScriptHelper { Map relationshipResources = locator.locateRelationResource(api,entityCollectionName, params.getRelationsFilter().keySet(), HttpMethod.GET); String uniqueEntityId = ResourceInspector.findUniqueId(objectToWrap); - Map relatedResources = executeRelatedResources(res, api, params, relationshipResources, uniqueEntityId); + Map relatedResources = executeRelatedResources(api, params, relationshipResources, uniqueEntityId); execRes.addRelated(relatedResources); } @@ -527,7 +525,7 @@ public class ResourceWebScriptHelper } } - private Object executeIncludedSource(WebScriptResponse response, Api api, Params params, String entityCollectionName, CollectionWithPagingInfo collectionToWrap) + private Object executeIncludedSource(Api api, Params params, String entityCollectionName, CollectionWithPagingInfo collectionToWrap) { if (params.includeSource()) { @@ -540,7 +538,7 @@ public class ResourceWebScriptHelper ResourceWithMetadata res = locator.locateEntityResource(api, entityCollectionName, HttpMethod.GET); if (res != null) { - Object result = executeRelatedResource(response, api, params, params.getEntityId(), null, res); + Object result = executeResource(api, params, params.getEntityId(), null, res); if (result!=null && result instanceof ExecutionResult) return ((ExecutionResult) result).getRoot(); } } @@ -557,7 +555,7 @@ public class ResourceWebScriptHelper * @param embeddded Map> * @return Map */ - private Map executeEmbeddedResources(WebScriptResponse response, Api api, Params params, Object objectToWrap, Map> embeddded) + private Map executeEmbeddedResources(Api api, Params params, Object objectToWrap, Map> embeddded) { final Map results = new HashMap(embeddded.size()); for (Entry> embeddedEntry : embeddded.entrySet()) @@ -568,7 +566,7 @@ public class ResourceWebScriptHelper Object id = ResourceInspectorUtil.invokeMethod(embeddedEntry.getValue().getSecond(), objectToWrap); if (id != null) { - Object execEmbeddedResult = executeRelatedResource(response, api, params, String.valueOf(id), embeddedEntry.getKey(), res); + Object execEmbeddedResult = executeResource(api, params, String.valueOf(id), embeddedEntry.getKey(), res); if (execEmbeddedResult != null) { if (execEmbeddedResult instanceof ExecutionResult) @@ -598,14 +596,14 @@ public class ResourceWebScriptHelper * @param uniqueEntityId String * @return Map */ - private Map executeRelatedResources(final WebScriptResponse res, final Api api, Params params, + private Map executeRelatedResources(final Api api, Params params, Map relatedResources, String uniqueEntityId) { final Map results = new HashMap(relatedResources.size()); for (final Entry relation : relatedResources.entrySet()) { - Object execResult = executeRelatedResource(res, api, params, uniqueEntityId, relation.getKey(), relation.getValue()); + Object execResult = executeResource(api, params, uniqueEntityId, relation.getKey(), relation.getValue()); if (execResult != null) { results.put(relation.getKey(), execResult); @@ -625,8 +623,8 @@ public class ResourceWebScriptHelper * @param resource ResourceWithMetadata * @return Object */ - private Object executeRelatedResource(final WebScriptResponse res, final Api api, Params params, - final String uniqueEntityId, final String resourceKey, final ResourceWithMetadata resource) + private Object executeResource(final Api api, Params params, + final String uniqueEntityId, final String resourceKey, final ResourceWithMetadata resource) { try { @@ -639,7 +637,8 @@ public class ResourceWebScriptHelper } final Params executionParams = Params.valueOf(paramFilter, uniqueEntityId, params.getRequest()); //Read only because this only occurs for GET requests - return executor.execute(resource, executionParams,res, true); + Object result = executor.executeAction(resource, executionParams); + return processAdditionsToTheResponse(null, api, null, executionParams, result); } catch(NotFoundException e) { @@ -656,8 +655,11 @@ public class ResourceWebScriptHelper { logger.debug("Ignored error, cannot access the object so can't embed it ", e); } + } catch (Throwable throwable) + { + logger.warn("Failed to execute a RelatedResource for "+resourceKey+" "+throwable.getMessage()); } - + return null; //default }