private static <K, RT extends RecordTemplate> Response<RT> unbatchResponse(BatchGetEntityRequest<K, RT> request, Response<BatchKVResponse<K, EntityResponse<RT>>> batchResponse, Object id) throws RemoteInvocationException { final BatchKVResponse<K, EntityResponse<RT>> batchEntity = batchResponse.getEntity(); final ErrorResponse errorResponse = batchEntity.getErrors().get(id); if (errorResponse != null) { throw new RestLiResponseException(errorResponse); } final EntityResponse<RT> entityResponse = batchEntity.getResults().get(id); if (entityResponse != null) { final RT entityResult = entityResponse.getEntity(); if (entityResult != null) { return new ResponseImpl<>(batchResponse, entityResult); } } LOGGER.debug("No result or error for base URI : {}, id: {}. Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", request.getBaseUriTemplate(), id); throw NOT_FOUND_EXCEPTION; }
@SuppressWarnings({ "deprecation" }) private void successBatchGetEntity(BatchGetEntityRequest request, Response<BatchKVResponse<K, EntityResponse<RT>>> responseToBatch, Entry<RestRequestBatchKey, BatchEntry<Response<Object>>> entry, final ProtocolVersion version) { Set<String> ids = (Set<String>) request.getObjectIds().stream() .map(o -> BatchResponse.keyToString(o, version)) .collect(Collectors.toSet()); DataMap dm = filterIdsInBatchResult(responseToBatch.getEntity().data(), ids); BatchKVResponse br = new BatchEntityResponse<>(dm, request.getResourceSpec().getKeyType(), request.getResourceSpec().getValueType(), request.getResourceSpec().getKeyParts(), request.getResourceSpec().getComplexKeyType(), version); Response rsp = new ResponseImpl(responseToBatch, br); entry.getValue().getPromise().done(rsp); }
final ResourceSpec firstResourceSpec = firstRequest.getResourceSpec(); final Map<String, Object> batchQueryParams = getReadOnlyQueryParameters(BatchGetRequestUtil.getBatchQueryParam(requests, batchFields)); return new BatchGetEntityRequest<K, V>(firstRequest.getHeaders(), firstRequest.getCookies(), firstRequest.getResponseDecoder(), batchQueryParams, firstRequest.getQueryParamClasses(), firstResourceSpec, firstRequest.getBaseUriTemplate(), firstRequest.getPathKeys(), firstRequest.getRequestOptions());
final Set<K> idObjects = (Set<K>) request.getObjectIds(); final BatchGetEntityRequestBuilder<K, T> builder = new BatchGetEntityRequestBuilder<K, T>(request.getBaseUriTemplate(), request.getResponseDecoder(), request.getResourceSpec(), request.getRequestOptions()); builder.ids(batch.getValue()); for (Map.Entry<String, Object> param : request.getQueryParamsObjects().entrySet()) for (Map.Entry<String, String> header : request.getHeaders().entrySet())
/** * Builds a GET request for this resource batch. * * @return a read request for the resource batch */ @Override public BatchGetEntityRequest<K, V> build() { ensureBatchKeys(); return new BatchGetEntityRequest<K, V>(buildReadOnlyHeaders(), buildReadOnlyCookies(), _decoder, buildReadOnlyQueryParameters(), getQueryParamClasses(), _resourceSpec, getBaseUriTemplate(), buildReadOnlyPathKeys(), getRequestOptions()); }