mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
128479 jvonka: V1 REST API: Node Version History - add basic paging REPO-313 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129162 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -158,8 +158,7 @@ public class AbstractNodeRelation implements InitializingBean
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Paging paging = parameters.getPaging();
|
return listPage(collection, parameters.getPaging());
|
||||||
return CollectionWithPagingInfo.asPaged(paging, collection, false, collection.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CollectionWithPagingInfo<Node> listNodeChildAssocs(List<ChildAssociationRef> childAssocRefs, Parameters parameters, Boolean isPrimary, boolean returnChild)
|
protected CollectionWithPagingInfo<Node> listNodeChildAssocs(List<ChildAssociationRef> childAssocRefs, Parameters parameters, Boolean isPrimary, boolean returnChild)
|
||||||
@@ -170,7 +169,7 @@ public class AbstractNodeRelation implements InitializingBean
|
|||||||
|
|
||||||
List<String> includeParam = parameters.getInclude();
|
List<String> includeParam = parameters.getInclude();
|
||||||
|
|
||||||
List<Node> result = new ArrayList<Node>(childAssocRefs.size());
|
List<Node> collection = new ArrayList<Node>(childAssocRefs.size());
|
||||||
for (ChildAssociationRef childAssocRef : childAssocRefs)
|
for (ChildAssociationRef childAssocRef : childAssocRefs)
|
||||||
{
|
{
|
||||||
if (isPrimary == null || (isPrimary == childAssocRef.isPrimary()))
|
if (isPrimary == null || (isPrimary == childAssocRef.isPrimary()))
|
||||||
@@ -193,24 +192,26 @@ public class AbstractNodeRelation implements InitializingBean
|
|||||||
|
|
||||||
node.setAssociation(new AssocChild(assocType, childAssocRef.isPrimary()));
|
node.setAssociation(new AssocChild(assocType, childAssocRef.isPrimary()));
|
||||||
|
|
||||||
|
collection.add(node);
|
||||||
result.add(node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Paging paging = parameters.getPaging();
|
return listPage(collection, parameters.getPaging());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected CollectionWithPagingInfo listPage(List result, Paging paging)
|
||||||
|
{
|
||||||
// return 'page' of results (note: depends on in-built/natural sort order of results)
|
// return 'page' of results (note: depends on in-built/natural sort order of results)
|
||||||
int skipCount = paging.getSkipCount();
|
int skipCount = paging.getSkipCount();
|
||||||
int pageSize = paging.getMaxItems();
|
int pageSize = paging.getMaxItems();
|
||||||
int pageEnd = skipCount + pageSize;
|
int pageEnd = skipCount + pageSize;
|
||||||
|
|
||||||
final List<Node> page = new ArrayList<>(pageSize);
|
final List page = new ArrayList<>(pageSize);
|
||||||
Iterator<Node> it = result.iterator();
|
Iterator it = result.iterator();
|
||||||
for (int counter = 0; counter < pageEnd && it.hasNext(); counter++)
|
for (int counter = 0; counter < pageEnd && it.hasNext(); counter++)
|
||||||
{
|
{
|
||||||
Node element = it.next();
|
Object element = it.next();
|
||||||
if (counter < skipCount)
|
if (counter < skipCount)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@@ -74,27 +74,15 @@ import java.util.Map;
|
|||||||
* @author janv
|
* @author janv
|
||||||
*/
|
*/
|
||||||
@RelationshipResource(name = "versions", entityResource = NodesEntityResource.class, title = "Node Versions")
|
@RelationshipResource(name = "versions", entityResource = NodesEntityResource.class, title = "Node Versions")
|
||||||
public class NodeVersionsRelation implements
|
public class NodeVersionsRelation extends AbstractNodeRelation implements
|
||||||
RelationshipResourceAction.Read<Node>,
|
RelationshipResourceAction.Read<Node>,
|
||||||
RelationshipResourceAction.ReadById<Node>,
|
RelationshipResourceAction.ReadById<Node>,
|
||||||
RelationshipResourceBinaryAction.Read,
|
RelationshipResourceBinaryAction.Read,
|
||||||
RelationshipResourceAction.Delete,
|
RelationshipResourceAction.Delete,
|
||||||
InitializingBean
|
InitializingBean
|
||||||
{
|
{
|
||||||
protected ServiceRegistry sr;
|
|
||||||
protected Nodes nodes;
|
|
||||||
protected VersionService versionService;
|
protected VersionService versionService;
|
||||||
|
|
||||||
public void setNodes(Nodes nodes)
|
|
||||||
{
|
|
||||||
this.nodes = nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServiceRegistry(ServiceRegistry sr)
|
|
||||||
{
|
|
||||||
this.sr = sr;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet()
|
public void afterPropertiesSet()
|
||||||
{
|
{
|
||||||
@@ -119,7 +107,6 @@ public class NodeVersionsRelation implements
|
|||||||
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
|
Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
|
||||||
List<String> includeParam = parameters.getInclude();
|
List<String> includeParam = parameters.getInclude();
|
||||||
|
|
||||||
// TODO fixme - add paging etc
|
|
||||||
List<Node> collection = null;
|
List<Node> collection = null;
|
||||||
if (vh != null)
|
if (vh != null)
|
||||||
{
|
{
|
||||||
@@ -132,8 +119,7 @@ public class NodeVersionsRelation implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Paging paging = parameters.getPaging();
|
return listPage(collection, parameters.getPaging());
|
||||||
return CollectionWithPagingInfo.asPaged(paging, collection, false, (collection != null ? collection.size() : 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mapVersionInfo(Version v, Node aNode)
|
private void mapVersionInfo(Version v, Node aNode)
|
||||||
|
@@ -31,10 +31,12 @@ import org.alfresco.rest.api.Nodes;
|
|||||||
import org.alfresco.rest.api.model.VersionOptions;
|
import org.alfresco.rest.api.model.VersionOptions;
|
||||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||||
|
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiHttpClient;
|
import org.alfresco.rest.api.tests.client.PublicApiHttpClient;
|
||||||
import org.alfresco.rest.api.tests.client.data.Document;
|
import org.alfresco.rest.api.tests.client.data.Document;
|
||||||
import org.alfresco.rest.api.tests.client.data.Node;
|
import org.alfresco.rest.api.tests.client.data.Node;
|
||||||
|
import org.alfresco.rest.api.tests.client.data.Rendition;
|
||||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
@@ -1260,7 +1262,72 @@ public class NodeVersionsApiTest extends AbstractBaseApiTest
|
|||||||
// TODO add tests to also check version comment (when we can list version history)
|
// TODO add tests to also check version comment (when we can list version history)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test version history paging.
|
||||||
|
*
|
||||||
|
* <p>GET:</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/versions}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testVersionHistoryPaging() throws Exception
|
||||||
|
{
|
||||||
|
// create folder
|
||||||
|
String f1Id = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
f1Id = createFolder(user1, Nodes.PATH_MY, "testVersionHistoryPaging-f1").getId();
|
||||||
|
|
||||||
|
String textContentSuffix = "Amazingly few discotheques provide jukeboxes ";
|
||||||
|
String contentName = "content-1";
|
||||||
|
|
||||||
|
int cnt = 6;
|
||||||
|
Pair<String, String> pair = uploadTextFileVersions(user1, f1Id, contentName, cnt, textContentSuffix, 0, null, null);
|
||||||
|
String versionLabel = pair.getFirst();
|
||||||
|
String docId = pair.getSecond();
|
||||||
|
|
||||||
|
assertEquals("1.5", versionLabel); // 1.0, 1.1, ... 1.5
|
||||||
|
|
||||||
|
// check version history count (note: no paging => default max items => 100)
|
||||||
|
HttpResponse response = getAll(getNodeVersionsUrl(docId), user1, null, null, 200);
|
||||||
|
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(cnt, nodes.size());
|
||||||
|
|
||||||
|
// Sanity Test paging
|
||||||
|
|
||||||
|
// SkipCount=0,MaxItems=2
|
||||||
|
Paging paging = getPaging(0, 2);
|
||||||
|
response = getAll(getNodeVersionsUrl(docId), user1, paging, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(2, nodes.size());
|
||||||
|
PublicApiClient.ExpectedPaging expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
|
||||||
|
assertEquals(2, expectedPaging.getCount().intValue());
|
||||||
|
assertEquals(0, expectedPaging.getSkipCount().intValue());
|
||||||
|
assertEquals(2, expectedPaging.getMaxItems().intValue());
|
||||||
|
assertTrue(expectedPaging.getTotalItems() >= cnt);
|
||||||
|
assertTrue(expectedPaging.getHasMoreItems());
|
||||||
|
|
||||||
|
// SkipCount=2,MaxItems=3
|
||||||
|
paging = getPaging(2, 3);
|
||||||
|
response = getAll(getNodeVersionsUrl(docId), user1, paging, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
assertEquals(3, nodes.size());
|
||||||
|
expectedPaging = RestApiUtil.parsePaging(response.getJsonResponse());
|
||||||
|
assertEquals(3, expectedPaging.getCount().intValue());
|
||||||
|
assertEquals(2, expectedPaging.getSkipCount().intValue());
|
||||||
|
assertEquals(3, expectedPaging.getMaxItems().intValue());
|
||||||
|
assertTrue(expectedPaging.getTotalItems() >= cnt);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (f1Id != null)
|
||||||
|
{
|
||||||
|
// some cleanup
|
||||||
|
Map<String, String> params = Collections.singletonMap("permanent", "true");
|
||||||
|
delete(URL_NODES, user1, f1Id, params, 204);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getScope()
|
public String getScope()
|
||||||
|
Reference in New Issue
Block a user