use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testComplexKey_partialUpdate.
@Test
public void testComplexKey_partialUpdate() throws Exception {
ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Message message = new Message();
message.setTone(Tone.FRIENDLY);
PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> inputs = new HashMap<>();
ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
inputs.put(key1, patch);
inputs.put(key2, patch);
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> result = complexKeyClient.batchPartialUpdate(inputs).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
// Update return valid result
Assert.assertEquals(result.get(key1).getStatus().intValue(), 204);
Assert.assertEquals(result.get(key2).getStatus().intValue(), 204);
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResult = complexKeyClient.batchGet(new HashSet<>(Arrays.asList(key1, key2))).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(getResult.get(key1).getEntity().getTone(), Tone.FRIENDLY);
Assert.assertEquals(getResult.get(key2).getEntity().getTone(), Tone.FRIENDLY);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testAssociateResourceBatchPartialUpdate.
@Test
public void testAssociateResourceBatchPartialUpdate() throws Exception {
Associations associations = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Map<CompoundKey, PatchRequest<Message>> patches = new HashMap<>();
patches.put(getAssociateResourceUrlKey(associations), new PatchRequest<>());
patches.put(getAssociateResourceSimpleKey(associations), new PatchRequest<>());
Map<CompoundKey, UpdateStatus> ids = associations.batchPartialUpdate(patches).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
for (CompoundKey id : ids.keySet()) {
Assert.assertEquals(ids.get(id).getStatus().intValue(), 204);
}
}
use of com.linkedin.restli.common.PatchRequest 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);
}
use of com.linkedin.restli.common.PatchRequest 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<>();
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();
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<>(results, errors);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class GroupMembershipsResource2 method batchUpdate.
@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchPatchRequest<CompoundKey, GroupMembership> patches) {
Map<CompoundKey, UpdateResponse> results = new HashMap<>();
for (Map.Entry<CompoundKey, PatchRequest<GroupMembership>> entry : patches.getData().entrySet()) {
CompoundKey key = entry.getKey();
PatchRequest<GroupMembership> patch = entry.getValue();
GroupMembership groupMembership = _app.getMembershipMgr().get(key);
if (groupMembership == null) {
results.put(key, new UpdateResponse(HttpStatus.S_404_NOT_FOUND));
} else {
try {
PatchApplier.applyPatch(groupMembership, patch);
_app.getMembershipMgr().save(groupMembership);
results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} catch (DataProcessingException e) {
results.put(key, new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
}
}
}
return new BatchUpdateResult<>(results);
}
Aggregations