Search in sources :

Example 6 with PostBulkGetOptions

use of com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions in project cloudant-java-sdk by IBM.

the class Cloudant method postBulkGet.

/**
 * Bulk query revision information for multiple documents.
 *
 * Fetch specific revisions or revision histories for multiple documents in bulk as replicators do.
 *
 * @param postBulkGetOptions the {@link PostBulkGetOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BulkGetResult}
 */
public ServiceCall<BulkGetResult> postBulkGet(PostBulkGetOptions postBulkGetOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postBulkGetOptions, "postBulkGetOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postBulkGetOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_bulk_get", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postBulkGet");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (postBulkGetOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(postBulkGetOptions.attachments()));
    }
    if (postBulkGetOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(postBulkGetOptions.attEncodingInfo()));
    }
    if (postBulkGetOptions.latest() != null) {
        builder.query("latest", String.valueOf(postBulkGetOptions.latest()));
    }
    if (postBulkGetOptions.revs() != null) {
        builder.query("revs", String.valueOf(postBulkGetOptions.revs()));
    }
    final JsonObject contentJson = new JsonObject();
    contentJson.add("docs", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postBulkGetOptions.docs()));
    builder.bodyJson(contentJson);
    ResponseConverter<BulkGetResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BulkGetResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) BulkGetResult(com.ibm.cloud.cloudant.v1.model.BulkGetResult)

Aggregations

BulkGetQueryDocument (com.ibm.cloud.cloudant.v1.model.BulkGetQueryDocument)5 PostBulkGetOptions (com.ibm.cloud.cloudant.v1.model.PostBulkGetOptions)5 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)5 MockResponse (okhttp3.mockwebserver.MockResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 InputStream (java.io.InputStream)3 BulkGetResult (com.ibm.cloud.cloudant.v1.model.BulkGetResult)2 JsonObject (com.google.gson.JsonObject)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 HashMap (java.util.HashMap)1