Merged 5.2.N (5.2.1) to HEAD (5.2)

130178 gjames: Merged searchapi (5.2.1) to 5.2.N (5.2.1)
      129808 gjames: SEARCH-112: Adding SearchContext to the response


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130329 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-09-06 22:04:24 +00:00
parent 9c8da6ba7c
commit a0a62612f4
8 changed files with 162 additions and 24 deletions

View File

@@ -61,7 +61,8 @@ public class SerializerOfCollectionWithPaging extends SerializerBase<Serializabl
jgen.writeFieldName("list");
jgen.writeStartObject();
serializePagination(pagedCol, jgen);
jgen.writeObjectField("entries", pagedCol.getCollection());
serializeContext(pagedCol, jgen);
jgen.writeObjectField("entries", pagedCol.getCollection());
serializeIncludedSource(pagedCol, jgen);
jgen.writeEndObject();
jgen.writeEndObject();
@@ -77,6 +78,15 @@ public class SerializerOfCollectionWithPaging extends SerializerBase<Serializabl
}
}
private void serializeContext(SerializablePagedCollection pagedCol, JsonGenerator jgen) throws IOException,
JsonProcessingException
{
if (pagedCol.getContext() != null)
{
jgen.writeObjectField("context",pagedCol.getContext());
}
}
private void serializePagination(SerializablePagedCollection pagedCol, JsonGenerator jgen) throws IOException,
JsonProcessingException
{

View File

@@ -26,6 +26,7 @@
package org.alfresco.rest.framework.resource;
import org.alfresco.rest.framework.resource.parameters.SearchContext;
import org.alfresco.rest.framework.resource.parameters.Paging;
import java.util.Collection;
@@ -65,4 +66,9 @@ public interface SerializablePagedCollection<T>
* The requested paging parameters set by the client
*/
Paging getPaging();
/**
* The search context for the collection
*/
SearchContext getContext();
}

View File

@@ -50,6 +50,7 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
private final Integer totalItems;
private final Paging paging;
private final Object sourceEntity;
private final SearchContext context;
/**
* Constructs a new CollectionWithPagingInfo.
@@ -58,7 +59,7 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
* @param hasMoreItems - Are there more items after this Collection?
* @param totalItems - The total number of items available.
*/
protected CollectionWithPagingInfo(Collection<T> collection, Paging paging, boolean hasMoreItems, Integer totalItems, Object sourceEntity)
protected CollectionWithPagingInfo(Collection<T> collection, Paging paging, boolean hasMoreItems, Integer totalItems, Object sourceEntity, SearchContext context)
{
super();
this.hasMoreItems = hasMoreItems;
@@ -75,8 +76,9 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
this.totalItems = totalItems;
}
this.sourceEntity = sourceEntity;
this.context = context;
}
/**
* Constructs a new CollectionWithPagingInfo.
* It automatically sets the total items based on the collection size and
@@ -89,7 +91,7 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
public static <T> CollectionWithPagingInfo<T> asPaged(Paging paging, Collection<T> aCollection)
{
int collectionSize = aCollection==null?0:aCollection.size();
return new CollectionWithPagingInfo<T>(aCollection, paging, false, collectionSize, null);
return new CollectionWithPagingInfo<T>(aCollection, paging, false, collectionSize, null, null);
}
/**
@@ -103,7 +105,7 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
public static <T> CollectionWithPagingInfo<T> asPagedCollection(T ...entity)
{
Collection<T> aNewCollection = Arrays.asList(entity);
return new CollectionWithPagingInfo<T>(aNewCollection, Paging.DEFAULT, false, aNewCollection.size(), null);
return new CollectionWithPagingInfo<T>(aNewCollection, Paging.DEFAULT, false, aNewCollection.size(), null, null);
}
/**
@@ -117,7 +119,22 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
*/
public static <T> CollectionWithPagingInfo<T> asPaged(Paging paging, Collection<T> aCollection, boolean hasMoreItems, Integer totalItems)
{
return new CollectionWithPagingInfo<T>(aCollection, paging, hasMoreItems, totalItems, null);
return new CollectionWithPagingInfo<T>(aCollection, paging, hasMoreItems, totalItems, null, null);
}
/**
* Constructs a new CollectionWithPagingInfo. Not for public use.
*
* @param paging - Paging request info
* @param aCollection - the collection that needs to be paged.
* @param hasMoreItems - Are there more items after this Collection?
* @param totalItems - The total number of items available.
* @param sourceEntity - The parent/source entity responsible for the collection
* @return CollectionWithPagingInfo
*/
public static <T> CollectionWithPagingInfo<T> asPaged(Paging paging, Collection<T> aCollection, boolean hasMoreItems, Integer totalItems, Object sourceEntity)
{
return new CollectionWithPagingInfo<T>(aCollection, paging, hasMoreItems, totalItems, sourceEntity, null);
}
/**
@@ -128,11 +145,12 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
* @param hasMoreItems - Are there more items after this Collection?
* @param totalItems - The total number of items available.
* @param sourceEntity - The parent/source entity responsible for the collection
* @param context - The search context
* @return CollectionWithPagingInfo
*/
public static <T> CollectionWithPagingInfo<T> asPaged(Paging paging, Collection<T> aCollection, boolean hasMoreItems, Integer totalItems, Object sourceEntity)
public static <T> CollectionWithPagingInfo<T> asPaged(Paging paging, Collection<T> aCollection, boolean hasMoreItems, Integer totalItems, Object sourceEntity, SearchContext context)
{
return new CollectionWithPagingInfo<T>(aCollection, paging, hasMoreItems, totalItems, sourceEntity);
return new CollectionWithPagingInfo<T>(aCollection, paging, hasMoreItems, totalItems, sourceEntity, context);
}
/**
@@ -183,4 +201,11 @@ public class CollectionWithPagingInfo<T> implements SerializablePagedCollection
{
return this.paging;
}
@Override
public SearchContext getContext()
{
return context;
}
}

View File

@@ -0,0 +1,59 @@
/*-
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.framework.resource.parameters;
/**
* The contextual results of a Search
*/
public class SearchContext
{
Consistency consistency;
public SearchContext(long lastTxId)
{
consistency = new Consistency(lastTxId);
}
public Consistency getConsistency()
{
return consistency;
}
public class Consistency
{
private long lastTxId;
public Consistency(long lastTxId)
{
this.lastTxId = lastTxId;
}
public long getlastTxId()
{
return lastTxId;
}
}
}

View File

@@ -174,7 +174,8 @@ public class ResourceWebScriptHelper
resultCollection.add(processAdditionsToTheResponse(res, api,entityCollectionName,params,obj));
}
}
return CollectionWithPagingInfo.asPaged(collectionToWrap.getPaging(), resultCollection, collectionToWrap.hasMoreItems(), collectionToWrap.getTotalItems(), sourceEntity);
return CollectionWithPagingInfo.asPaged(collectionToWrap.getPaging(), resultCollection, collectionToWrap.hasMoreItems(),
collectionToWrap.getTotalItems(), sourceEntity, collectionToWrap.getContext());
}
else
{