Search in sources :

Example 6 with UpdateResponse

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

the class GroupMembershipsResource3 method update.

/**
 * @see AssociationResource#update
 */
@Override
public UpdateResponse update(ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> id, PatchRequest<ComplexKeyGroupMembership> patch) {
    ComplexKeyGroupMembership membership = fromGroupMembership(_app.getMembershipMgr().get(complexKeyToCompoundKey(id)));
    try {
        PatchApplier.applyPatch(membership, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(S_400_BAD_REQUEST);
    }
    // validate(membership);
    // we set groupID, memberID based on the URI
    membership.setId(id.getKey());
    _app.getMembershipMgr().save(toGroupMembership(membership));
    return new UpdateResponse(S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) ComplexKeyGroupMembership(com.linkedin.restli.examples.groups.api.ComplexKeyGroupMembership) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

Example 7 with UpdateResponse

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

the class MixedResource method update.

@Update
public Promise<UpdateResponse> update(Long key, Greeting entity) {
    final SettablePromise<UpdateResponse> result = Promises.settable();
    Runnable requestHandler = new Runnable() {

        public void run() {
            result.done(new UpdateResponse(HttpStatus.S_200_OK));
        }
    };
    scheduler.schedule(requestHandler, DELAY, TimeUnit.MILLISECONDS);
    return result;
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) Update(com.linkedin.restli.server.annotations.RestMethod.Update)

Example 8 with UpdateResponse

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

the class StreamingGreetings method respondWithResponseAttachment.

private void respondWithResponseAttachment(final Callback<UpdateResponse> callback) {
    if (getContext().responseAttachmentsSupported()) {
        // Echo the bytes back from the header
        final String headerValue = getContext().getRequestHeaders().get("getHeader");
        final GreetingWriter greetingWriter = new GreetingWriter(ByteString.copy(headerValue.getBytes()));
        final RestLiResponseAttachments streamingAttachments = new RestLiResponseAttachments.Builder().appendSingleAttachment(greetingWriter).build();
        getContext().setResponseAttachments(streamingAttachments);
        callback.onSuccess(new UpdateResponse(HttpStatus.S_200_OK));
    }
    callback.onError(new RestLiServiceException(HttpStatus.S_400_BAD_REQUEST, "You must be able to receive attachments!"));
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ByteString(com.linkedin.data.ByteString) RestLiResponseAttachments(com.linkedin.restli.server.RestLiResponseAttachments)

Example 9 with UpdateResponse

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

the class GroupMembershipsResource2 method batchUpdate.

/**
 * @see com.linkedin.restli.server.resources.AssociationResourceTemplate#batchUpdate(com.linkedin.restli.server.BatchUpdateRequest)
 */
@Override
public BatchUpdateResult<CompoundKey, GroupMembership> batchUpdate(BatchUpdateRequest<CompoundKey, GroupMembership> entities) {
    Map<CompoundKey, UpdateResponse> results = new HashMap<>();
    for (Map.Entry<CompoundKey, GroupMembership> entry : entities.getData().entrySet()) {
        CompoundKey id = entry.getKey();
        GroupMembership membership = entry.getValue();
        membership.setId(URIParamUtils.encodeKeyForBody(id, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
        membership.setGroupID(((Integer) id.getPart(GROUP_ID)));
        membership.setMemberID(((Integer) id.getPart(MEMBER_ID)));
        _app.getMembershipMgr().save(membership);
        results.put(id, new UpdateResponse(S_204_NO_CONTENT));
    }
    return new BatchUpdateResult<>(results);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) BatchUpdateResult(com.linkedin.restli.server.BatchUpdateResult) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with UpdateResponse

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

the class GroupMembershipsResource2 method update.

/**
 * @see AssociationResource#update
 */
@Override
public UpdateResponse update(CompoundKey id, PatchRequest<GroupMembership> patch) {
    GroupMembership membership = _app.getMembershipMgr().get(id);
    try {
        PatchApplier.applyPatch(membership, patch);
    } catch (DataProcessingException e) {
        return new UpdateResponse(S_400_BAD_REQUEST);
    }
    validate(membership);
    // we set groupID, memberID based on the URI
    membership.setId(URIParamUtils.encodeKeyForBody(id, true, AllProtocolVersions.BASELINE_PROTOCOL_VERSION));
    membership.setGroupID(getContext().getPathKeys().getAsInt(GROUP_ID));
    membership.setMemberID(getContext().getPathKeys().getAsInt(MEMBER_ID));
    _app.getMembershipMgr().save(membership);
    return new UpdateResponse(S_204_NO_CONTENT);
}
Also used : UpdateResponse(com.linkedin.restli.server.UpdateResponse) GroupMembership(com.linkedin.restli.examples.groups.api.GroupMembership) DataProcessingException(com.linkedin.data.transform.DataProcessingException)

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