Author: lindner Date: Sat Oct 31 11:35:04 2009 New Revision: 831532 URL: http://svn.apache.org/viewvc?rev=831532&view=rev Log: SHINDIG-1117 | Lists returned for JSON-RPC do not include all properties
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RestfulCollection.java incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java?rev=831532&r1=831531&r2=831532&view=diff ============================================================================== --- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java (original) +++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/JsonRpcServlet.java Sat Oct 31 11:35:04 2009 @@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -105,9 +106,10 @@ } String content = null; - Map<String, FormDataItem> formItems = new HashMap<String, FormDataItem>(); + Map<String, FormDataItem> formItems = Collections.emptyMap(); // default for most requests if (formParser.isMultipartContent(servletRequest)) { + formItems = new HashMap<String, FormDataItem>(); for (FormDataItem item : formParser.parse(servletRequest)) { if (item.isFormField() && REQUEST_PARAM.equals(item.getFieldName()) && content == null) { // As per spec, in case of a multipart/form-data content, there will be one form field @@ -218,8 +220,22 @@ } else if (response instanceof RestfulCollection) { Map<String, Object> map = Maps.newHashMap(); RestfulCollection<?> collection = (RestfulCollection<?>) response; - map.put("startIndex", collection.getStartIndex()); - map.put("totalResults", collection.getTotalResults()); + // Return sublist info + if (collection.getTotalResults() != collection.getEntry().size()) { + map.put("totalResults", collection.getTotalResults()); + map.put("startIndex", collection.getStartIndex()); + map.put("itemsPerPage", collection.getItemsPerPage()); + } + + if (!collection.isFiltered()) + map.put("filtered", collection.isFiltered()); + + if (!collection.isUpdatedSince()) + map.put("updatedSince", collection.isUpdatedSince()); + + if (!collection.isSorted()) + map.put("sorted", collection.isUpdatedSince()); + map.put("list", collection.getEntry()); result.put("data", map); } else { Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RestfulCollection.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RestfulCollection.java?rev=831532&r1=831531&r2=831532&view=diff ============================================================================== --- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RestfulCollection.java (original) +++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/RestfulCollection.java Sat Oct 31 11:35:04 2009 @@ -23,19 +23,50 @@ private List<T> entry; private int startIndex; private int totalResults; + private int itemsPerPage; - private boolean filtered = true; - private boolean sorted = true; - private boolean updatedSince = true; - + private boolean filtered = false; + private boolean sorted = false; + private boolean updatedSince = false; + + /** + * Creates a new RestfulCollection that includes a complete set of entries. + * + * Default values for startIndex, totalResults, itemsPerPage and filtering parameters are automatically set. + * + * @param entry a list of entries + */ public RestfulCollection(List<T> entry) { - this(entry, 0, entry.size()); + this(entry, 0, entry.size(), entry.size()); + this.filtered=true; + this.sorted=true; + this.updatedSince=true; } + /** + * @deprecated As of 1.1-BETA4 use {...@link #RestfulCollection(java.util.List, int, int, int)} with the extra itemsPerPage Argument + * This contructor will be removed in 1.1 RC1 + */ + @Deprecated public RestfulCollection(List<T> entry, int startIndex, int totalResults) { + this(entry, startIndex, totalResults, entry.size()); + } + + /** + * Create a paginated collection response. + * + * @param entry paginated entries + * @param startIndex the index corresponding to the first element of {entry} + * @param totalResults the total size of the resultset + * @param itemsPerPage the size of the pagination, generally set to the user-specified count parameter. Clamped to the totalResults size automatically + * + * @since 1.1-BETA4 + */ + public RestfulCollection(List<T> entry, int startIndex, int totalResults, int itemsPerPage) { this.entry = entry; this.startIndex = startIndex; this.totalResults = totalResults; + this.itemsPerPage = Math.min(itemsPerPage, totalResults); } public List<T> getEntry() { @@ -58,6 +89,14 @@ return totalResults; } + public void setItemsPerPage(int itemsPerPage) { + this.itemsPerPage = itemsPerPage; + } + + public int getItemsPerPage() { + return itemsPerPage; + } + public void setTotalResults(int totalResults) { this.totalResults = totalResults; } Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java?rev=831532&r1=831531&r2=831532&view=diff ============================================================================== --- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java (original) +++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/protocol/conversion/xstream/RestfullCollectionConverter.java Sat Oct 31 11:35:04 2009 @@ -61,12 +61,19 @@ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { RestfulCollection<?> collection = (RestfulCollection<?>) source; + + // Required per spec writer.startNode("startIndex"); writer.setValue(String.valueOf(collection.getStartIndex())); writer.endNode(); writer.startNode("totalResults"); writer.setValue(String.valueOf(collection.getTotalResults())); writer.endNode(); + writer.startNode("itemsPerPage"); + writer.setValue(String.valueOf(collection.getItemsPerPage())); + writer.endNode(); + + // Optional writer.startNode("isFiltered"); writer.setValue(String.valueOf(collection.isFiltered())); writer.endNode(); @@ -76,6 +83,7 @@ writer.startNode("isUpdatedSince"); writer.setValue(String.valueOf(collection.isUpdatedSince())); writer.endNode(); + // TODO: resolve if entry is the container or the name of the object. for (Object o : collection.getEntry()) { writer.startNode("entry"); Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java?rev=831532&r1=831531&r2=831532&view=diff ============================================================================== --- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java (original) +++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java Sat Oct 31 11:35:04 2009 @@ -49,14 +49,17 @@ assertEquals(entry, collection.getEntry()); assertEquals(0, collection.getStartIndex()); assertEquals(entry.size(), collection.getTotalResults()); + assertEquals(entry.size(), collection.getItemsPerPage()); int startIndex = 9; int totalResults = 10; - collection = new RestfulCollection<String>(entry, startIndex, totalResults); + int resultsPerPage = 1; + collection = new RestfulCollection<String>(entry, startIndex, totalResults, resultsPerPage); assertEquals(entry, collection.getEntry()); assertEquals(startIndex, collection.getStartIndex()); assertEquals(totalResults, collection.getTotalResults()); + assertEquals(resultsPerPage, collection.getItemsPerPage()); } } Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java?rev=831532&r1=831531&r2=831532&view=diff ============================================================================== --- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java (original) +++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomFeed.java Sat Oct 31 11:35:04 2009 @@ -71,7 +71,7 @@ } startIndex = r.getStartIndex(); totalResults = r.getTotalResults(); - itemsPerPage = entryList.size(); + itemsPerPage = r.getItemsPerPage(); author = "?"; link = new AtomLink("rel", "???"); } else if ( obj instanceof DataCollection ) { Modified: incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java?rev=831532&r1=831531&r2=831532&view=diff ============================================================================== --- incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java (original) +++ incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialService.java Sat Oct 31 11:35:04 2009 @@ -298,8 +298,7 @@ int last = options.getFirst() + options.getMax(); result = result.subList(options.getFirst(), Math.min(last, totalSize)); - return ImmediateFuture.newInstance(new RestfulCollection<Person>(result, options.getFirst(), - totalSize)); + return ImmediateFuture.newInstance(new RestfulCollection<Person>(result, options.getFirst(), totalSize, options.getMax())); } catch (JSONException je) { throw new ProtocolException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, je.getMessage(), je);