From 82f2708aa723e3fa0b74b2d457cbf0122642ccea Mon Sep 17 00:00:00 2001 From: Iuliana Danea Date: Thu, 13 Oct 2016 06:52:01 +0000 Subject: [PATCH] ACE-5453: 500 error: GET /nodes/{nodeId}/ratings?skipCount=XXX - implemented fix and added new unit test git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131385 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../rest/api/impl/NodeRatingsImpl.java | 11 +++++---- .../rest/api/tests/TestNodeRatings.java | 24 ++++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/source/java/org/alfresco/rest/api/impl/NodeRatingsImpl.java b/source/java/org/alfresco/rest/api/impl/NodeRatingsImpl.java index b5b16613d0..27256ae15e 100644 --- a/source/java/org/alfresco/rest/api/impl/NodeRatingsImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodeRatingsImpl.java @@ -107,15 +107,17 @@ public class NodeRatingsImpl implements NodeRatings Iterator it = schemes.iterator(); int skipCount = paging.getSkipCount(); - int maxItems = paging.getMaxItems(); + int maxItems = paging.getMaxItems(); + int totalSize = schemes.size(); + int count = 0; + int end = skipCount + maxItems; if(end < 0) { // overflow end = Integer.MAX_VALUE; } - int count = Math.min(maxItems, schemes.size() - skipCount); - List ratings = new ArrayList(count); + List ratings = new ArrayList(totalSize); for(int i = 0; i < end && it.hasNext(); i++) { @@ -124,13 +126,12 @@ public class NodeRatingsImpl implements NodeRatings { continue; } - + count++; RatingScheme ratingScheme = validateRatingScheme(schemeName); NodeRating nodeRating = ratingScheme.getNodeRating(nodeRef); ratings.add(nodeRating); } - int totalSize = schemes.size(); boolean hasMoreItems = (skipCount + count < totalSize); return CollectionWithPagingInfo.asPaged(paging, ratings, hasMoreItems, totalSize); diff --git a/source/test-java/org/alfresco/rest/api/tests/TestNodeRatings.java b/source/test-java/org/alfresco/rest/api/tests/TestNodeRatings.java index a9da574ae2..41b8cf7c18 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestNodeRatings.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestNodeRatings.java @@ -534,7 +534,29 @@ public class TestNodeRatings extends AbstractBaseApiTest assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } } - } + + // Test case ACE-5453 + { + try + { + testSkipCountLargeValue(person11, network1, nodeRef1, nodesProxy); + } + catch (PublicApiException e) + { + fail(); + } + } + } + + // test for retrieving the list of ratings with high value of skipCount(e.g. 10) + public void testSkipCountLargeValue(TestPerson person11, TestNetwork network1, NodeRef nodeRef1, Nodes nodesProxy) throws PublicApiException + { + List expectedRatings = repoService.getNodeRatings(person11.getId(), network1.getId(), nodeRef1); + int skipCount = 10; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems, expectedRatings.size(), expectedRatings.size()); + nodesProxy.getNodeRatings(nodeRef1.getId(), createParams(paging, null)); + } @Override public String getScope()