use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class AnnotatedComplexKeysResource method create.
@RestMethod.Create
public Promise<CreateResponse> create(final Message message) {
final SettablePromise<CreateResponse> result = Promises.settable();
final Runnable requestHandler = new Runnable() {
public void run() {
ComplexResourceKey<TwoPartKey, TwoPartKey> key = _dataProvider.create(message);
result.done(new CreateResponse(key));
}
};
_scheduler.schedule(requestHandler, DELAY, TimeUnit.MILLISECONDS);
return result;
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchUpdate.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchUpdate(BatchPatchRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> patches) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse>();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> patch : patches.getData().entrySet()) {
try {
this.partialUpdate(patch.getKey(), patch.getValue());
results.put(patch.getKey(), new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
} catch (DataProcessingException e) {
results.put(patch.getKey(), new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
}
}
return new BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(results);
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method addExample.
private void addExample(String majorKey, String minorKey, String messageText) {
TwoPartKey key = new TwoPartKey();
key.setMajor(majorKey);
key.setMinor(minorKey);
Message message = new Message();
message.setId(keyToString(key));
message.setMessage(messageText);
message.setTone(Tone.SINCERE);
_db.put(keyToString(key), message);
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchGet.
public BatchResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGet(Set<ComplexResourceKey<TwoPartKey, TwoPartKey>> keys) {
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> data = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>();
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException> errors = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException>();
for (ComplexResourceKey<TwoPartKey, TwoPartKey> key : keys) {
String stringKey = keyToString(key.getKey());
if (_db.containsKey(stringKey)) {
data.put(key, _db.get(stringKey));
} else {
errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(data, errors);
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchDelete.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchDelete(BatchDeleteRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> ids) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse>();
for (ComplexResourceKey<TwoPartKey, TwoPartKey> id : ids.getKeys()) {
_db.remove(keyToString(id.getKey()));
results.put(id, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
}
return new BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>(results);
}
Aggregations