Search in sources :

Example 11 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method getDocument.

/**
 * Retrieve a document.
 *
 * Returns document with the specified `doc_id` from the specified database. Unless you request a specific revision,
 * the latest revision of the document is always returned.
 *
 * @param getDocumentOptions the {@link GetDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Document}
 */
public ServiceCall<Document> getDocument(GetDocumentOptions getDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getDocumentOptions, "getDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getDocumentOptions.db());
    pathParamsMap.put("doc_id", getDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", getDocumentOptions.ifNoneMatch());
    }
    if (getDocumentOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(getDocumentOptions.attachments()));
    }
    if (getDocumentOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(getDocumentOptions.attEncodingInfo()));
    }
    if (getDocumentOptions.conflicts() != null) {
        builder.query("conflicts", String.valueOf(getDocumentOptions.conflicts()));
    }
    if (getDocumentOptions.deletedConflicts() != null) {
        builder.query("deleted_conflicts", String.valueOf(getDocumentOptions.deletedConflicts()));
    }
    if (getDocumentOptions.latest() != null) {
        builder.query("latest", String.valueOf(getDocumentOptions.latest()));
    }
    if (getDocumentOptions.localSeq() != null) {
        builder.query("local_seq", String.valueOf(getDocumentOptions.localSeq()));
    }
    if (getDocumentOptions.meta() != null) {
        builder.query("meta", String.valueOf(getDocumentOptions.meta()));
    }
    if (getDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(getDocumentOptions.rev()));
    }
    if (getDocumentOptions.revs() != null) {
        builder.query("revs", String.valueOf(getDocumentOptions.revs()));
    }
    if (getDocumentOptions.revsInfo() != null) {
        builder.query("revs_info", String.valueOf(getDocumentOptions.revsInfo()));
    }
    ResponseConverter<Document> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Document>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument) Document(com.ibm.cloud.cloudant.v1.model.Document) SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument)

Example 12 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method deleteIndex.

/**
 * Delete an index.
 *
 * @param deleteIndexOptions the {@link DeleteIndexOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> deleteIndex(DeleteIndexOptions deleteIndexOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteIndexOptions, "deleteIndexOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteIndexOptions.db());
    pathParamsMap.put("ddoc", deleteIndexOptions.ddoc());
    pathParamsMap.put("type", deleteIndexOptions.type());
    pathParamsMap.put("index", deleteIndexOptions.index());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_index/_design/{ddoc}/{type}/{index}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteIndex");
    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 13 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method putDatabase.

/**
 * Create a database.
 *
 * @param putDatabaseOptions the {@link PutDatabaseOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putDatabase(PutDatabaseOptions putDatabaseOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putDatabaseOptions, "putDatabaseOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", putDatabaseOptions.db());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putDatabase");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (putDatabaseOptions.partitioned() != null) {
        builder.query("partitioned", String.valueOf(putDatabaseOptions.partitioned()));
    }
    if (putDatabaseOptions.q() != null) {
        builder.query("q", String.valueOf(putDatabaseOptions.q()));
    }
    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 14 with Cloudant

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

Example 15 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method getReplicationDocument.

/**
 * Retrieve a replication document.
 *
 * Retrieves a replication document from the `_replicator` database to view the configuration of the replication. The
 * status of the replication is no longer recorded in the document but can be checked via the replication scheduler.
 *
 * @param getReplicationDocumentOptions the {@link GetReplicationDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ReplicationDocument}
 */
public ServiceCall<ReplicationDocument> getReplicationDocument(GetReplicationDocumentOptions getReplicationDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getReplicationDocumentOptions, "getReplicationDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", getReplicationDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getReplicationDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getReplicationDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", getReplicationDocumentOptions.ifNoneMatch());
    }
    if (getReplicationDocumentOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(getReplicationDocumentOptions.attachments()));
    }
    if (getReplicationDocumentOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(getReplicationDocumentOptions.attEncodingInfo()));
    }
    if (getReplicationDocumentOptions.conflicts() != null) {
        builder.query("conflicts", String.valueOf(getReplicationDocumentOptions.conflicts()));
    }
    if (getReplicationDocumentOptions.deletedConflicts() != null) {
        builder.query("deleted_conflicts", String.valueOf(getReplicationDocumentOptions.deletedConflicts()));
    }
    if (getReplicationDocumentOptions.latest() != null) {
        builder.query("latest", String.valueOf(getReplicationDocumentOptions.latest()));
    }
    if (getReplicationDocumentOptions.localSeq() != null) {
        builder.query("local_seq", String.valueOf(getReplicationDocumentOptions.localSeq()));
    }
    if (getReplicationDocumentOptions.meta() != null) {
        builder.query("meta", String.valueOf(getReplicationDocumentOptions.meta()));
    }
    if (getReplicationDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(getReplicationDocumentOptions.rev()));
    }
    if (getReplicationDocumentOptions.revs() != null) {
        builder.query("revs", String.valueOf(getReplicationDocumentOptions.revs()));
    }
    if (getReplicationDocumentOptions.revsInfo() != null) {
        builder.query("revs_info", String.valueOf(getReplicationDocumentOptions.revsInfo()));
    }
    ResponseConverter<ReplicationDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ReplicationDocument>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument)

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