use of com.ibm.cloud.cloudant.v1.model.DocumentResult in project cloudant-java-sdk by IBM.
the class Cloudant method deleteAttachment.
/**
* Delete an attachment.
*
* Deletes the attachment with the filename, `{attachment_name}`, from the specified doc. You must supply the `rev`
* query parameter or `If-Match` header with the current revision to delete the attachment.
*
* @param deleteAttachmentOptions the {@link DeleteAttachmentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteAttachment(DeleteAttachmentOptions deleteAttachmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteAttachmentOptions, "deleteAttachmentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteAttachmentOptions.db());
pathParamsMap.put("doc_id", deleteAttachmentOptions.docId());
pathParamsMap.put("attachment_name", deleteAttachmentOptions.attachmentName());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}/{attachment_name}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteAttachment");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteAttachmentOptions.ifMatch() != null) {
builder.header("If-Match", deleteAttachmentOptions.ifMatch());
}
if (deleteAttachmentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteAttachmentOptions.rev()));
}
if (deleteAttachmentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteAttachmentOptions.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.DocumentResult in project cloudant-java-sdk by IBM.
the class Cloudant method putLocalDocument.
/**
* Create or modify a local document.
*
* Stores the specified local document. The semantics are identical to storing a standard document in the specified
* database, except that the document is not replicated.
*
* @param putLocalDocumentOptions the {@link PutLocalDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> putLocalDocument(PutLocalDocumentOptions putLocalDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putLocalDocumentOptions, "putLocalDocumentOptions cannot be null");
if (putLocalDocumentOptions.document() != null && putLocalDocumentOptions.contentType() == null) {
putLocalDocumentOptions = putLocalDocumentOptions.newBuilder().contentType("application/json").build();
}
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putLocalDocumentOptions.db());
pathParamsMap.put("doc_id", putLocalDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putLocalDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (putLocalDocumentOptions.contentType() != null) {
builder.header("Content-Type", putLocalDocumentOptions.contentType());
}
if (putLocalDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(putLocalDocumentOptions.batch()));
}
builder.bodyContent(putLocalDocumentOptions.contentType(), putLocalDocumentOptions.document(), null, putLocalDocumentOptions.body());
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.DocumentResult in project cloudant-java-sdk by IBM.
the class Cloudant method putReplicationDocument.
/**
* Create or modify a replication using a replication document.
*
* Creates or modifies a document in the `_replicator` database to start a new replication or to edit an existing
* replication.
*
* @param putReplicationDocumentOptions the {@link PutReplicationDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> putReplicationDocument(PutReplicationDocumentOptions putReplicationDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putReplicationDocumentOptions, "putReplicationDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("doc_id", putReplicationDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putReplicationDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (putReplicationDocumentOptions.ifMatch() != null) {
builder.header("If-Match", putReplicationDocumentOptions.ifMatch());
}
if (putReplicationDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(putReplicationDocumentOptions.batch()));
}
if (putReplicationDocumentOptions.newEdits() != null) {
builder.query("new_edits", String.valueOf(putReplicationDocumentOptions.newEdits()));
}
if (putReplicationDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(putReplicationDocumentOptions.rev()));
}
builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting().toJson(putReplicationDocumentOptions.replicationDocument()), "application/json");
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.DocumentResult in project cloudant-java-sdk by IBM.
the class Cloudant method postDocument.
/**
* Create or modify a document in a database.
*
* Creates or modifies a document in the specified database by using the supplied JSON document. If the JSON document
* doesn't specify an `_id` field, then the document is created with a new unique ID generated by the UUID algorithm
* that is configured for the server. If the document includes the `_id` field, then it is created with that `_id` or
* updated if the `_id` already exists, and an appropriate `_rev` is included in the JSON document. If the `_id`
* includes the `_local` or `_design` prefix, then this operation is used to create or modify local or design
* documents respectively.
*
* @param postDocumentOptions the {@link PostDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> postDocument(PostDocumentOptions postDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postDocumentOptions, "postDocumentOptions cannot be null");
if (postDocumentOptions.document() != null && postDocumentOptions.contentType() == null) {
postDocumentOptions = postDocumentOptions.newBuilder().contentType("application/json").build();
}
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postDocumentOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (postDocumentOptions.contentType() != null) {
builder.header("Content-Type", postDocumentOptions.contentType());
}
if (postDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(postDocumentOptions.batch()));
}
builder.bodyContent(postDocumentOptions.contentType(), postDocumentOptions.document(), null, postDocumentOptions.body());
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.DocumentResult in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDocument.
/**
* Delete a document.
*
* Marks the specified document as deleted by adding a `_deleted` field with the value `true`. Documents with this
* field are not returned within requests anymore but stay in the database. You must supply the current (latest)
* revision, either by using the `rev` parameter or by using the `If-Match` header to specify the revision.
*
* @param deleteDocumentOptions the {@link DeleteDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteDocument(DeleteDocumentOptions deleteDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDocumentOptions, "deleteDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDocumentOptions.db());
pathParamsMap.put("doc_id", deleteDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteDocumentOptions.ifMatch() != null) {
builder.header("If-Match", deleteDocumentOptions.ifMatch());
}
if (deleteDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteDocumentOptions.batch()));
}
if (deleteDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteDocumentOptions.rev()));
}
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations