Search in sources :

Example 1 with ActionResponseDecoder

use of com.linkedin.restli.internal.client.ActionResponseDecoder in project rest.li by linkedin.

the class ActionRequestBuilder method build.

@SuppressWarnings("unchecked")
@Override
public ActionRequest<V> build() {
    if (_name == null) {
        throw new IllegalStateException("name required to build action request");
    }
    RecordDataSchema requestDataSchema;
    RecordDataSchema actionResponseDataSchema;
    FieldDef<V> responseFieldDef;
    if (// old builder code in use
    _resourceSpec.getRequestMetadata(_name) == null) {
        requestDataSchema = DynamicRecordMetadata.buildSchema(_name, _actionParams.keySet());
        if (_elementType == null) {
            _elementType = new TypeSpec<>(_elementClass);
        }
        Collection<FieldDef<?>> responseFieldDefCollection;
        if (_elementType.getType() == Void.class) {
            responseFieldDef = null;
            responseFieldDefCollection = Collections.emptyList();
        } else {
            responseFieldDef = new FieldDef<>(ActionResponse.VALUE_NAME, _elementType.getType(), _elementType.getSchema());
            responseFieldDefCollection = Collections.<FieldDef<?>>singleton(responseFieldDef);
        }
        actionResponseDataSchema = DynamicRecordMetadata.buildSchema(_name, responseFieldDefCollection);
    } else {
        requestDataSchema = _resourceSpec.getRequestMetadata(_name).getRecordDataSchema();
        actionResponseDataSchema = _resourceSpec.getActionResponseMetadata(_name).getRecordDataSchema();
        responseFieldDef = (FieldDef<V>) _resourceSpec.getActionResponseMetadata(_name).getFieldDef(ActionResponse.VALUE_NAME);
    }
    @SuppressWarnings("unchecked") ActionResponseDecoder<V> actionResponseDecoder = new ActionResponseDecoder<>(responseFieldDef, actionResponseDataSchema);
    DynamicRecordTemplate inputParameters = new DynamicRecordTemplate(requestDataSchema, buildReadOnlyActionParameters());
    inputParameters.data().setReadOnly();
    return new ActionRequest<>(inputParameters, buildReadOnlyHeaders(), buildReadOnlyCookies(), actionResponseDecoder, _resourceSpec, buildReadOnlyQueryParameters(), getQueryParamClasses(), _name, getBaseUriTemplate(), buildReadOnlyPathKeys(), getRequestOptions(), buildReadOnlyId(), _streamingAttachments == null ? null : Collections.unmodifiableList(_streamingAttachments));
}
Also used : FieldDef(com.linkedin.data.template.FieldDef) ActionResponseDecoder(com.linkedin.restli.internal.client.ActionResponseDecoder) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema)

Aggregations

RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)1 FieldDef (com.linkedin.data.template.FieldDef)1 ActionResponseDecoder (com.linkedin.restli.internal.client.ActionResponseDecoder)1