use of com.ibm.cloud.cloudant.v1.model.Document 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.Document 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.Document 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);
}
use of com.ibm.cloud.cloudant.v1.model.Document in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDesignDocument.
/**
* Delete a design document.
*
* Marks the specified design document as deleted by adding a `_deleted` field with the value `true`. Documents with
* this field are not returned with requests 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 deleteDesignDocumentOptions the {@link DeleteDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteDesignDocument(DeleteDesignDocumentOptions deleteDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDesignDocumentOptions, "deleteDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDesignDocumentOptions.db());
pathParamsMap.put("ddoc", deleteDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteDesignDocumentOptions.ifMatch() != null) {
builder.header("If-Match", deleteDesignDocumentOptions.ifMatch());
}
if (deleteDesignDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteDesignDocumentOptions.batch()));
}
if (deleteDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteDesignDocumentOptions.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 GetInfoFromExistingDatabase method main.
public static void main(String[] args) {
// 1. Create a Cloudant client with "EXAMPLES" service name ===========
Cloudant client = Cloudant.newInstance("EXAMPLES");
// 2. Get server information ==========================================
ServerInformation serverInformation = client.getServerInformation().execute().getResult();
System.out.println("Server Version: " + serverInformation.getVersion());
// 3. Get database information for "animaldb" =========================
String dbName = "animaldb";
GetDatabaseInformationOptions dbInformationOptions = new GetDatabaseInformationOptions.Builder(dbName).build();
DatabaseInformation dbInformationResponse = client.getDatabaseInformation(dbInformationOptions).execute().getResult();
// 4. Show document count in database =================================
Long documentCount = dbInformationResponse.getDocCount();
System.out.println("Document count in \"" + dbInformationResponse.getDbName() + "\" database is " + documentCount + ".");
// 5. Get zebra document out of the database by document id ===========
GetDocumentOptions getDocOptions = new GetDocumentOptions.Builder().db(dbName).docId("zebra").build();
Document documentAboutZebra = client.getDocument(getDocOptions).execute().getResult();
System.out.println("Document retrieved from database:\n" + documentAboutZebra);
}
Aggregations