Search in sources :

Example 11 with UpdateResponse

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

the class NullGreetingsResourceImpl method batchUpdate.

@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Long, Greeting> batchUpdate(BatchPatchRequest<Long, Greeting> entityUpdates) {
    final Map<Long, UpdateResponse> responseMap = new HashMap<>();
    responseMap.put(3l, new UpdateResponse(HttpStatus.S_201_CREATED));
    if (entityUpdates.getData().containsKey(1l)) {
        // Return a null BatchUpdateResult
        return null;
    } else if (entityUpdates.getData().containsKey(2l)) {
        // Return a BatchUpdateResult with a null results Map
        return new BatchUpdateResult<>(null);
    } else if (entityUpdates.getData().containsKey(3l)) {
        // Return a BatchUpdateResult with a null errors Map
        return new BatchUpdateResult<>(responseMap, null);
    } else {
        // Return a BatchUpdateResult with a map that has a null key in it
        responseMap.put(null, new UpdateResponse(HttpStatus.S_201_CREATED));
        return new BatchUpdateResult<>(responseMap);
    }
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 12 with UpdateResponse

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

the class SimpleResourceUnderCollectionResource method update.

/**
 * Updates the greeting.
 */
@Override
public UpdateResponse update(PatchRequest<Greeting> patchRequest) {
    Long key = this.getContext().getPathKeys().get("subgreetingsId");
    if (TONES.containsKey(key)) {
        try {
            Greeting patched = new Greeting();
            PatchApplier.applyPatch(patched, patchRequest);
            TONES.put(key, patched.getTone());
            return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
        } catch (DataProcessingException e) {
            return new UpdateResponse((HttpStatus.S_400_BAD_REQUEST));
        }
    } else {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateResponse(com.linkedin.restli.server.UpdateResponse) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 13 with UpdateResponse

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

the class GreetingsResourceImpl method update.

@RestMethod.PartialUpdate
public UpdateResponse update(Long key, PatchRequest<Greeting> patch) {
    Greeting g = _db.get(key);
    if (g == null) {
        return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
    }
    try {
        PatchApplier.applyPatch(g, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
    }
    _db.put(key, g);
    return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) UpdateResponse(com.linkedin.restli.server.UpdateResponse) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 14 with UpdateResponse

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

the class TestUpdateResponseBuilder method testBuilderException.

@Test
public void testBuilderException() {
    UpdateResponse updateResponse = new UpdateResponse(null);
    Map<String, String> headers = ResponseBuilderUtil.getHeaders();
    UpdateResponseBuilder updateResponseBuilder = new UpdateResponseBuilder();
    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
    try {
        updateResponseBuilder.buildRestLiResponseData(null, routingResult, updateResponse, headers, Collections.emptyList());
        Assert.fail("buildRestLiResponseData should have failed because of a null HTTP status!");
    } catch (RestLiServiceException e) {
        Assert.assertTrue(e.getMessage().contains("Unexpected null encountered. HttpStatus is null inside of a UpdateResponse returned by the resource method: "));
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Test(org.testng.annotations.Test)

Example 15 with UpdateResponse

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

the class AutomaticValidationDemoResource method batchUpdate.

@RestMethod.BatchPartialUpdate
public BatchUpdateResult<Integer, ValidationDemo> batchUpdate(final BatchPatchRequest<Integer, ValidationDemo> entityUpdates) {
    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();
        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) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) HashMap(java.util.HashMap) Map(java.util.Map) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo)

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