use of com.linkedin.restli.internal.server.methods.AnyRecord in project rest.li by linkedin.
the class BatchGetResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public PartialRestResponse buildResponse(RoutingResult routingResult, RestLiResponseData responseData) {
final Map<Object, BatchResponseEntry> responses = (Map<Object, BatchResponseEntry>) responseData.getBatchResponseEnvelope().getBatchResponseMap();
// Build the EntityResponse for each key from the merged map with mask from routingResult.
Map<Object, EntityResponse<RecordTemplate>> entityBatchResponse = buildEntityResponse(routingResult, responses);
PartialRestResponse.Builder builder = new PartialRestResponse.Builder();
final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
@SuppressWarnings("unchecked") final BatchResponse<AnyRecord> response = toBatchResponse(entityBatchResponse, protocolVersion);
builder.entity(response);
return builder.headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
use of com.linkedin.restli.internal.server.methods.AnyRecord in project rest.li by linkedin.
the class BatchUpdateResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public PartialRestResponse buildResponse(RoutingResult routingResult, RestLiResponseData responseData) {
Map<Object, UpdateStatus> mergedResults = new HashMap<Object, UpdateStatus>();
final Map<Object, BatchResponseEntry> responses = (Map<Object, BatchResponseEntry>) responseData.getBatchResponseEnvelope().getBatchResponseMap();
generateResultEntityResponse(routingResult, responses, mergedResults);
PartialRestResponse.Builder builder = new PartialRestResponse.Builder();
final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
@SuppressWarnings("unchecked") final BatchResponse<AnyRecord> response = toBatchResponse(mergedResults, protocolVersion);
return builder.entity(response).headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
use of com.linkedin.restli.internal.server.methods.AnyRecord in project rest.li by linkedin.
the class CreateResponseBuilder method buildRestLiResponseData.
@Override
public RestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
CreateResponse createResponse = (CreateResponse) result;
if (createResponse.hasError()) {
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(createResponse.getError(), headers, cookies);
responseData.setResponseEnvelope(new CreateResponseEnvelope(null, responseData));
return responseData;
}
Object id = null;
if (createResponse.hasId()) {
id = ResponseUtils.translateCanonicalKeyToAlternativeKeyIfNeeded(createResponse.getId(), routingResult);
final ProtocolVersion protocolVersion = ((ServerResourceContext) routingResult.getContext()).getRestliProtocolVersion();
String stringKey = URIParamUtils.encodeKeyForUri(id, UriComponent.Type.PATH_SEGMENT, protocolVersion);
UriBuilder uribuilder = UriBuilder.fromUri(request.getURI());
uribuilder.path(stringKey);
if (routingResult.getContext().hasParameter(RestConstants.ALT_KEY_PARAM)) {
// add altkey param to location URI
uribuilder.queryParam(RestConstants.ALT_KEY_PARAM, routingResult.getContext().getParameter(RestConstants.ALT_KEY_PARAM));
}
headers.put(RestConstants.HEADER_LOCATION, uribuilder.build((Object) null).toString());
headers.put(HeaderUtil.getIdHeaderName(protocolVersion), URIParamUtils.encodeKeyForHeader(id, protocolVersion));
}
//Verify that a null status was not passed into the CreateResponse. If so, this is a developer error.
if (createResponse.getStatus() == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. HttpStatus is null inside of a CreateResponse from the resource method: " + routingResult.getResourceMethod());
}
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(createResponse.getStatus(), headers, cookies);
CreateResponseEnvelope responseEnvelope;
if (createResponse instanceof CreateKVResponse) {
final ResourceContext resourceContext = routingResult.getContext();
DataMap entityData = ((CreateKVResponse) createResponse).getEntity().data();
final DataMap data = RestUtils.projectFields(entityData, resourceContext.getProjectionMode(), resourceContext.getProjectionMask());
responseEnvelope = new CreateResponseEnvelope(new AnyRecord(data), true, responseData);
} else //Instance of idResponse
{
IdResponse<?> idResponse = new IdResponse<Object>(id);
responseEnvelope = new CreateResponseEnvelope(idResponse, responseData);
}
responseData.setResponseEnvelope(responseEnvelope);
return responseData;
}
use of com.linkedin.restli.internal.server.methods.AnyRecord in project rest.li by linkedin.
the class BatchGetResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public RestLiResponse buildResponse(RoutingResult routingResult, RestLiResponseData<BatchGetResponseEnvelope> responseData) {
final Map<Object, BatchResponseEntry> responses = (Map<Object, BatchResponseEntry>) responseData.getResponseEnvelope().getBatchResponseMap();
// Build the EntityResponse for each key from the merged map with mask from routingResult.
Map<Object, EntityResponse<RecordTemplate>> entityBatchResponse = buildEntityResponse(routingResult, responses);
RestLiResponse.Builder builder = new RestLiResponse.Builder();
final ProtocolVersion protocolVersion = routingResult.getContext().getRestliProtocolVersion();
@SuppressWarnings("unchecked") final BatchResponse<AnyRecord> response = toBatchResponse(entityBatchResponse, protocolVersion);
builder.entity(response);
return builder.headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
use of com.linkedin.restli.internal.server.methods.AnyRecord in project rest.li by linkedin.
the class BatchPartialUpdateResponseBuilder method buildUpdateStatus.
/**
* Defines how to build an update status for batch partial update. If the update response is an {@link UpdateEntityResponse}
* and the client is requesting the entities to be returned, then build an {@link UpdateEntityStatus} containing the
* entity to be returned for a given update response.
* @param resourceContext current resource context
* @param updateResponse update response returned by the resource method
* @return update status possibly containing the returned entity
*/
@Override
protected UpdateStatus buildUpdateStatus(ResourceContext resourceContext, UpdateResponse updateResponse) {
if (updateResponse instanceof UpdateEntityResponse && resourceContext.isReturnEntityRequested()) {
final RecordTemplate entity = ((UpdateEntityResponse<?>) updateResponse).getEntity();
final DataMap entityData = entity != null ? entity.data() : null;
final DataMap projectedData = RestUtils.projectFields(entityData, resourceContext);
return new UpdateEntityStatus<>(updateResponse.getStatus().getCode(), new AnyRecord(projectedData));
} else {
return super.buildUpdateStatus(resourceContext, updateResponse);
}
}
Aggregations