Search in sources :

Example 6 with PostAllDocsOptions

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

the class PostAllDocsOptionsTest method testPostAllDocsOptions.

@Test
public void testPostAllDocsOptions() throws Throwable {
    PostAllDocsOptions postAllDocsOptionsModel = new PostAllDocsOptions.Builder().db("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("0")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("testString").build();
    assertEquals(postAllDocsOptionsModel.db(), "testString");
    assertEquals(postAllDocsOptionsModel.attEncodingInfo(), Boolean.valueOf(false));
    assertEquals(postAllDocsOptionsModel.attachments(), Boolean.valueOf(false));
    assertEquals(postAllDocsOptionsModel.conflicts(), Boolean.valueOf(false));
    assertEquals(postAllDocsOptionsModel.descending(), Boolean.valueOf(false));
    assertEquals(postAllDocsOptionsModel.includeDocs(), Boolean.valueOf(false));
    assertEquals(postAllDocsOptionsModel.inclusiveEnd(), Boolean.valueOf(true));
    assertEquals(postAllDocsOptionsModel.limit(), Long.valueOf("0"));
    assertEquals(postAllDocsOptionsModel.skip(), Long.valueOf("0"));
    assertEquals(postAllDocsOptionsModel.updateSeq(), Boolean.valueOf(false));
    assertEquals(postAllDocsOptionsModel.endkey(), "testString");
    assertEquals(postAllDocsOptionsModel.key(), "testString");
    assertEquals(postAllDocsOptionsModel.keys(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
    assertEquals(postAllDocsOptionsModel.startkey(), "testString");
}
Also used : PostAllDocsOptions(com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions) Test(org.testng.annotations.Test)

Example 7 with PostAllDocsOptions

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

the class Cloudant method postAllDocs.

/**
 * Query a list of all documents in a database.
 *
 * Queries the primary index (all document IDs). The results that match the request body parameters are returned in a
 * JSON object, including a list of matching documents with basic contents, such as the ID and revision. When no
 * request body parameters are specified, results for all documents in the database are returned. Optionally, document
 * content or additional metadata can be included in the response.
 *
 * @param postAllDocsOptions the {@link PostAllDocsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link AllDocsResult}
 */
public ServiceCall<AllDocsResult> postAllDocs(PostAllDocsOptions postAllDocsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsOptions, "postAllDocsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postAllDocsOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocs");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (postAllDocsOptions.attEncodingInfo() != null) {
        contentJson.addProperty("att_encoding_info", postAllDocsOptions.attEncodingInfo());
    }
    if (postAllDocsOptions.attachments() != null) {
        contentJson.addProperty("attachments", postAllDocsOptions.attachments());
    }
    if (postAllDocsOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postAllDocsOptions.conflicts());
    }
    if (postAllDocsOptions.descending() != null) {
        contentJson.addProperty("descending", postAllDocsOptions.descending());
    }
    if (postAllDocsOptions.includeDocs() != null) {
        contentJson.addProperty("include_docs", postAllDocsOptions.includeDocs());
    }
    if (postAllDocsOptions.inclusiveEnd() != null) {
        contentJson.addProperty("inclusive_end", postAllDocsOptions.inclusiveEnd());
    }
    if (postAllDocsOptions.limit() != null) {
        contentJson.addProperty("limit", postAllDocsOptions.limit());
    }
    if (postAllDocsOptions.skip() != null) {
        contentJson.addProperty("skip", postAllDocsOptions.skip());
    }
    if (postAllDocsOptions.updateSeq() != null) {
        contentJson.addProperty("update_seq", postAllDocsOptions.updateSeq());
    }
    if (postAllDocsOptions.endkey() != null) {
        contentJson.addProperty("endkey", postAllDocsOptions.endkey());
    }
    if (postAllDocsOptions.key() != null) {
        contentJson.addProperty("key", postAllDocsOptions.key());
    }
    if (postAllDocsOptions.keys() != null) {
        contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postAllDocsOptions.keys()));
    }
    if (postAllDocsOptions.startkey() != null) {
        contentJson.addProperty("startkey", postAllDocsOptions.startkey());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<AllDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsResult>() {
    }.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) AllDocsResult(com.ibm.cloud.cloudant.v1.model.AllDocsResult)

Aggregations

PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)6 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)5 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)3 Test (org.testng.annotations.Test)3 GsonBuilder (com.google.gson.GsonBuilder)2 DocsResultRow (com.ibm.cloud.cloudant.v1.model.DocsResultRow)2 Document (com.ibm.cloud.cloudant.v1.model.Document)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JsonObject (com.google.gson.JsonObject)1 DeleteDocumentOptions (com.ibm.cloud.cloudant.v1.model.DeleteDocumentOptions)1 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 CloudEvent (io.cloudevents.CloudEvent)1 CloudEventImpl (io.cloudevents.v02.CloudEventImpl)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1