Search in sources :

Example 21 with UriBuilder

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;
}
Also used : UriBuilder(com.linkedin.jersey.api.uri.UriBuilder)

Example 22 with UriBuilder

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)");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UriBuilder(com.linkedin.jersey.api.uri.UriBuilder) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 23 with UriBuilder

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();
}
Also used : UriBuilder(com.linkedin.jersey.api.uri.UriBuilder) DataMap(com.linkedin.data.DataMap)

Example 24 with UriBuilder

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)");
}
Also used : DataList(com.linkedin.data.DataList) UriBuilder(com.linkedin.jersey.api.uri.UriBuilder) URI(java.net.URI) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 25 with UriBuilder

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);
}
Also used : DataList(com.linkedin.data.DataList) UriBuilder(com.linkedin.jersey.api.uri.UriBuilder) URI(java.net.URI) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

UriBuilder (com.linkedin.jersey.api.uri.UriBuilder)45 DataMap (com.linkedin.data.DataMap)9 URI (java.net.URI)6 Test (org.testng.annotations.Test)5 DataList (com.linkedin.data.DataList)3 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)2 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)2 CreateKVResponse (com.linkedin.restli.server.CreateKVResponse)2 CreateResponse (com.linkedin.restli.server.CreateResponse)2 ResourceContext (com.linkedin.restli.server.ResourceContext)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 HashMap (java.util.HashMap)2 MaskMap (com.linkedin.data.schema.MaskMap)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 IdResponse (com.linkedin.restli.common.IdResponse)1 QueryParamsDataMap (com.linkedin.restli.internal.common.QueryParamsDataMap)1 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)1 ArrayList (java.util.ArrayList)1