Search in sources :

Example 6 with ResponseImpl

use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.

the class BatchGetRequestUtil method unbatchKVResponse.

/**
 * Extract the get response for this resource out of an auto-batched batch response.
 * This is pure rest.li logic, and it complements the auto-batching logic in BatchGetRequestBuilder.
 * @throws com.linkedin.r2.RemoteInvocationException if the server returned an error response for this resource,
 * or if it returned neither a result nor an error.
 */
public static <K, V extends RecordTemplate> Response<V> unbatchKVResponse(Request<BatchKVResponse<K, V>> request, Response<BatchKVResponse<K, V>> batchResponse, K id) throws RemoteInvocationException {
    final BatchKVResponse<K, V> batchEntity = batchResponse.getEntity();
    final ErrorResponse errorResponse = batchEntity.getErrors().get(id);
    if (errorResponse != null) {
        throw new RestLiResponseException(errorResponse);
    }
    final V entityResult = batchEntity.getResults().get(id);
    if (entityResult == null) {
        throw new RestLiDecodingException("No result or error for base URI " + request.getBaseUriTemplate() + ", id " + id + ". Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", null);
    }
    return new ResponseImpl<>(batchResponse, entityResult);
}
Also used : ResponseImpl(com.linkedin.restli.internal.client.ResponseImpl) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 7 with ResponseImpl

use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.

the class TestDefaultScatterGatherStrategy method createBatchKVResponse.

private static Response<BatchKVResponse<Long, UpdateStatus>> createBatchKVResponse(ProtocolVersion version, Set<Long> resultKeys, Set<Long> errorKeys) {
    DataMap resultMap = new DataMap();
    DataMap errorMap = new DataMap();
    for (Long id : resultKeys) {
        resultMap.put(id.toString(), new UpdateStatus().setStatus(HttpStatus.S_200_OK.getCode()).data());
    }
    for (Long id : errorKeys) {
        ErrorResponse err = new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode());
        errorMap.put(id.toString(), err.data());
    }
    DataMap responseMap = new DataMap();
    responseMap.put(BatchResponse.RESULTS, resultMap);
    responseMap.put(BatchResponse.ERRORS, errorMap);
    DataMap mergedMap = ResponseDecoderUtil.mergeUpdateStatusResponseData(responseMap);
    BatchKVResponse<Long, UpdateStatus> response = new BatchKVResponse<>(mergedMap, new TypeSpec<>(Long.class), new TypeSpec<>(UpdateStatus.class), Collections.emptyMap(), version);
    return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) ResponseImpl(com.linkedin.restli.internal.client.ResponseImpl) DataMap(com.linkedin.data.DataMap) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 8 with ResponseImpl

use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.

the class TestDefaultScatterGatherStrategy method createBatchGetKVResponse.

private static Response<BatchKVResponse<Long, TestRecord>> createBatchGetKVResponse(ProtocolVersion version, Set<Long> resultKeys, Set<Long> errorKeys) {
    DataMap resultMap = new DataMap();
    for (Long id : resultKeys) {
        resultMap.put(id.toString(), new TestRecord().setId(id).data());
    }
    DataMap errorMap = new DataMap();
    for (Long id : errorKeys) {
        errorMap.put(id.toString(), new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode()).data());
    }
    DataMap responseMap = new DataMap();
    responseMap.put(BatchResponse.RESULTS, resultMap);
    responseMap.put(BatchResponse.ERRORS, errorMap);
    BatchKVResponse<Long, TestRecord> response = new BatchKVResponse<>(responseMap, new TypeSpec<>(Long.class), new TypeSpec<>(TestRecord.class), Collections.emptyMap(), null, version);
    return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
Also used : TestRecord(com.linkedin.restli.client.test.TestRecord) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) ResponseImpl(com.linkedin.restli.internal.client.ResponseImpl) DataMap(com.linkedin.data.DataMap) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 9 with ResponseImpl

use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.

the class TestDefaultScatterGatherStrategy method createBatchEntityResponse.

private static Response<BatchKVResponse<Long, EntityResponse<TestRecord>>> createBatchEntityResponse(ProtocolVersion version, Set<Long> resultKeys, Set<Long> errorKeys) {
    DataMap resultMap = new DataMap();
    for (Long id : resultKeys) {
        resultMap.put(id.toString(), new EntityResponse<>(TestRecord.class).setEntity(new TestRecord().setId(id)).setStatus(HttpStatus.S_200_OK).data());
    }
    DataMap errorMap = new DataMap();
    for (Long id : errorKeys) {
        errorMap.put(id.toString(), new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode()).data());
    }
    DataMap responseMap = new DataMap();
    responseMap.put(BatchResponse.RESULTS, resultMap);
    responseMap.put(BatchResponse.ERRORS, errorMap);
    BatchEntityResponse<Long, TestRecord> response = new BatchEntityResponse<>(responseMap, new TypeSpec<>(Long.class), new TypeSpec<>(TestRecord.class), Collections.emptyMap(), null, version);
    return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
Also used : BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) BatchEntityResponse(com.linkedin.restli.internal.client.response.BatchEntityResponse) BatchUpdateEntityResponse(com.linkedin.restli.internal.client.response.BatchUpdateEntityResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) TestRecord(com.linkedin.restli.client.test.TestRecord) ResponseImpl(com.linkedin.restli.internal.client.ResponseImpl) DataMap(com.linkedin.data.DataMap) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 10 with ResponseImpl

use of com.linkedin.restli.internal.client.ResponseImpl in project rest.li by linkedin.

the class TestDefaultScatterGatherStrategy method createBatchResponse.

private static Response<BatchResponse<TestRecord>> createBatchResponse(Set<Long> resultKeys, Set<Long> errorKeys) {
    DataMap resultMap = new DataMap();
    for (Long id : resultKeys) {
        resultMap.put(id.toString(), new TestRecord().setId(id).data());
    }
    DataMap errorMap = new DataMap();
    for (Long id : errorKeys) {
        errorMap.put(id.toString(), new ErrorResponse().setStatus(HttpStatus.S_404_NOT_FOUND.getCode()).data());
    }
    DataMap responseMap = new DataMap();
    responseMap.put(BatchResponse.RESULTS, resultMap);
    responseMap.put(BatchResponse.ERRORS, errorMap);
    BatchResponse<TestRecord> response = new BatchResponse<>(responseMap, TestRecord.class);
    return new ResponseImpl<>(HttpStatus.S_200_OK.getCode(), Collections.emptyMap(), Collections.emptyList(), response, null);
}
Also used : BatchResponse(com.linkedin.restli.common.BatchResponse) TestRecord(com.linkedin.restli.client.test.TestRecord) ResponseImpl(com.linkedin.restli.internal.client.ResponseImpl) DataMap(com.linkedin.data.DataMap) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Aggregations

ResponseImpl (com.linkedin.restli.internal.client.ResponseImpl)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)9 DataMap (com.linkedin.data.DataMap)6 TestRecord (com.linkedin.restli.client.test.TestRecord)4 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)3 EntityResponse (com.linkedin.restli.common.EntityResponse)3 BatchEntityResponse (com.linkedin.restli.internal.client.response.BatchEntityResponse)3 BatchResponse (com.linkedin.restli.common.BatchResponse)2 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)2 BatchUpdateEntityResponse (com.linkedin.restli.internal.client.response.BatchUpdateEntityResponse)2 Callback (com.linkedin.common.callback.Callback)1 PathSpec (com.linkedin.data.schema.PathSpec)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 Batch (com.linkedin.parseq.batching.Batch)1 BatchEntry (com.linkedin.parseq.batching.BatchImpl.BatchEntry)1 Tuple3 (com.linkedin.parseq.function.Tuple3)1 Tuples (com.linkedin.parseq.function.Tuples)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)1