use of com.linkedin.restli.internal.server.response.BatchFinderResponseEnvelope.BatchFinderEntry in project rest.li by linkedin.
the class BatchFinderResponseBuilder method buildRestLiResponseData.
@Override
@SuppressWarnings("unchecked")
public RestLiResponseData<BatchFinderResponseEnvelope> buildRestLiResponseData(Request request, RoutingResult routingResult, Object object, Map<String, String> headers, List<HttpCookie> cookies) {
BatchFinderResult<RecordTemplate, RecordTemplate, RecordTemplate> result = (BatchFinderResult<RecordTemplate, RecordTemplate, RecordTemplate>) object;
DataList criteriaParams = getCriteriaParameters(routingResult);
List<BatchFinderEntry> collectionResponse = new ArrayList<>(criteriaParams.size());
final ResourceContextImpl resourceContext = (ResourceContextImpl) routingResult.getContext();
TimingContextUtil.beginTiming(routingResult.getContext().getRawRequestContext(), FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());
for (Object criteriaParam : criteriaParams.values()) {
RecordTemplate criteria = new AnyRecord((DataMap) criteriaParam);
BatchFinderEntry entry;
if (result.getResults().containsKey(criteria)) {
CollectionResult<RecordTemplate, RecordTemplate> cr = result.getResult(criteria);
// Process elements
List<AnyRecord> elements = buildElements(cr, resourceContext);
// Process paging
final CollectionMetadata projectedPaging = buildPaginationMetaData(routingResult, criteria, resourceContext, request, cr);
// Process metadata
final AnyRecord projectedCustomMetadata = buildMetaData(cr, resourceContext);
entry = new BatchFinderEntry(elements, projectedPaging, projectedCustomMetadata);
} else if (result.getErrors().containsKey(criteria)) {
entry = new BatchFinderEntry(result.getErrors().get(criteria));
} else {
entry = new BatchFinderEntry(new RestLiServiceException(S_404_NOT_FOUND, "The server didn't find a representation for this criteria"));
}
collectionResponse.add(entry);
}
TimingContextUtil.endTiming(routingResult.getContext().getRawRequestContext(), FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());
return new RestLiResponseDataImpl<>(new BatchFinderResponseEnvelope(HttpStatus.S_200_OK, collectionResponse), headers, cookies);
}
use of com.linkedin.restli.internal.server.response.BatchFinderResponseEnvelope.BatchFinderEntry in project rest.li by linkedin.
the class BatchFinderResponseBuilder method buildResponse.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public RestLiResponse buildResponse(RoutingResult routingResult, RestLiResponseData<BatchFinderResponseEnvelope> responseData) {
BatchFinderResponseEnvelope response = responseData.getResponseEnvelope();
DataMap dataMap = new DataMap();
DataList elementsMap = new DataList();
for (BatchFinderEntry entry : response.getItems()) {
CheckedUtil.addWithoutChecking(elementsMap, entry.toResponse(_errorResponseBuilder));
}
CheckedUtil.putWithoutChecking(dataMap, CollectionResponse.ELEMENTS, elementsMap);
BatchCollectionResponse<?> collectionResponse = new BatchCollectionResponse<>(dataMap, null);
RestLiResponse.Builder builder = new RestLiResponse.Builder();
return builder.entity(collectionResponse).headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
Aggregations