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");
}
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);
}
Aggregations