use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class CloudantTest method testGetDocumentWOptions.
@Test
public void testGetDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"_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\"}]}";
String getDocumentPath = "/testString/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the GetDocumentOptions model
GetDocumentOptions getDocumentOptionsModel = new GetDocumentOptions.Builder().db("testString").docId("testString").ifNoneMatch("testString").attachments(false).attEncodingInfo(false).conflicts(false).deletedConflicts(false).latest(false).localSeq(false).meta(false).rev("testString").revs(false).revsInfo(false).build();
// Invoke operation with valid options model (positive test)
Response<Document> response = cloudantService.getDocument(getDocumentOptionsModel).execute();
assertNotNull(response);
Document responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(Boolean.valueOf(query.get("attachments")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("att_encoding_info")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("deleted_conflicts")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("latest")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("local_seq")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("meta")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
assertEquals(Boolean.valueOf(query.get("revs")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("revs_info")), Boolean.valueOf(false));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDocumentPath);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method postDesignDocs.
/**
* Query a list of all design documents in a database.
*
* Queries the index of all design document IDs. The results matching the request body parameters are returned in a
* JSON object, including a list of matching design documents with basic contents, such as the ID and revision. When
* no request body parameters are specified, results for all design documents in the database are returned.
* Optionally, the design document content or additional metadata can be included in the response.
*
* @param postDesignDocsOptions the {@link PostDesignDocsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsResult}
*/
public ServiceCall<AllDocsResult> postDesignDocs(PostDesignDocsOptions postDesignDocsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postDesignDocsOptions, "postDesignDocsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postDesignDocsOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design_docs", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDesignDocs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
if (postDesignDocsOptions.accept() != null) {
builder.header("Accept", postDesignDocsOptions.accept());
}
final JsonObject contentJson = new JsonObject();
if (postDesignDocsOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postDesignDocsOptions.attEncodingInfo());
}
if (postDesignDocsOptions.attachments() != null) {
contentJson.addProperty("attachments", postDesignDocsOptions.attachments());
}
if (postDesignDocsOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postDesignDocsOptions.conflicts());
}
if (postDesignDocsOptions.descending() != null) {
contentJson.addProperty("descending", postDesignDocsOptions.descending());
}
if (postDesignDocsOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postDesignDocsOptions.includeDocs());
}
if (postDesignDocsOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postDesignDocsOptions.inclusiveEnd());
}
if (postDesignDocsOptions.limit() != null) {
contentJson.addProperty("limit", postDesignDocsOptions.limit());
}
if (postDesignDocsOptions.skip() != null) {
contentJson.addProperty("skip", postDesignDocsOptions.skip());
}
if (postDesignDocsOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postDesignDocsOptions.updateSeq());
}
if (postDesignDocsOptions.endkey() != null) {
contentJson.addProperty("endkey", postDesignDocsOptions.endkey());
}
if (postDesignDocsOptions.key() != null) {
contentJson.addProperty("key", postDesignDocsOptions.key());
}
if (postDesignDocsOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postDesignDocsOptions.keys()));
}
if (postDesignDocsOptions.startkey() != null) {
contentJson.addProperty("startkey", postDesignDocsOptions.startkey());
}
builder.bodyJson(contentJson);
ResponseConverter<AllDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method postBulkDocs.
/**
* Bulk modify multiple documents in a database.
*
* The bulk document API allows you to create and update multiple documents at the same time within a single request.
* The basic operation is similar to creating or updating a single document, except that you batch the document
* structure and information.
*
* @param postBulkDocsOptions the {@link PostBulkDocsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link List}
*/
public ServiceCall<List<DocumentResult>> postBulkDocs(PostBulkDocsOptions postBulkDocsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postBulkDocsOptions, "postBulkDocsOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postBulkDocsOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_bulk_docs", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postBulkDocs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.bodyContent("application/json", postBulkDocsOptions.bulkDocs(), null, postBulkDocsOptions.body());
ResponseConverter<List<DocumentResult>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<List<DocumentResult>>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method getLocalDocument.
/**
* Retrieve a local document.
*
* Retrieves the specified local document. The semantics are identical to accessing a standard document in the
* specified database, except that the document is not replicated.
*
* @param getLocalDocumentOptions the {@link GetLocalDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Document}
*/
public ServiceCall<Document> getLocalDocument(GetLocalDocumentOptions getLocalDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getLocalDocumentOptions, "getLocalDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getLocalDocumentOptions.db());
pathParamsMap.put("doc_id", getLocalDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getLocalDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
if (getLocalDocumentOptions.accept() != null) {
builder.header("Accept", getLocalDocumentOptions.accept());
}
if (getLocalDocumentOptions.ifNoneMatch() != null) {
builder.header("If-None-Match", getLocalDocumentOptions.ifNoneMatch());
}
if (getLocalDocumentOptions.attachments() != null) {
builder.query("attachments", String.valueOf(getLocalDocumentOptions.attachments()));
}
if (getLocalDocumentOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(getLocalDocumentOptions.attEncodingInfo()));
}
if (getLocalDocumentOptions.localSeq() != null) {
builder.query("local_seq", String.valueOf(getLocalDocumentOptions.localSeq()));
}
ResponseConverter<Document> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Document>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Document 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