use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDatabase.
/**
* Delete a database.
*
* Deletes the specified database and all documents and attachments contained within it. To avoid deleting a database,
* the server responds with a 400 HTTP status code when the request URL includes a `?rev=` parameter. This response
* suggests that a user wanted to delete a document but forgot to add the document ID to the URL.
*
* @param deleteDatabaseOptions the {@link DeleteDatabaseOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> deleteDatabase(DeleteDatabaseOptions deleteDatabaseOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDatabaseOptions, "deleteDatabaseOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDatabaseOptions.db());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDatabase");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.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 getDesignDocumentInformation.
/**
* Retrieve information about a design document.
*
* Retrieves information about the specified design document, including the index, index size, and current status of
* the design document and associated index information.
*
* @param getDesignDocumentInformationOptions the {@link GetDesignDocumentInformationOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DesignDocumentInformation}
*/
public ServiceCall<DesignDocumentInformation> getDesignDocumentInformation(GetDesignDocumentInformationOptions getDesignDocumentInformationOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getDesignDocumentInformationOptions, "getDesignDocumentInformationOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getDesignDocumentInformationOptions.db());
pathParamsMap.put("ddoc", getDesignDocumentInformationOptions.ddoc());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_info", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDesignDocumentInformation");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<DesignDocumentInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DesignDocumentInformation>() {
}.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 deleteLocalDocument.
/**
* Delete a local document.
*
* Deletes the specified local document. The semantics are identical to deleting a standard document in the specified
* database, except that the document is not replicated.
*
* @param deleteLocalDocumentOptions the {@link DeleteLocalDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteLocalDocument(DeleteLocalDocumentOptions deleteLocalDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteLocalDocumentOptions, "deleteLocalDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteLocalDocumentOptions.db());
pathParamsMap.put("doc_id", deleteLocalDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteLocalDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteLocalDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteLocalDocumentOptions.batch()));
}
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<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 postPartitionView.
/**
* Query a database partition MapReduce view function.
*
* Runs the specified view function from the specified design document. Unlike `GET /{db}/_design/{ddoc}/_view/{view}`
* for accessing views, the POST method supports the specification of explicit keys to be retrieved from the view
* results. The remainder of the POST view functionality is identical to the `GET /{db}/_design/{ddoc}/_view/{view}`
* API.
*
* @param postPartitionViewOptions the {@link PostPartitionViewOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ViewResult}
*/
public ServiceCall<ViewResult> postPartitionView(PostPartitionViewOptions postPartitionViewOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionViewOptions, "postPartitionViewOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postPartitionViewOptions.db());
pathParamsMap.put("partition_key", postPartitionViewOptions.partitionKey());
pathParamsMap.put("ddoc", postPartitionViewOptions.ddoc());
pathParamsMap.put("view", postPartitionViewOptions.view());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_design/{ddoc}/_view/{view}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionView");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
if (postPartitionViewOptions.attEncodingInfo() != null) {
contentJson.addProperty("att_encoding_info", postPartitionViewOptions.attEncodingInfo());
}
if (postPartitionViewOptions.attachments() != null) {
contentJson.addProperty("attachments", postPartitionViewOptions.attachments());
}
if (postPartitionViewOptions.conflicts() != null) {
contentJson.addProperty("conflicts", postPartitionViewOptions.conflicts());
}
if (postPartitionViewOptions.descending() != null) {
contentJson.addProperty("descending", postPartitionViewOptions.descending());
}
if (postPartitionViewOptions.includeDocs() != null) {
contentJson.addProperty("include_docs", postPartitionViewOptions.includeDocs());
}
if (postPartitionViewOptions.inclusiveEnd() != null) {
contentJson.addProperty("inclusive_end", postPartitionViewOptions.inclusiveEnd());
}
if (postPartitionViewOptions.limit() != null) {
contentJson.addProperty("limit", postPartitionViewOptions.limit());
}
if (postPartitionViewOptions.skip() != null) {
contentJson.addProperty("skip", postPartitionViewOptions.skip());
}
if (postPartitionViewOptions.updateSeq() != null) {
contentJson.addProperty("update_seq", postPartitionViewOptions.updateSeq());
}
if (postPartitionViewOptions.endkey() != null) {
contentJson.add("endkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.endkey()));
}
if (postPartitionViewOptions.endkeyDocid() != null) {
contentJson.addProperty("endkey_docid", postPartitionViewOptions.endkeyDocid());
}
if (postPartitionViewOptions.group() != null) {
contentJson.addProperty("group", postPartitionViewOptions.group());
}
if (postPartitionViewOptions.groupLevel() != null) {
contentJson.addProperty("group_level", postPartitionViewOptions.groupLevel());
}
if (postPartitionViewOptions.key() != null) {
contentJson.add("key", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.key()));
}
if (postPartitionViewOptions.keys() != null) {
contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.keys()));
}
if (postPartitionViewOptions.reduce() != null) {
contentJson.addProperty("reduce", postPartitionViewOptions.reduce());
}
if (postPartitionViewOptions.stable() != null) {
contentJson.addProperty("stable", postPartitionViewOptions.stable());
}
if (postPartitionViewOptions.startkey() != null) {
contentJson.add("startkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.startkey()));
}
if (postPartitionViewOptions.startkeyDocid() != null) {
contentJson.addProperty("startkey_docid", postPartitionViewOptions.startkeyDocid());
}
if (postPartitionViewOptions.update() != null) {
contentJson.addProperty("update", postPartitionViewOptions.update());
}
builder.bodyJson(contentJson);
ResponseConverter<ViewResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class BulkDocsTest method testBulkDocs.
@Test
public void testBulkDocs() throws Throwable {
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();
assertEquals(attachmentModel.contentType(), "testString");
assertEquals(attachmentModel.data(), TestUtilities.createMockByteArray("This is a mock byte array value."));
assertEquals(attachmentModel.digest(), "testString");
assertEquals(attachmentModel.encodedLength(), Long.valueOf("0"));
assertEquals(attachmentModel.encoding(), "testString");
assertEquals(attachmentModel.follows(), Boolean.valueOf(true));
assertEquals(attachmentModel.length(), Long.valueOf("0"));
assertEquals(attachmentModel.revpos(), Long.valueOf("1"));
assertEquals(attachmentModel.stub(), Boolean.valueOf(true));
Revisions revisionsModel = new Revisions.Builder().ids(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).start(Long.valueOf("1")).build();
assertEquals(revisionsModel.ids(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(revisionsModel.start(), Long.valueOf("1"));
DocumentRevisionStatus documentRevisionStatusModel = new DocumentRevisionStatus.Builder().rev("testString").status("available").build();
assertEquals(documentRevisionStatusModel.rev(), "testString");
assertEquals(documentRevisionStatusModel.status(), "available");
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("testString").localSeq("testString").rev("testString").revisions(revisionsModel).revsInfo(new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel))).add("foo", "testString").build();
assertEquals(documentModel.getAttachments(), new java.util.HashMap<String, Attachment>() {
{
put("foo", attachmentModel);
}
});
assertEquals(documentModel.getConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(documentModel.isDeleted(), Boolean.valueOf(true));
assertEquals(documentModel.getDeletedConflicts(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(documentModel.getId(), "testString");
assertEquals(documentModel.getLocalSeq(), "testString");
assertEquals(documentModel.getRev(), "testString");
assertEquals(documentModel.getRevisions(), revisionsModel);
assertEquals(documentModel.getRevsInfo(), new java.util.ArrayList<DocumentRevisionStatus>(java.util.Arrays.asList(documentRevisionStatusModel)));
assertEquals(documentModel.get("foo"), "testString");
BulkDocs bulkDocsModel = new BulkDocs.Builder().docs(new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel))).newEdits(true).build();
assertEquals(bulkDocsModel.docs(), new java.util.ArrayList<Document>(java.util.Arrays.asList(documentModel)));
assertEquals(bulkDocsModel.newEdits(), Boolean.valueOf(true));
String json = TestUtilities.serialize(bulkDocsModel);
BulkDocs bulkDocsModelNew = TestUtilities.deserialize(json, BulkDocs.class);
assertTrue(bulkDocsModelNew instanceof BulkDocs);
assertEquals(bulkDocsModelNew.newEdits(), Boolean.valueOf(true));
}
Aggregations