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
This commit is contained in:
Ancuta Morarasu
2016-05-11 11:37:33 +00:00
parent 64afcc134e
commit 83029d134f
4 changed files with 26 additions and 5 deletions

View File

@@ -99,6 +99,14 @@ public interface Parameters
*/ */
public String getBinaryProperty(); 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. * Represents a Query specified by the client.
* Specified by the "WHERE" request parameter. * Specified by the "WHERE" request parameter.

View File

@@ -135,6 +135,7 @@ public class Params implements Parameters
return this.recognizedParams.filter; return this.recognizedParams.filter;
} }
@Override
public boolean includeSource() public boolean includeSource()
{ {
return this.recognizedParams.includeSource; return this.recognizedParams.includeSource;

View File

@@ -483,10 +483,10 @@ public class ResourceWebScriptHelper
{ {
PropertyCheck.mandatory(this, null, params); PropertyCheck.mandatory(this, null, params);
if (objectToWrap == null ) return null; if (objectToWrap == null ) return null;
if (objectToWrap instanceof SerializablePagedCollection<?>) if (objectToWrap instanceof CollectionWithPagingInfo<?>)
{ {
SerializablePagedCollection<?> collectionToWrap = (SerializablePagedCollection<?>) objectToWrap; CollectionWithPagingInfo<?> collectionToWrap = (CollectionWithPagingInfo<?>) objectToWrap;
Object sourceEntity = executeIncludedSource(res, api, params, entityCollectionName); Object sourceEntity = executeIncludedSource(res, api, params, entityCollectionName, collectionToWrap);
Collection<Object> resultCollection = new ArrayList(collectionToWrap.getCollection().size()); Collection<Object> resultCollection = new ArrayList(collectionToWrap.getCollection().size());
if (!collectionToWrap.getCollection().isEmpty()) 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 (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); ResourceWithMetadata res = locator.locateEntityResource(api, entityCollectionName, HttpMethod.GET);
if (res != null) if (res != null)
{ {

View File

@@ -250,6 +250,12 @@ public class SerializeTests extends AbstractContextTest
assertNotNull(resultCollection); assertNotNull(resultCollection);
out = writeResponse(resultCollection); out = writeResponse(resultCollection);
assertFalse("There must not 'source' json output", StringUtils.contains(out, "\"source\":{\"name\":\"Dolly\",\"age\":3,\"sheepGuid\":\"1\"}")); 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 @Test