use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class PhotoResource method update.
// update an existing photo with given entity
@Override
public UpdateResponse update(Long key, Photo entity) {
final Photo currPhoto = _db.getData().get(key);
if (currPhoto == null) {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
// ID and URN are required fields, so use a dummy value to denote "empty" fields
if ((entity.hasId() && entity.getId() != -1) || (entity.hasUrn() && !entity.getUrn().equals(""))) {
throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "Photo ID is not acceptable in request");
}
// make sure the ID in the entity is consistent with the key in the database
entity.setId(key);
entity.setUrn(String.valueOf(key));
_db.getData().put(key, entity);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class PhotoResource method update.
// allow partial update to an existing photo
@Override
public UpdateResponse update(Long key, PatchRequest<Photo> patchRequest) {
final Photo p = _db.getData().get(key);
if (p == null) {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
try {
PatchApplier.applyPatch(p, patchRequest);
} catch (DataProcessingException e) {
return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
}
// photo's id and URN should not be changed
p.setId(key);
p.setUrn(String.valueOf(key));
_db.getData().put(key, p);
return new UpdateResponse(HttpStatus.S_202_ACCEPTED);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class TestPhotoResource method testResourceDelete.
@Test
public void testResourceDelete() {
final Long id = createPhoto();
// validate response status code
final UpdateResponse uResp = _res.delete(id);
Assert.assertEquals(uResp.getStatus(), HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method delete.
public ExampleRequestResponse delete() {
checkSupports(ResourceMethod.DELETE);
DeleteRequestBuilder<Object, RecordTemplatePlaceholder> delete = new DeleteRequestBuilder<>(_uriTemplate, RecordTemplatePlaceholder.class, _resourceSpec, _requestOptions);
if (_resourceSpec.getKeyType() != null) {
delete.id(generateKey());
}
addParams(delete, ResourceMethod.DELETE);
addPathKeys(delete);
DeleteRequest<RecordTemplatePlaceholder> request = delete.build();
return buildRequestResponse(request, new UpdateResponse(HttpStatus.S_200_OK), buildResourceMethodDescriptorForRestMethod(request));
}
use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method batchDelete.
public ExampleRequestResponse batchDelete() {
checkSupports(ResourceMethod.BATCH_DELETE);
BatchDeleteRequestBuilder<Object, RecordTemplatePlaceholder> delete = new BatchDeleteRequestBuilder<>(_uriTemplate, RecordTemplatePlaceholder.class, _resourceSpec, _requestOptions);
Object id1 = generateKey(0);
Object id2 = generateKey(1);
delete.ids(id1, id2);
addParams(delete, ResourceMethod.BATCH_DELETE);
addPathKeys(delete);
BatchDeleteRequest<Object, RecordTemplatePlaceholder> request = delete.build();
final Map<Object, UpdateResponse> bdResponseData = new HashMap<>();
bdResponseData.put(id1, new UpdateResponse(HttpStatus.S_200_OK));
bdResponseData.put(id2, new UpdateResponse(HttpStatus.S_200_OK));
BatchUpdateResult<Object, RecordTemplatePlaceholder> result = new BatchUpdateResult<>(bdResponseData);
return buildRequestResponse(request, result, buildResourceMethodDescriptorForRestMethod(request));
}
Aggregations