Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

122165 gjames: RA-823 Adding an interface


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126453 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 10:57:42 +00:00
parent 3b6cad99e6
commit 9446c8938a
3 changed files with 50 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package org.alfresco.rest.framework.jacksonextensions;
import java.io.IOException; import java.io.IOException;
import org.alfresco.rest.framework.resource.SerializablePagedCollection;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper; import org.alfresco.rest.framework.webscripts.ResourceWebScriptHelper;
import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.JsonGenerationException;
@@ -11,21 +12,21 @@ import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.ser.std.SerializerBase; import org.codehaus.jackson.map.ser.std.SerializerBase;
/** /**
* Serializes CollectionWithPagingInfo into the correct response format, with Paging information and entries// * Serializes SerializablePagedCollection into the correct response format, with Paging information and entries
* *
* @author Gethin James * @author Gethin James
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class SerializerOfCollectionWithPaging extends SerializerBase<CollectionWithPagingInfo> public class SerializerOfCollectionWithPaging extends SerializerBase<SerializablePagedCollection>
{ {
protected SerializerOfCollectionWithPaging() protected SerializerOfCollectionWithPaging()
{ {
super(CollectionWithPagingInfo.class); super(SerializablePagedCollection.class);
} }
@Override @Override
public void serialize(CollectionWithPagingInfo pagedCol, JsonGenerator jgen, SerializerProvider provider) public void serialize(SerializablePagedCollection pagedCol, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException throws IOException, JsonGenerationException
{ {
if (pagedCol != null) if (pagedCol != null)
@@ -40,7 +41,7 @@ public class SerializerOfCollectionWithPaging extends SerializerBase<CollectionW
} }
} }
private void serializePagination(CollectionWithPagingInfo pagedCol, JsonGenerator jgen) throws IOException, private void serializePagination(SerializablePagedCollection pagedCol, JsonGenerator jgen) throws IOException,
JsonProcessingException JsonProcessingException
{ {
jgen.writeFieldName("pagination"); jgen.writeFieldName("pagination");

View File

@@ -0,0 +1,37 @@
package org.alfresco.rest.framework.resource;
import org.alfresco.rest.framework.resource.parameters.Paging;
import java.util.Collection;
/**
* A specialist representation of a Collection that can be serialized to json with paging information
*
* @author Gethin James.
*/
public interface SerializablePagedCollection<T>
{
/**
* Returns the Collection object
* @return Collection
*/
Collection<T> getCollection();
/**
* Indicates if the returned collection has more items after the current returned list.
*/
boolean hasMoreItems();
/**
* Indicates the total number of items available.
*
* Can be greater than the number of items returned in the list.
*
*/
Integer getTotalItems();
/**
* The requested paging parameters set by the client
*/
Paging getPaging();
}

View File

@@ -1,5 +1,7 @@
package org.alfresco.rest.framework.resource.parameters; package org.alfresco.rest.framework.resource.parameters;
import org.alfresco.rest.framework.resource.SerializablePagedCollection;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@@ -15,7 +17,7 @@ import java.util.Collections;
* *
* @author Gethin James. * @author Gethin James.
*/ */
public class CollectionWithPagingInfo<T> public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
{ {
private final Collection<T> collection; private final Collection<T> collection;
@@ -95,6 +97,7 @@ public class CollectionWithPagingInfo<T>
* Returns the Collection object * Returns the Collection object
* @return Collection * @return Collection
*/ */
@Override
public Collection<T> getCollection() public Collection<T> getCollection()
{ {
return this.collection; return this.collection;
@@ -103,6 +106,7 @@ public class CollectionWithPagingInfo<T>
/** /**
* Indicates if the returned collection has more items after the current returned list. * Indicates if the returned collection has more items after the current returned list.
*/ */
@Override
public boolean hasMoreItems() public boolean hasMoreItems()
{ {
return this.hasMoreItems; return this.hasMoreItems;
@@ -114,6 +118,7 @@ public class CollectionWithPagingInfo<T>
* Can be greater than the number of items returned in the list. * Can be greater than the number of items returned in the list.
* *
*/ */
@Override
public Integer getTotalItems() public Integer getTotalItems()
{ {
return this.totalItems; return this.totalItems;
@@ -122,6 +127,7 @@ public class CollectionWithPagingInfo<T>
/** /**
* The requested paging parameters set by the client * The requested paging parameters set by the client
*/ */
@Override
public Paging getPaging() public Paging getPaging()
{ {
return this.paging; return this.paging;