use of com.linkedin.restli.server.BatchUpdateEntityResult in project rest.li by linkedin.
the class TestBatchPartialUpdateResponseBuilder method testProjectionInBuildRestLiResponseData.
/**
* Ensures that the returned entities are properly projected when a projection mask is passed into the response builder.
*/
@Test
@SuppressWarnings("unchecked")
public void testProjectionInBuildRestLiResponseData() {
final Long id = 1L;
TestRecord record = new TestRecord().setIntField(2147).setDoubleField(21.47).setFloatField(123F).setLongField(456L);
BatchUpdateEntityResult<Long, TestRecord> result = new BatchUpdateEntityResult<>(Collections.singletonMap(id, new UpdateEntityResponse<>(HttpStatus.S_200_OK, record)));
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("intField"), MaskOperation.POSITIVE_MASK_OP);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
RoutingResult routingResult = getMockRoutingResult(true, maskTree);
BatchPartialUpdateResponseBuilder batchPartialUpdateResponseBuilder = new BatchPartialUpdateResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData<BatchPartialUpdateResponseEnvelope> responseData = batchPartialUpdateResponseBuilder.buildRestLiResponseData(null, routingResult, result, headers, Collections.emptyList());
UpdateEntityStatus<TestRecord> updateEntityStatus = (UpdateEntityStatus<TestRecord>) responseData.getResponseEnvelope().getBatchResponseMap().get(id).getRecord();
Assert.assertNotNull(updateEntityStatus);
RecordTemplate returnedRecord = updateEntityStatus.getEntity();
Assert.assertEquals(returnedRecord.data().size(), 1, "Expected response record to be projected down to one field.");
Assert.assertEquals((int) returnedRecord.data().get("intField"), 2147, "Expected response record intField to match original.");
}
use of com.linkedin.restli.server.BatchUpdateEntityResult in project rest.li by linkedin.
the class LatencyInstrumentationResource method batchPartialUpdate.
/**
* This is the "downstream endpoint", queried by {@link #create(InstrumentationControl)} (the "upstream endpoint").
*/
@ReturnEntity
@RestMethod.BatchPartialUpdate
public BatchUpdateEntityResult<Long, InstrumentationControl> batchPartialUpdate(BatchPatchRequest<Long, InstrumentationControl> batchPatchRequest) throws DataProcessingException {
final Map<Long, UpdateEntityResponse<InstrumentationControl>> results = new HashMap<>();
final Map<Long, RestLiServiceException> errors = new HashMap<>();
for (Map.Entry<Long, PatchRequest<InstrumentationControl>> entry : batchPatchRequest.getData().entrySet()) {
// Render each patch into a normal record so we know whether or not to force a failure
InstrumentationControl control = new InstrumentationControl();
PatchApplier.applyPatch(control, entry.getValue());
if (control.isForceException()) {
RestLiServiceException error = new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You wanted me to fail, so I failed.").setCode(DOWNSTREAM_ERROR_CODE);
errors.put(entry.getKey(), error);
} else {
results.put(entry.getKey(), new UpdateEntityResponse<>(HttpStatus.S_200_OK, control));
}
}
return new BatchUpdateEntityResult<>(results, errors);
}
Aggregations