use of com.ibm.cloud.cloudant.v1.model.Document 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);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method postChanges.
/**
* Query the database document changes feed.
*
* Requests the database changes feed in the same way as `GET /{db}/_changes` does. It is widely used with the
* `filter` query parameter because it allows one to pass more information to the filter.
*
* @param postChangesOptions the {@link PostChangesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ChangesResult}
*/
public ServiceCall<ChangesResult> postChanges(PostChangesOptions postChangesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postChangesOptions, "postChangesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postChangesOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_changes", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postChanges");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (postChangesOptions.lastEventId() != null) {
builder.header("Last-Event-ID", postChangesOptions.lastEventId());
}
if (postChangesOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(postChangesOptions.attEncodingInfo()));
}
if (postChangesOptions.attachments() != null) {
builder.query("attachments", String.valueOf(postChangesOptions.attachments()));
}
if (postChangesOptions.conflicts() != null) {
builder.query("conflicts", String.valueOf(postChangesOptions.conflicts()));
}
if (postChangesOptions.descending() != null) {
builder.query("descending", String.valueOf(postChangesOptions.descending()));
}
if (postChangesOptions.feed() != null) {
builder.query("feed", String.valueOf(postChangesOptions.feed()));
}
if (postChangesOptions.filter() != null) {
builder.query("filter", String.valueOf(postChangesOptions.filter()));
}
if (postChangesOptions.heartbeat() != null) {
builder.query("heartbeat", String.valueOf(postChangesOptions.heartbeat()));
}
if (postChangesOptions.includeDocs() != null) {
builder.query("include_docs", String.valueOf(postChangesOptions.includeDocs()));
}
if (postChangesOptions.limit() != null) {
builder.query("limit", String.valueOf(postChangesOptions.limit()));
}
if (postChangesOptions.seqInterval() != null) {
builder.query("seq_interval", String.valueOf(postChangesOptions.seqInterval()));
}
if (postChangesOptions.since() != null) {
builder.query("since", String.valueOf(postChangesOptions.since()));
}
if (postChangesOptions.style() != null) {
builder.query("style", String.valueOf(postChangesOptions.style()));
}
if (postChangesOptions.timeout() != null) {
builder.query("timeout", String.valueOf(postChangesOptions.timeout()));
}
if (postChangesOptions.view() != null) {
builder.query("view", String.valueOf(postChangesOptions.view()));
}
final JsonObject contentJson = new JsonObject();
if (postChangesOptions.docIds() != null) {
contentJson.add("doc_ids", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.docIds()));
}
if (postChangesOptions.fields() != null) {
contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.fields()));
}
if (postChangesOptions.selector() != null) {
contentJson.add("selector", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.selector()));
}
builder.bodyJson(contentJson);
ResponseConverter<ChangesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ChangesResult>() {
}.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 getDesignDocument.
/**
* Retrieve a design document.
*
* Returns design document with the specified `doc_id` from the specified database. Unless you request a specific
* revision, the current revision of the design document is always returned.
*
* @param getDesignDocumentOptions the {@link GetDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DesignDocument}
*/
public ServiceCall<DesignDocument> getDesignDocument(GetDesignDocumentOptions getDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getDesignDocumentOptions, "getDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getDesignDocumentOptions.db());
pathParamsMap.put("ddoc", getDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getDesignDocumentOptions.ifNoneMatch() != null) {
builder.header("If-None-Match", getDesignDocumentOptions.ifNoneMatch());
}
if (getDesignDocumentOptions.attachments() != null) {
builder.query("attachments", String.valueOf(getDesignDocumentOptions.attachments()));
}
if (getDesignDocumentOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(getDesignDocumentOptions.attEncodingInfo()));
}
if (getDesignDocumentOptions.conflicts() != null) {
builder.query("conflicts", String.valueOf(getDesignDocumentOptions.conflicts()));
}
if (getDesignDocumentOptions.deletedConflicts() != null) {
builder.query("deleted_conflicts", String.valueOf(getDesignDocumentOptions.deletedConflicts()));
}
if (getDesignDocumentOptions.latest() != null) {
builder.query("latest", String.valueOf(getDesignDocumentOptions.latest()));
}
if (getDesignDocumentOptions.localSeq() != null) {
builder.query("local_seq", String.valueOf(getDesignDocumentOptions.localSeq()));
}
if (getDesignDocumentOptions.meta() != null) {
builder.query("meta", String.valueOf(getDesignDocumentOptions.meta()));
}
if (getDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(getDesignDocumentOptions.rev()));
}
if (getDesignDocumentOptions.revs() != null) {
builder.query("revs", String.valueOf(getDesignDocumentOptions.revs()));
}
if (getDesignDocumentOptions.revsInfo() != null) {
builder.query("revs_info", String.valueOf(getDesignDocumentOptions.revsInfo()));
}
ResponseConverter<DesignDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DesignDocument>() {
}.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 postAllDocsQueries.
/**
* Multi-query the list of all documents in a database.
*
* Runs multiple queries using the primary index (all document IDs). Returns a JSON object that contains a list of
* result objects, one for each query, with a structure equivalent to that of a single `_all_docs` request. This
* enables you to request multiple queries in a single request, in place of multiple `POST /{db}/_all_docs` requests.
*
* @param postAllDocsQueriesOptions the {@link PostAllDocsQueriesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link AllDocsQueriesResult}
*/
public ServiceCall<AllDocsQueriesResult> postAllDocsQueries(PostAllDocsQueriesOptions postAllDocsQueriesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsQueriesOptions, "postAllDocsQueriesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postAllDocsQueriesOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs/queries", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocsQueries");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postAllDocsQueriesOptions.queries()));
builder.bodyJson(contentJson);
ResponseConverter<AllDocsQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsQueriesResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class CloudantTest method testPutDocumentWOptions.
@Test
public void testPutDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
String putDocumentPath = "/testString/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the Attachment model
Attachment attachmentModel = new Attachment.Builder().contentType("testString").data(TestUtilities.createMockByteArray("This is a mock byte array value.")).digest("testString").encodedLength(Long.valueOf("0")).encoding("testString").follows(true).length(Long.valueOf("0")).revpos(Long.valueOf("1")).stub(true).build();
// Construct an instance of the Revisions model
Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
// Construct an instance of the DocumentRevisionStatus model
DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
// Construct an instance of the Document model
Document documentModel = new Document.Builder().attachments(new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
}).conflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).deleted(true).deletedConflicts(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).id("exampleid").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("brand", "Foo").add("colours", "[\"red\",\"green\",\"black\",\"blue\"]").add("description", "Slim Colourful Design Electronic Cooking Appliance for ...").add("image", "assets/img/0gmsnghhew.jpg").add("keywords", "[\"Foo\",\"Scales\",\"Weight\",\"Digital\",\"Kitchen\"]").add("name", "Digital Kitchen Scales").add("price", "14.99").add("productid", "1000042").add("taxonomy", "[\"Home\",\"Kitchen\",\"Small Appliances\"]").add("type", "product").build();
// Construct an instance of the PutDocumentOptions model
PutDocumentOptions putDocumentOptionsModel = new PutDocumentOptions.Builder().db("testString").docId("testString").document(documentModel).contentType("application/json").ifMatch("testString").batch("ok").newEdits(false).rev("testString").build();
// Invoke operation with valid options model (positive test)
Response<DocumentResult> response = cloudantService.putDocument(putDocumentOptionsModel).execute();
assertNotNull(response);
DocumentResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "PUT");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("batch"), "ok");
assertEquals(Boolean.valueOf(query.get("new_edits")), Boolean.valueOf(false));
assertEquals(query.get("rev"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, putDocumentPath);
}
Aggregations