com.linkedin.restli.internal.common
Class QueryParamsDataMap

java.lang.Object
  extended by com.linkedin.restli.internal.common.QueryParamsDataMap

public class QueryParamsDataMap
extends java.lang.Object

A utility class for parsing query parameters map into a DataMap. Complex objects are represented by dot-delimited and possibly indexed parameter names. * @author adubman


Method Summary
static void addSortedParams(com.linkedin.jersey.api.uri.UriBuilder uriBuilder, com.linkedin.data.DataMap params)
          Same as above, but taking a DataMap representation of query parameters
static void addSortedParams(com.linkedin.jersey.api.uri.UriBuilder uriBuilder, java.util.Map<java.lang.String,java.util.List<java.lang.String>> params)
          Helper method to add the provided query params multimap to the provided UriBuilder, sorting both keys and values within the list for each key.
static java.lang.String dataMapToQueryString(com.linkedin.data.DataMap dataMap, URLEscaper.Escaping escaping)
          Helper method to convert a DataMap into a string by concatenating key-value pairs with "&", sorted by both key and value.
static ComplexResourceKey<?,?> fixUpComplexKeySingletonArray(ComplexResourceKey<?,?> complexResourceKey)
          Because of backwards compatibility concerns, array fields of the key component of a ComplexResourceKeys in a get request will be represented in the request url in the old style.
static com.linkedin.data.DataMap parseDataMapKeys(java.util.Map<java.lang.String,java.util.List<java.lang.String>> queryParameters)
          Parse a multi-map representing query parameters into a DataMap, as follows.
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> queryString(com.linkedin.data.DataMap dataMap)
          Create a map of query string parameters (name, value) from the provided DataMap, in the same manner as parseDataMapKeys() below created a DataMap from a map of query parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dataMapToQueryString

public static java.lang.String dataMapToQueryString(com.linkedin.data.DataMap dataMap,
                                                    URLEscaper.Escaping escaping)
Helper method to convert a DataMap into a string by concatenating key-value pairs with "&", sorted by both key and value.

Returns:
a String

queryString

public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> queryString(com.linkedin.data.DataMap dataMap)
Create a map of query string parameters (name, value) from the provided DataMap, in the same manner as parseDataMapKeys() below created a DataMap from a map of query parameters.

Parameters:
dataMap - a dataMap
Returns:
the map of query string parameters.

parseDataMapKeys

public static com.linkedin.data.DataMap parseDataMapKeys(java.util.Map<java.lang.String,java.util.List<java.lang.String>> queryParameters)
                                                  throws PathSegment.PathSegmentSyntaxException
Parse a multi-map representing query parameters into a DataMap, as follows. Multi-indexed parameter names, such as ids[0][2] or ids[0,2] are not currently supported. For example, the following query string: /groupMemberships?ids[0].params.versionTag=tag1&ids[0].params.authToken=tok1&ids[0].memberID=1&ids[0].groupID=2& \ ids[1].params.versionTag=tag2&ids[1].params.authToken=tok2&ids[1].memberID=2&ids[1].groupID=2& \ q=someFinder is parsed into the following data map: {"ids" : [ { "memberID" : "1", "groupID" : "2", "params" : { "authToken" : "tok1", "versionTag" : "tag1" } }, { "memberID" : "2", "groupID" : "2", "params" : { "authToken" : "tok2", "versionTag" : "tag2" } } ], "q" : "someFinder" } Note: at this point the data map is not typed - all names and values are parsed as strings. Note: when parsing indexed parameter names, those will be converted to a list, preserving the order of the values according to the index, but ignoring any possible "holes" in the index sequence. The index values therefore only serve to define order of the parameter values, rather than their actual position in any collection.

Parameters:
queryParameters - the query parameters
Returns:
- the DataMap represented by potentially hierarchical keys encoded by the multi-part parameter names.
Throws:
PathSegment.PathSegmentSyntaxException

addSortedParams

public static void addSortedParams(com.linkedin.jersey.api.uri.UriBuilder uriBuilder,
                                   java.util.Map<java.lang.String,java.util.List<java.lang.String>> params)
Helper method to add the provided query params multimap to the provided UriBuilder, sorting both keys and values within the list for each key.

Parameters:
uriBuilder -
params -

addSortedParams

public static void addSortedParams(com.linkedin.jersey.api.uri.UriBuilder uriBuilder,
                                   com.linkedin.data.DataMap params)
Same as above, but taking a DataMap representation of query parameters

Parameters:
uriBuilder -
params -

fixUpComplexKeySingletonArray

public static ComplexResourceKey<?,?> fixUpComplexKeySingletonArray(ComplexResourceKey<?,?> complexResourceKey)
Because of backwards compatibility concerns, array fields of the key component of a ComplexResourceKeys in a get request will be represented in the request url in the old style. That is, if an array field has the name "a", and contains [1,2] the part of the url representing the serialized array will look like "a=1&a=2". However, if the array is a singleton it will just be represented by "a=1". Therefore it is not possible to distinguish between a single value itself and an array containing a single value. The purpose of this function is to fix up the singleton array problem by checking to see whether the given ComplexKey's key part has an array component, and, if so and the data for that field is NOT a dataList, placing the data into a dataList.

Parameters:
complexResourceKey - The complex key to be fixed.