Search in sources :

Example 11 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testBatchGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
public void testBatchGet(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
    Request<BatchResponse<Greeting>> request = new GreetingsBuilders(requestOptions).batchGet().ids(ids).build();
    Response<BatchResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
    BatchResponse<Greeting> batchResponse = response.getEntity();
    Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Also used : GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchResponse(com.linkedin.restli.common.BatchResponse) Test(org.testng.annotations.Test)

Example 12 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class TestSimpleResourceHierarchy method testSubCollectionBatchGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionBatchGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
    Request<BatchResponse<Greeting>> request = new SubgreetingsBuilders(requestOptions).batchGet().ids(ids).build();
    Response<BatchResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
    BatchResponse<Greeting> batchResponse = response.getEntity();
    Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchResponse(com.linkedin.restli.common.BatchResponse) SubgreetingsBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsBuilders) Test(org.testng.annotations.Test)

Example 13 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class MockBatchResponseFactory method create.

/**
   * Creates a {@link com.linkedin.restli.common.BatchResponse}
   *
   * @param entryClass the class of the elements stored in this {@link com.linkedin.restli.common.BatchResponse}
   * @param recordTemplates the elements to be stored in this {@link com.linkedin.restli.common.BatchResponse}
   * @param <T> class of the elements stored in this {@link com.linkedin.restli.common.BatchResponse}
   * @return a {@link com.linkedin.restli.common.BatchResponse} with the above properties
   */
public static <T extends RecordTemplate> BatchResponse<T> create(Class<T> entryClass, Map<String, T> recordTemplates) {
    DataMap batchResponseDataMap = new DataMap();
    DataMap rawBatchData = new DataMap();
    batchResponseDataMap.put(BatchResponse.RESULTS, rawBatchData);
    for (Map.Entry<String, T> entry : recordTemplates.entrySet()) {
        rawBatchData.put(entry.getKey(), entry.getValue().data());
    }
    return new BatchResponse<T>(batchResponseDataMap, entryClass);
}
Also used : BatchResponse(com.linkedin.restli.common.BatchResponse) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 14 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class BatchGetResponseBuilder method toBatchResponse.

private static <K, V extends RecordTemplate> BatchResponse<AnyRecord> toBatchResponse(Map<K, EntityResponse<V>> entities, ProtocolVersion protocolVersion) {
    final DataMap splitResponseData = new DataMap();
    final DataMap splitResults = new DataMap();
    final DataMap splitStatuses = new DataMap();
    final DataMap splitErrors = new DataMap();
    for (Map.Entry<K, EntityResponse<V>> resultEntry : entities.entrySet()) {
        final DataMap entityResponseData = resultEntry.getValue().data();
        final String stringKey = URIParamUtils.encodeKeyForBody(resultEntry.getKey(), false, protocolVersion);
        final DataMap entityData = entityResponseData.getDataMap(EntityResponse.ENTITY);
        if (entityData != null) {
            CheckedUtil.putWithoutChecking(splitResults, stringKey, entityData);
        }
        final Integer status = entityResponseData.getInteger(EntityResponse.STATUS);
        if (status != null) {
            CheckedUtil.putWithoutChecking(splitStatuses, stringKey, status);
        }
        final DataMap error = entityResponseData.getDataMap(EntityResponse.ERROR);
        if (error != null) {
            CheckedUtil.putWithoutChecking(splitErrors, stringKey, error);
        }
    }
    CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.RESULTS, splitResults);
    CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.STATUSES, splitStatuses);
    CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.ERRORS, splitErrors);
    return new BatchResponse<AnyRecord>(splitResponseData, AnyRecord.class);
}
Also used : EntityResponse(com.linkedin.restli.common.EntityResponse) BatchResponse(com.linkedin.restli.common.BatchResponse) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Example 15 with BatchResponse

use of com.linkedin.restli.common.BatchResponse in project rest.li by linkedin.

the class BatchUpdateResponseBuilder method toBatchResponse.

private static <K> BatchResponse<AnyRecord> toBatchResponse(Map<K, UpdateStatus> statuses, ProtocolVersion protocolVersion) {
    final DataMap splitResponseData = new DataMap();
    final DataMap splitStatuses = new DataMap();
    final DataMap splitErrors = new DataMap();
    for (Map.Entry<K, UpdateStatus> statusEntry : statuses.entrySet()) {
        final DataMap statusData = statusEntry.getValue().data();
        final String stringKey = URIParamUtils.encodeKeyForBody(statusEntry.getKey(), false, protocolVersion);
        final DataMap error = statusData.getDataMap("error");
        if (error == null) {
            // status and error should be mutually exclusive for now
            CheckedUtil.putWithoutChecking(splitStatuses, stringKey, statusData);
        } else {
            CheckedUtil.putWithoutChecking(splitErrors, stringKey, error);
        }
    }
    CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.RESULTS, splitStatuses);
    CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.ERRORS, splitErrors);
    return new BatchResponse<AnyRecord>(splitResponseData, AnyRecord.class);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) BatchResponse(com.linkedin.restli.common.BatchResponse) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap)

Aggregations

BatchResponse (com.linkedin.restli.common.BatchResponse)25 Test (org.testng.annotations.Test)19 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)9 HashMap (java.util.HashMap)8 DataMap (com.linkedin.data.DataMap)6 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)6 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)6 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)6 ResourceContext (com.linkedin.restli.server.ResourceContext)6 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)5 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 UpdateStatus (com.linkedin.restli.common.UpdateStatus)4 Foo (com.linkedin.pegasus.generator.examples.Foo)3 HashSet (java.util.HashSet)3 RestClient (com.linkedin.restli.client.RestClient)2 CreateStatus (com.linkedin.restli.common.CreateStatus)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2