Search in sources :

Example 76 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 77 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 78 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 79 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DesignDocumentInformation(com.ibm.cloud.cloudant.v1.model.DesignDocumentInformation)

Example 80 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)70 HashMap (java.util.HashMap)51 JsonObject (com.google.gson.JsonObject)23 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)17 Ok (com.ibm.cloud.cloudant.v1.model.Ok)11 Document (com.ibm.cloud.cloudant.v1.model.Document)9 List (java.util.List)8 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)6 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)6 ArrayList (java.util.ArrayList)6 Cloudant (com.ibm.cloud.cloudant.v1.Cloudant)5 SecurityObject (com.ibm.cloud.cloudant.v1.model.SecurityObject)5 Test (org.testng.annotations.Test)5 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 GetDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDocumentOptions)3 PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)3 PostDocumentOptions (com.ibm.cloud.cloudant.v1.model.PostDocumentOptions)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3