Search in sources :

Example 1 with TwoPartKey

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;
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) CreateResponse(com.linkedin.restli.server.CreateResponse)

Example 2 with TwoPartKey

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);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) HashMap(java.util.HashMap) Map(java.util.Map) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 3 with TwoPartKey

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);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message)

Example 4 with TwoPartKey

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);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) HashMap(java.util.HashMap) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) BatchResult(com.linkedin.restli.server.BatchResult)

Example 5 with TwoPartKey

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);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Aggregations

TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)21 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)15 Message (com.linkedin.restli.examples.greetings.api.Message)13 HashMap (java.util.HashMap)7 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 DataMap (com.linkedin.data.DataMap)4 EntityResponse (com.linkedin.restli.common.EntityResponse)4 UpdateStatus (com.linkedin.restli.common.UpdateStatus)3 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)3 UpdateResponse (com.linkedin.restli.server.UpdateResponse)3 Test (org.testng.annotations.Test)3 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 EmptyRecord (com.linkedin.restli.common.EmptyRecord)2 PatchRequest (com.linkedin.restli.common.PatchRequest)2 CreateResponse (com.linkedin.restli.server.CreateResponse)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 HashSet (java.util.HashSet)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1