use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method getSchedulerDocs.
/**
* Retrieve replication scheduler documents.
*
* Lists replication documents, including information about all documents, even the ones in a completed or failed
* state. For each document, the endpoint returns the document ID, database, replication ID, source and target, and
* other information.
*
* @param getSchedulerDocsOptions the {@link GetSchedulerDocsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link SchedulerDocsResult}
*/
public ServiceCall<SchedulerDocsResult> getSchedulerDocs(GetSchedulerDocsOptions getSchedulerDocsOptions) {
if (getSchedulerDocsOptions == null) {
getSchedulerDocsOptions = new GetSchedulerDocsOptions.Builder().build();
}
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_scheduler/docs"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSchedulerDocs");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getSchedulerDocsOptions.limit() != null) {
builder.query("limit", String.valueOf(getSchedulerDocsOptions.limit()));
}
if (getSchedulerDocsOptions.skip() != null) {
builder.query("skip", String.valueOf(getSchedulerDocsOptions.skip()));
}
if (getSchedulerDocsOptions.states() != null) {
builder.query("states", RequestUtils.join(getSchedulerDocsOptions.states(), ","));
}
ResponseConverter<SchedulerDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SchedulerDocsResult>() {
}.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 putDesignDocument.
/**
* Create or modify a design document.
*
* The PUT method creates a new named design document, or creates a new revision of the existing design document.
*
* @param putDesignDocumentOptions the {@link PutDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> putDesignDocument(PutDesignDocumentOptions putDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putDesignDocumentOptions, "putDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putDesignDocumentOptions.db());
pathParamsMap.put("ddoc", putDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (putDesignDocumentOptions.ifMatch() != null) {
builder.header("If-Match", putDesignDocumentOptions.ifMatch());
}
if (putDesignDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(putDesignDocumentOptions.batch()));
}
if (putDesignDocumentOptions.newEdits() != null) {
builder.query("new_edits", String.valueOf(putDesignDocumentOptions.newEdits()));
}
if (putDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(putDesignDocumentOptions.rev()));
}
builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting().toJson(putDesignDocumentOptions.designDocument()), "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.Document in project cloudant-java-sdk by IBM.
the class Cloudant method putDocument.
/**
* Create or modify a document.
*
* The PUT method creates a new named document, or creates a new revision of the existing document. Unlike the `POST
* /{db}` request, you must specify the document ID in the request URL.
*
* @param putDocumentOptions the {@link PutDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> putDocument(PutDocumentOptions putDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putDocumentOptions, "putDocumentOptions cannot be null");
if (putDocumentOptions.document() != null && putDocumentOptions.contentType() == null) {
putDocumentOptions = putDocumentOptions.newBuilder().contentType("application/json").build();
}
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putDocumentOptions.db());
pathParamsMap.put("doc_id", putDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (putDocumentOptions.contentType() != null) {
builder.header("Content-Type", putDocumentOptions.contentType());
}
if (putDocumentOptions.ifMatch() != null) {
builder.header("If-Match", putDocumentOptions.ifMatch());
}
if (putDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(putDocumentOptions.batch()));
}
if (putDocumentOptions.newEdits() != null) {
builder.query("new_edits", String.valueOf(putDocumentOptions.newEdits()));
}
if (putDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(putDocumentOptions.rev()));
}
builder.bodyContent(putDocumentOptions.contentType(), putDocumentOptions.document(), null, putDocumentOptions.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.Document in project cloudant-java-sdk by IBM.
the class Cloudant method deleteReplicationDocument.
/**
* Cancel a replication.
*
* Cancels a replication by deleting the document that describes it from the `_replicator` database.
*
* @param deleteReplicationDocumentOptions the {@link DeleteReplicationDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteReplicationDocument(DeleteReplicationDocumentOptions deleteReplicationDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteReplicationDocumentOptions, "deleteReplicationDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("doc_id", deleteReplicationDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteReplicationDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteReplicationDocumentOptions.ifMatch() != null) {
builder.header("If-Match", deleteReplicationDocumentOptions.ifMatch());
}
if (deleteReplicationDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteReplicationDocumentOptions.batch()));
}
if (deleteReplicationDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteReplicationDocumentOptions.rev()));
}
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 putAttachment.
/**
* Create or modify an attachment.
*
* Uploads the supplied content as an attachment to the specified document. The attachment name that you provide must
* be a URL encoded string. You must supply the Content-Type header, and for an existing document, you must also
* supply either the `rev` query argument or the `If-Match` HTTP header. If you omit the revision, a new, otherwise
* empty, document is created with the provided attachment, or a conflict occurs. If the uploaded attachment uses an
* existing attachment name in the remote database, it updates the corresponding stored content of the database. Since
* you must supply the revision information to add an attachment to the document, this serves as validation to update
* the existing attachment.
*
* @param putAttachmentOptions the {@link PutAttachmentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> putAttachment(PutAttachmentOptions putAttachmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putAttachmentOptions, "putAttachmentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putAttachmentOptions.db());
pathParamsMap.put("doc_id", putAttachmentOptions.docId());
pathParamsMap.put("attachment_name", putAttachmentOptions.attachmentName());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}/{attachment_name}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putAttachment");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.header("Content-Type", putAttachmentOptions.contentType());
if (putAttachmentOptions.ifMatch() != null) {
builder.header("If-Match", putAttachmentOptions.ifMatch());
}
if (putAttachmentOptions.rev() != null) {
builder.query("rev", String.valueOf(putAttachmentOptions.rev()));
}
builder.bodyContent(putAttachmentOptions.contentType(), null, null, putAttachmentOptions.attachment());
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations