Search in sources :

Example 1 with PostPartitionAllDocsOptions

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

the class Cloudant method postPartitionAllDocs.

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

Example 2 with PostPartitionAllDocsOptions

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

the class PostPartitionAllDocsOptionsTest method testPostPartitionAllDocsOptions.

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

Example 3 with PostPartitionAllDocsOptions

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

the class CloudantTest method testPostPartitionAllDocsWOptions.

@Test
public void testPostPartitionAllDocsWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"total_rows\": 0, \"rows\": [{\"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\", \"doc\": {\"_attachments\": {\"mapKey\": {\"content_type\": \"contentType\", \"data\": \"VGhpcyBpcyBhbiBlbmNvZGVkIGJ5dGUgYXJyYXku\", \"digest\": \"digest\", \"encoded_length\": 0, \"encoding\": \"encoding\", \"follows\": false, \"length\": 0, \"revpos\": 1, \"stub\": true}}, \"_conflicts\": [\"conflicts\"], \"_deleted\": false, \"_deleted_conflicts\": [\"deletedConflicts\"], \"_id\": \"id\", \"_local_seq\": \"localSeq\", \"_rev\": \"rev\", \"_revisions\": {\"ids\": [\"ids\"], \"start\": 1}, \"_revs_info\": [{\"rev\": \"rev\", \"status\": \"available\"}]}, \"id\": \"id\", \"key\": \"key\", \"value\": {\"rev\": \"rev\"}}], \"update_seq\": \"updateSeq\"}";
    String postPartitionAllDocsPath = "/testString/_partition/testString/_all_docs";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostPartitionAllDocsOptions model
    PostPartitionAllDocsOptions postPartitionAllDocsOptionsModel = new PostPartitionAllDocsOptions.Builder().db("testString").partitionKey("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("10")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("0007741142412418284").build();
    // Invoke operation with valid options model (positive test)
    Response<AllDocsResult> response = cloudantService.postPartitionAllDocs(postPartitionAllDocsOptionsModel).execute();
    assertNotNull(response);
    AllDocsResult responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postPartitionAllDocsPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) AllDocsResult(com.ibm.cloud.cloudant.v1.model.AllDocsResult) PostPartitionAllDocsOptions(com.ibm.cloud.cloudant.v1.model.PostPartitionAllDocsOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with PostPartitionAllDocsOptions

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

the class CloudantTest method testPostPartitionAllDocsAsStreamWOptions.

@Test
public void testPostPartitionAllDocsAsStreamWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"foo\": \"this is a mock response for JSON streaming\"}";
    String postPartitionAllDocsAsStreamPath = "/testString/_partition/testString/_all_docs";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the PostPartitionAllDocsOptions model
    PostPartitionAllDocsOptions postPartitionAllDocsOptionsModel = new PostPartitionAllDocsOptions.Builder().db("testString").partitionKey("testString").attEncodingInfo(false).attachments(false).conflicts(false).descending(false).includeDocs(false).inclusiveEnd(true).limit(Long.valueOf("10")).skip(Long.valueOf("0")).updateSeq(false).endkey("testString").key("testString").keys(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).startkey("0007741142412418284").build();
    // Invoke operation with valid options model (positive test)
    Response<InputStream> response = cloudantService.postPartitionAllDocsAsStream(postPartitionAllDocsOptionsModel).execute();
    assertNotNull(response);
    InputStream responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, postPartitionAllDocsAsStreamPath);
    // Verify streamed JSON response
    java.util.Scanner s = new java.util.Scanner(responseObj).useDelimiter("\\A");
    String streamedResponseBody = s.hasNext() ? s.next() : "";
    assertEquals(streamedResponseBody, mockResponseBody);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) InputStream(java.io.InputStream) PostPartitionAllDocsOptions(com.ibm.cloud.cloudant.v1.model.PostPartitionAllDocsOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PostPartitionAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostPartitionAllDocsOptions)3 Test (org.testng.annotations.Test)3 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)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 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1