]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5397: Requests for refObjs that specify a page number beyond the list end...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 13 Jul 2012 16:48:49 +0000 (09:48 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 13 Jul 2012 16:48:49 +0000 (09:48 -0700)
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java

index 93f36a29b148e384e241b1efd0776167fa7a08fb..2d4db981e7dc4387de25f02fbee429191685de32 100644 (file)
@@ -292,9 +292,12 @@ public class RefNameServiceUtils {
             // in the list results.\r
             //\r
             // FIXME: There may well be a pattern-based way to do this\r
-            // in our framework.\r
+            // in our framework, and if we can eliminate much of the\r
+            // non-DRY code below, that would be desirable.\r
+            \r
             int startIndex = 0;\r
             int endIndex = 0;\r
+            \r
             // Return all results if pageSize is 0.\r
             if (pageSize == 0) {\r
                 startIndex = 0;\r
@@ -303,25 +306,27 @@ public class RefNameServiceUtils {
                startIndex = pageNum * pageSize;\r
             }\r
             \r
-            // Return an empty list if the start of the requested page is\r
+            // Return an empty list when the start of the requested page is\r
             // beyond the last item in the list.\r
             if (startIndex > list.size()) {\r
-                wrapperList = null;\r
+                wrapperList.getAuthorityRefDocItem().clear();\r
+                commonList.setItemsInPage(wrapperList.getAuthorityRefDocItem().size());\r
                 return wrapperList;\r
             }\r
 \r
             // Otherwise, return a list of items from the start of the specified\r
-            // page through the last item on that page, or otherwise through the last\r
-            // item in the entire list, if it occurs prior to the end of that page.\r
+            // page through the last item on that page, or otherwise through the\r
+            // last item in the entire list, if that occurs earlier than the end\r
+            // of the specified page.\r
             if (endIndex == 0) {\r
                 int pageEndIndex = ((startIndex + pageSize));\r
                 endIndex = (pageEndIndex > list.size()) ? list.size() : pageEndIndex;\r
             }\r
             \r
-            // Slice the list to return only the specified page.\r
-            // Note: the second argument to List.subList() is exclusive of the\r
-            // item at its index position, reflecting the zero-index nature of\r
-            // the list.\r
+            // Slice the list to return only the specified page of results.\r
+            // Note: the second argument to List.subList(), endIndex, is\r
+            // exclusive of the item at its index position, reflecting the\r
+            // zero-index nature of the list.\r
             List<AuthorityRefDocList.AuthorityRefDocItem> currentPageList =\r
                     new ArrayList<AuthorityRefDocList.AuthorityRefDocItem>(list.subList(startIndex, endIndex));\r
             wrapperList.getAuthorityRefDocItem().clear();\r