From 83029d134f8a6cb6cf518ccdc3e4eab13850f179 Mon Sep 17 00:00:00 2001 From: Ancuta Morarasu Date: Wed, 11 May 2016 11:37:33 +0000 Subject: [PATCH] Merged HEAD (5.2) to 5.2.N (5.2.1) 126479 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 122547 gjames: RA-823: Allow the implementation to specify the "source entity" first. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126823 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../framework/resource/parameters/Parameters.java | 10 +++++++++- .../rest/framework/resource/parameters/Params.java | 1 + .../webscripts/ResourceWebScriptHelper.java | 14 ++++++++++---- .../rest/framework/tests/core/SerializeTests.java | 6 ++++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java b/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java index cee29b16b5..f6f1662fc2 100644 --- a/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java +++ b/source/java/org/alfresco/rest/framework/resource/parameters/Parameters.java @@ -98,7 +98,15 @@ public interface Parameters * @return String the propertyName */ public String getBinaryProperty(); - + + /** + * Indicates if the source entity should be includes in the request. + * This will normally be done by the framework but implentations may prefer + * to do it themselves. + * @return true if the source should be included. + */ + boolean includeSource(); + /** * Represents a Query specified by the client. * Specified by the "WHERE" request parameter. diff --git a/source/java/org/alfresco/rest/framework/resource/parameters/Params.java b/source/java/org/alfresco/rest/framework/resource/parameters/Params.java index 420db78b7b..3ddea7484a 100644 --- a/source/java/org/alfresco/rest/framework/resource/parameters/Params.java +++ b/source/java/org/alfresco/rest/framework/resource/parameters/Params.java @@ -135,6 +135,7 @@ public class Params implements Parameters return this.recognizedParams.filter; } + @Override public boolean includeSource() { return this.recognizedParams.includeSource; diff --git a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java index 5578e759ee..61ef255204 100644 --- a/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java +++ b/source/java/org/alfresco/rest/framework/webscripts/ResourceWebScriptHelper.java @@ -483,10 +483,10 @@ public class ResourceWebScriptHelper { PropertyCheck.mandatory(this, null, params); if (objectToWrap == null ) return null; - if (objectToWrap instanceof SerializablePagedCollection) + if (objectToWrap instanceof CollectionWithPagingInfo) { - SerializablePagedCollection collectionToWrap = (SerializablePagedCollection) objectToWrap; - Object sourceEntity = executeIncludedSource(res, api, params, entityCollectionName); + CollectionWithPagingInfo collectionToWrap = (CollectionWithPagingInfo) objectToWrap; + Object sourceEntity = executeIncludedSource(res, api, params, entityCollectionName, collectionToWrap); Collection resultCollection = new ArrayList(collectionToWrap.getCollection().size()); if (!collectionToWrap.getCollection().isEmpty()) { @@ -527,10 +527,16 @@ public class ResourceWebScriptHelper } } - private Object executeIncludedSource(WebScriptResponse response, Api api, Params params, String entityCollectionName) + private Object executeIncludedSource(WebScriptResponse response, Api api, Params params, String entityCollectionName, CollectionWithPagingInfo collectionToWrap) { if (params.includeSource()) { + if (collectionToWrap.getSourceEntity() != null) + { + //The implementation has already set it so return it; + return collectionToWrap.getSourceEntity(); + } + ResourceWithMetadata res = locator.locateEntityResource(api, entityCollectionName, HttpMethod.GET); if (res != null) { diff --git a/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java b/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java index 1a8ff9ef08..b1c26dae37 100644 --- a/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java +++ b/source/test-java/org/alfresco/rest/framework/tests/core/SerializeTests.java @@ -250,6 +250,12 @@ public class SerializeTests extends AbstractContextTest assertNotNull(resultCollection); out = writeResponse(resultCollection); assertFalse("There must not 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"1\"}")); + + coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1, exec2), false, 2, new Sheep("barbie")); + resultCollection = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api,"sheep",ParamsExtender.valueOf(true,"1"),coll); + assertNotNull(resultCollection); + out = writeResponse(resultCollection); + assertTrue("There must 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"barbie\"")); } @Test