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