use of com.linkedin.restli.server.BatchUpdateResult in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchUpdate.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchUpdate(BatchUpdateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse>();
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException> errors = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException>();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entry : entities.getData().entrySet()) {
if (_db.containsKey(keyToString(entry.getKey().getKey()))) {
_db.put(keyToString(entry.getKey().getKey()), entry.getValue());
results.put(entry.getKey(), new UpdateResponse(HttpStatus.S_200_OK));
} else {
errors.put(entry.getKey(), new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(results, errors);
}
use of com.linkedin.restli.server.BatchUpdateResult in project rest.li by linkedin.
the class ExampleRequestResponseGenerator method batchDelete.
public ExampleRequestResponse batchDelete() {
checkSupports(ResourceMethod.BATCH_DELETE);
BatchDeleteRequestBuilder<Object, RecordTemplatePlaceholder> delete = new BatchDeleteRequestBuilder<Object, RecordTemplatePlaceholder>(_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<Object, UpdateResponse>();
bdResponseData.put(id1, new UpdateResponse(HttpStatus.S_200_OK));
bdResponseData.put(id2, new UpdateResponse(HttpStatus.S_200_OK));
BatchUpdateResult<Object, RecordTemplatePlaceholder> result = new BatchUpdateResult<Object, RecordTemplatePlaceholder>(bdResponseData);
return buildRequestResponse(request, result, buildResourceMethodDescriptorForRestMethod(request));
}
use of com.linkedin.restli.server.BatchUpdateResult in project rest.li by linkedin.
the class ValidationDemoResource method batchUpdate.
@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchPatchRequest<Integer, ValidationDemo> entityUpdates, @ValidatorParam RestLiDataValidator validator) {
Map<Integer, UpdateResponse> results = new HashMap<Integer, UpdateResponse>();
Map<Integer, RestLiServiceException> errors = new HashMap<Integer, RestLiServiceException>();
for (Map.Entry<Integer, PatchRequest<ValidationDemo>> entry : entityUpdates.getData().entrySet()) {
Integer key = entry.getKey();
PatchRequest<ValidationDemo> patch = entry.getValue();
ValidationResult result = validator.validateInput(patch);
if (result.isValid()) {
results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_422_UNPROCESSABLE_ENTITY, result.getMessages().toString()));
}
}
return new BatchUpdateResult<Integer, ValidationDemo>(results, errors);
}
use of com.linkedin.restli.server.BatchUpdateResult in project rest.li by linkedin.
the class NullGreetingsResourceImpl method batchUpdate.
@RestMethod.BatchUpdate
public BatchUpdateResult<Long, Greeting> batchUpdate(BatchUpdateRequest<Long, Greeting> entities) {
final Map<Long, UpdateResponse> responseMap = new HashMap<Long, UpdateResponse>();
responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
final Map<Long, RestLiServiceException> errorsMap = new HashMap<Long, RestLiServiceException>();
errorsMap.put(8l, new RestLiServiceException(HttpStatus.S_202_ACCEPTED));
if (entities.getData().containsKey(1l)) {
//Return a null BatchUpdateResult
return null;
} else if (entities.getData().containsKey(2l)) {
//Return a BatchUpdateResult with a null results Map
return new BatchUpdateResult<Long, Greeting>(null);
} else if (entities.getData().containsKey(3l)) {
//Return a BatchUpdateResult with a null errors Map
return new BatchUpdateResult<Long, Greeting>(responseMap, null);
} else if (entities.getData().containsKey(4l)) {
//Return a BatchUpdateResult with a errors Map that has a null key in it
errorsMap.put(null, new RestLiServiceException(HttpStatus.S_202_ACCEPTED));
return new BatchUpdateResult<Long, Greeting>(responseMap, errorsMap);
} else if (entities.getData().containsKey(5l)) {
//Return a BatchUpdateResult with a errors Map that has a null value in it
errorsMap.put(9l, null);
return new BatchUpdateResult<Long, Greeting>(responseMap, errorsMap);
} else if (entities.getData().containsKey(6l)) {
//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<Long, Greeting>(responseMap);
} else {
/*
* Return a BatchUpdateResult with java.util.concurrent.ConcurrentHashMap(s).
* This test is in place because certain map implementations, such as ConcurrentHashMap, can throw an NPE when
* calling contains(null). We want to verify that checking for the existence of nulls in maps returned by
* Rest.li resource methods do not cause such NPEs.
* This is one of the few cases in this file where an error will not be generated by Rest.li.
*/
final Map<Long, UpdateResponse> concurrentResponseMap = new ConcurrentHashMap<Long, UpdateResponse>(responseMap);
return new BatchUpdateResult<Long, Greeting>(concurrentResponseMap, new ConcurrentHashMap<Long, RestLiServiceException>());
}
}
use of com.linkedin.restli.server.BatchUpdateResult in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchUpdateCollection.
@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchUpdateCollection() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchUpdateRequest batchUpdateRequest = (BatchUpdateRequest) EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchUpdateRequest)).andReturn(Promises.<BatchUpdateResult<Long, Status>>value(null)).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "PUT", version, "/promisestatuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
Aggregations