Search in sources :

Example 41 with UpdateResponse

use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.

the class AnnotatedComplexKeysResource method update.

@RestMethod.PartialUpdate
public Promise<UpdateResponse> update(final ComplexResourceKey<TwoPartKey, TwoPartKey> key, final PatchRequest<Message> patch) {
    final SettablePromise<UpdateResponse> result = Promises.settable();
    final Runnable requestHandler = new Runnable() {

        public void run() {
            try {
                _dataProvider.partialUpdate(key, patch);
                result.done(new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
            } catch (DataProcessingException e) {
                result.done(new UpdateResponse(HttpStatus.S_400_BAD_REQUEST));
            }
        }
    };
    _scheduler.schedule(requestHandler, DELAY, TimeUnit.MILLISECONDS);
    return result;
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 42 with UpdateResponse

use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.

the class AutomaticValidationDemoResource method batchUpdate.

@RestMethod.BatchUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchUpdateRequest<Integer, ValidationDemo> entities) {
    Map<Integer, UpdateResponse> results = new HashMap<>();
    Map<Integer, RestLiServiceException> errors = new HashMap<>();
    for (Map.Entry<Integer, ValidationDemo> entry : entities.getData().entrySet()) {
        Integer key = entry.getKey();
        ValidationDemo entity = entry.getValue();
        results.put(key, new UpdateResponse(HttpStatus.S_204_NO_CONTENT));
    }
    return new BatchUpdateResult<>(results, errors);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

Example 43 with UpdateResponse

use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.

the class ChainedTyperefResource method batchUpdate.

@Override
public BatchUpdateResult<CompoundKey, Greeting> batchUpdate(BatchUpdateRequest<CompoundKey, Greeting> entities) {
    Set<CompoundKey> keys = entities.getData().keySet();
    Map<CompoundKey, UpdateResponse> responseMap = new HashMap<>();
    Map<CompoundKey, RestLiServiceException> errorMap = new HashMap<>();
    for (CompoundKey key : keys) {
        responseMap.put(key, new UpdateResponse(HttpStatus.S_201_CREATED));
    }
    return new BatchUpdateResult<>(responseMap);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap)

Example 44 with UpdateResponse

use of com.linkedin.restli.server.UpdateResponse 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<>();
    final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException> errors = new HashMap<>();
    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<>(results, errors);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) Message(com.linkedin.restli.examples.greetings.api.Message) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) HashMap(java.util.HashMap) Map(java.util.Map)

Example 45 with UpdateResponse

use of com.linkedin.restli.server.UpdateResponse in project rest.li by linkedin.

the class AlbumResource method update.

// update an existing photo with given entity
@Override
public UpdateResponse update(Long key, Album entity) {
    final Album currPhoto = _db.getData().get(key);
    if (currPhoto == null) {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
    // disallow changing entity ID and URN
    if (entity.hasId() || entity.hasUrn()) {
        throw new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "Album ID is not acceptable in request");
    }
    // make sure the ID in the entity is consistent with the key in the database
    entity.setId(key);
    entity.setUrn(String.valueOf(key));
    _db.getData().put(key, entity);
    return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) Album(com.linkedin.restli.example.Album)

Aggregations

UpdateResponse (com.linkedin.restli.server.UpdateResponse)55 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)21 HashMap (java.util.HashMap)21 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)18 DataProcessingException (com.linkedin.data.transform.DataProcessingException)12 Map (java.util.Map)11 Test (org.testng.annotations.Test)11 CompoundKey (com.linkedin.restli.common.CompoundKey)9 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)6 HttpStatus (com.linkedin.restli.common.HttpStatus)5 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)5 ByteString (com.linkedin.data.ByteString)4 PatchRequest (com.linkedin.restli.common.PatchRequest)4 UpdateStatus (com.linkedin.restli.common.UpdateStatus)4 Photo (com.linkedin.restli.example.Photo)4 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)4 BatchPatchRequest (com.linkedin.restli.server.BatchPatchRequest)4 Callback (com.linkedin.common.callback.Callback)3 DataMap (com.linkedin.data.DataMap)3 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)3