use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class GetAllRequestUriBuilder method getUriBuilderWithoutQueryParams.
@Override
protected UriBuilder getUriBuilderWithoutQueryParams() {
UriBuilder b = super.getUriBuilderWithoutQueryParams();
appendAssocKeys(b);
return b;
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class TestQueryParamsUtil method testConvertToDataMap.
@Test
public void testConvertToDataMap() {
Map<String, Object> queryParams = new HashMap<>();
Map<String, Object> hashMapParam = new HashMap<>();
hashMapParam.put("someField", "someValue");
hashMapParam.put("foo", "bar");
hashMapParam.put("notifications", ImmutableMap.of("a", "b"));
hashMapParam.put("type", Type.BOOLEAN);
List<Object> subList = new ArrayList<>();
subList.add("first");
subList.add(ImmutableMap.of("x", "1", "y", 2));
subList.add(ImmutableList.of(Type.ARRAY, Type.BYTES, Type.MAP));
hashMapParam.put("subList", subList);
List<Object> arrayListParam = new ArrayList<>();
arrayListParam.add("x");
arrayListParam.add("y");
arrayListParam.add(hashMapParam);
arrayListParam.add(Type.DOUBLE);
queryParams.put("hashMapParam", hashMapParam);
queryParams.put("arrayListParam", arrayListParam);
DataMap dataMapQueryParams = QueryParamsUtil.convertToDataMap(queryParams);
UriBuilder uriBuilder = new UriBuilder();
URIParamUtils.addSortedParams(uriBuilder, dataMapQueryParams);
String query = uriBuilder.build().getQuery();
Assert.assertEquals(query, "arrayListParam=List(x,y,(foo:bar,notifications:(a:b),someField:someValue,subList:List(first,(x:1,y:2),List(ARRAY,BYTES,MAP)),type:BOOLEAN),DOUBLE)" + "&hashMapParam=(foo:bar,notifications:(a:b),someField:someValue,subList:List(first,(x:1,y:2),List(ARRAY,BYTES,MAP)),type:BOOLEAN)");
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class URIParamUtils method replaceQueryParam.
/**
* replace the values of the given queryParam with new ones
* @param uri initial URI
* @param queryParam name of the queryParam
* @param values values of the queryParam
* @param parameters all parameters
* @param version The {@link ProtocolVersion}
*/
public static URI replaceQueryParam(URI uri, String queryParam, DataComplex values, DataMap parameters, ProtocolVersion version) {
UriBuilder builder = UriBuilder.fromPath(uri.getPath());
DataMap newQueryParams = new DataMap();
newQueryParams.putAll(parameters);
newQueryParams.put(queryParam, values);
URIParamUtils.addSortedParams(builder, newQueryParams, version);
return builder.build();
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class TestUriParamUtils method testProjectionMask.
@Test
public void testProjectionMask() {
DataMap queryParams = new DataMap();
DataMap fields = new DataMap();
fields.put("name", 1);
DataMap friends = new DataMap();
friends.put("$start", 1);
friends.put("$count", 2);
fields.put("friends", friends);
queryParams.put("fields", fields);
DataMap paramMap = new DataMap();
paramMap.put("foo", "bar");
paramMap.put("empty", new DataMap());
queryParams.put("aParam", paramMap);
DataList paramList = new DataList();
paramList.add("x");
paramList.add("y");
paramList.add("z");
queryParams.put("bParam", paramList);
UriBuilder uriBuilder = new UriBuilder();
URIParamUtils.addSortedParams(uriBuilder, queryParams);
URI uri = uriBuilder.build();
String query = uri.getQuery();
Assert.assertEquals(query, "aParam=(empty:(),foo:bar)&bParam=List(x,y,z)&fields=name,friends:($start:1,$count:2)");
String rawQuery = uri.getRawQuery();
Assert.assertEquals(rawQuery, "aParam=(empty:(),foo:bar)&bParam=List(x,y,z)&fields=name,friends:($start:1,$count:2)");
}
use of com.linkedin.jersey.api.uri.UriBuilder in project rest.li by linkedin.
the class TestUriParamUtils method replaceQueryParam.
@Test
public void replaceQueryParam() {
DataMap queryParams = new DataMap();
queryParams.put("bq", "batch_finder");
queryParams.put("page", "1");
queryParams.put("count", "10");
DataMap criteria1 = new DataMap();
criteria1.put("criteria1_fieldA", "valueA");
criteria1.put("criteria1_fieldB", "valueB");
criteria1.put("criteria1_fieldC", "valueC");
DataMap criteria2 = new DataMap();
criteria2.put("criteria2_fieldA", "valueA");
criteria2.put("criteria2_fieldB", "valueB");
criteria2.put("criteria2_fieldC", "valueC");
DataList paramList = new DataList();
paramList.add(criteria1);
paramList.add(criteria2);
queryParams.put("criteria", paramList);
UriBuilder uriBuilder = new UriBuilder();
URIParamUtils.addSortedParams(uriBuilder, queryParams);
URI uri = uriBuilder.build();
DataList newParamList = new DataList();
newParamList.add(criteria1);
URI replacedURIV1 = URIParamUtils.replaceQueryParam(uri, "criteria", newParamList, queryParams, AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion());
URI replacedURIV2 = URIParamUtils.replaceQueryParam(uri, "criteria", newParamList, queryParams, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion());
String expectedURI = "bq=batch_finder&count=10&criteria=List((criteria1_fieldA:valueA,criteria1_fieldB:valueB," + "criteria1_fieldC:valueC),(criteria2_fieldA:valueA,criteria2_fieldB:valueB,criteria2_fieldC:valueC))&page=1";
String expectedNewURIV2 = "bq=batch_finder&count=10&criteria=List((criteria1_fieldA:valueA,criteria1_fieldB:valueB," + "criteria1_fieldC:valueC))&page=1";
String expectedNewURIV1 = "bq=batch_finder&count=10&criteria[0].criteria1_fieldA=valueA" + "&criteria[0].criteria1_fieldB=valueB&criteria[0].criteria1_fieldC=valueC&page=1";
Assert.assertEquals(uri.getQuery(), expectedURI);
Assert.assertEquals(replacedURIV2.getQuery(), expectedNewURIV2);
Assert.assertEquals(replacedURIV1.getQuery(), expectedNewURIV1);
}
Aggregations