use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchUpdate.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchUpdate(BatchPatchRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> patches) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<>();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> patch : patches.getData().entrySet()) {
try {
this.partialUpdate(patch.getKey(), patch.getValue());
results.put(patch.getKey(), new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} catch (DataProcessingException e) {
results.put(patch.getKey(), new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
}
}
return new BatchUpdateResult<>(results);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchDelete.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchDelete(BatchDeleteRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> ids) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<>();
for (ComplexResourceKey<TwoPartKey, TwoPartKey> id : ids.getKeys()) {
_db.remove(keyToString(id.getKey()));
results.put(id, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
}
return new BatchUpdateResult<>(results);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class BatchGreetingResource method update.
@RestMethod.PartialUpdate
public UpdateResponse update(Long id, PatchRequest<Greeting> patch) {
Greeting greeting = DB.get(id);
try {
PatchApplier.applyPatch(greeting, patch);
} catch (DataProcessingException e) {
return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
}
DB.put(id, greeting);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class CustomTypesResource3 method batchUpdate.
@Override
public BatchUpdateResult<CompoundKey, Greeting> batchUpdate(BatchUpdateRequest<CompoundKey, Greeting> entities) {
Set<CompoundKey> keys = entities.getData().keySet();
Map<CompoundKey, UpdateResponse> responseMap = new HashMap<>();
Map<CompoundKey, RestLiServiceException> errorMap = new HashMap<>();
for (CompoundKey key : keys) {
responseMap.put(key, new UpdateResponse(HttpStatus.S_201_CREATED));
}
return new BatchUpdateResult<>(responseMap);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class PartialUpdateResponseBuilder method buildRestLiResponseData.
@Override
@SuppressWarnings({ "unchecked" })
public RestLiResponseData<PartialUpdateResponseEnvelope> buildRestLiResponseData(Request request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
UpdateResponse updateResponse = (UpdateResponse) result;
// Verify that the status in the UpdateResponse is not null. If so, this is a developer error.
if (updateResponse.getStatus() == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. HttpStatus is null inside of an UpdateResponse returned by the resource method: " + routingResult.getResourceMethod());
}
final ResourceContext resourceContext = routingResult.getContext();
RecordTemplate entityResponse = null;
// Add patched entity to the response if result is an UpdateEntityResponse and the client is asking for the entity
if (result instanceof UpdateEntityResponse && resourceContext.isReturnEntityRequested()) {
UpdateEntityResponse<?> updateEntityResponse = (UpdateEntityResponse<?>) updateResponse;
if (updateEntityResponse.hasEntity()) {
DataMap entityData = updateEntityResponse.getEntity().data();
TimingContextUtil.beginTiming(resourceContext.getRawRequestContext(), FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());
final DataMap data = RestUtils.projectFields(entityData, resourceContext);
TimingContextUtil.endTiming(resourceContext.getRawRequestContext(), FrameworkTimingKeys.SERVER_RESPONSE_RESTLI_PROJECTION_APPLY.key());
// Returned entity is to be added to the response envelope
entityResponse = new EntityResponse<>(data, updateEntityResponse.getEntity().getClass());
} else {
// If trying to return an error response, a RestLiServiceException should be thrown in the resource method.
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Entity is null inside of an UpdateEntityResponse returned by the resource method: " + routingResult.getResourceMethod());
}
}
return new RestLiResponseDataImpl<>(new PartialUpdateResponseEnvelope(updateResponse.getStatus(), entityResponse), headers, cookies);
}
Aggregations