use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class NullGreetingsResourceImpl method batchUpdate.
@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Long, Greeting> batchUpdate(BatchPatchRequest<Long, Greeting> entityUpdates) {
final Map<Long, UpdateResponse> responseMap = new HashMap<>();
responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
if (entityUpdates.getData().containsKey(1l)) {
// Return a null BatchUpdateResult
return null;
} else if (entityUpdates.getData().containsKey(2l)) {
// Return a BatchUpdateResult with a null results Map
return new BatchUpdateResult<>(null);
} else if (entityUpdates.getData().containsKey(3l)) {
// Return a BatchUpdateResult with a null errors Map
return new BatchUpdateResult<>(responseMap, null);
} else {
// Return a BatchUpdateResult with a map that has a null key in it
responseMap.put(null, 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 SimpleResourceUnderCollectionResource method update.
/**
* Updates the greeting.
*/
@Override
public UpdateResponse update(PatchRequest<Greeting> patchRequest) {
Long key = this.getContext().getPathKeys().get("subgreetingsId");
if (TONES.containsKey(key)) {
try {
Greeting patched = new Greeting();
PatchApplier.applyPatch(patched, patchRequest);
TONES.put(key, patched.getTone());
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
} catch (DataProcessingException e) {
return new UpdateResponse((HttpStatus.S_400_BAD_REQUEST));
}
} else {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class GreetingsResourceImpl method update.
@RestMethod.PartialUpdate
public UpdateResponse update(Long key, PatchRequest<Greeting> patch) {
Greeting g = _db.get(key);
if (g == null) {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
try {
PatchApplier.applyPatch(g, patch);
} catch (DataProcessingException e) {
return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
}
_db.put(key, g);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestUpdateResponseBuilder method testBuilderException.
@Test
public void testBuilderException() {
UpdateResponse updateResponse = new UpdateResponse(null);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
UpdateResponseBuilder updateResponseBuilder = new UpdateResponseBuilder();
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
try {
updateResponseBuilder.buildRestLiResponseData(null, routingResult, updateResponse, headers, Collections.emptyList());
Assert.fail("buildRestLiResponseData should have failed because of a null HTTP status!");
} catch (RestLiServiceException e) {
Assert.assertTrue(e.getMessage().contains("Unexpected null encountered. HttpStatus is null inside of a UpdateResponse returned by the resource method: "));
}
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class AutomaticValidationDemoResource method batchUpdate.
@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchPatchRequest<Integer, ValidationDemo> entityUpdates) {
Map<Integer, UpdateResponse> results = new HashMap<>();
Map<Integer, RestLiServiceException> errors = new HashMap<>();
for (Map.Entry<Integer, PatchRequest<ValidationDemo>> entry : entityUpdates.getData().entrySet()) {
Integer key = entry.getKey();
PatchRequest<ValidationDemo> patch = entry.getValue();
results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
}
return new BatchUpdateResult<>(results, errors);
}
Aggregations