Search in sources :

Example 81 with Cloudant

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

the class Cloudant method postPartitionFind.

/**
 * Query a database partition index by using selector syntax (POST).
 *
 * Query documents by using a declarative JSON querying syntax. Queries can use the built-in `_all_docs` index or
 * custom indices, specified by using the `_index` endpoint.
 *
 * @param postPartitionFindOptions the {@link PostPartitionFindOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link FindResult}
 */
public ServiceCall<FindResult> postPartitionFind(PostPartitionFindOptions postPartitionFindOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionFindOptions, "postPartitionFindOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postPartitionFindOptions.db());
    pathParamsMap.put("partition_key", postPartitionFindOptions.partitionKey());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_find", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionFind");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.add("selector", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.selector()));
    if (postPartitionFindOptions.bookmark() != null) {
        contentJson.addProperty("bookmark", postPartitionFindOptions.bookmark());
    }
    if (postPartitionFindOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postPartitionFindOptions.conflicts());
    }
    if (postPartitionFindOptions.executionStats() != null) {
        contentJson.addProperty("execution_stats", postPartitionFindOptions.executionStats());
    }
    if (postPartitionFindOptions.fields() != null) {
        contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.fields()));
    }
    if (postPartitionFindOptions.limit() != null) {
        contentJson.addProperty("limit", postPartitionFindOptions.limit());
    }
    if (postPartitionFindOptions.skip() != null) {
        contentJson.addProperty("skip", postPartitionFindOptions.skip());
    }
    if (postPartitionFindOptions.sort() != null) {
        contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.sort()));
    }
    if (postPartitionFindOptions.stable() != null) {
        contentJson.addProperty("stable", postPartitionFindOptions.stable());
    }
    if (postPartitionFindOptions.update() != null) {
        contentJson.addProperty("update", postPartitionFindOptions.update());
    }
    if (postPartitionFindOptions.useIndex() != null) {
        contentJson.add("use_index", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.useIndex()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<FindResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<FindResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) FindResult(com.ibm.cloud.cloudant.v1.model.FindResult)

Example 82 with Cloudant

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

the class Cloudant method postPartitionView.

/**
 * Query a database partition MapReduce view function.
 *
 * Runs the specified view function from the specified design document. Unlike `GET /{db}/_design/{ddoc}/_view/{view}`
 * for accessing views, the POST method supports the specification of explicit keys to be retrieved from the view
 * results. The remainder of the POST view functionality is identical to the `GET /{db}/_design/{ddoc}/_view/{view}`
 * API.
 *
 * @param postPartitionViewOptions the {@link PostPartitionViewOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ViewResult}
 */
public ServiceCall<ViewResult> postPartitionView(PostPartitionViewOptions postPartitionViewOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionViewOptions, "postPartitionViewOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postPartitionViewOptions.db());
    pathParamsMap.put("partition_key", postPartitionViewOptions.partitionKey());
    pathParamsMap.put("ddoc", postPartitionViewOptions.ddoc());
    pathParamsMap.put("view", postPartitionViewOptions.view());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_design/{ddoc}/_view/{view}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionView");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (postPartitionViewOptions.attEncodingInfo() != null) {
        contentJson.addProperty("att_encoding_info", postPartitionViewOptions.attEncodingInfo());
    }
    if (postPartitionViewOptions.attachments() != null) {
        contentJson.addProperty("attachments", postPartitionViewOptions.attachments());
    }
    if (postPartitionViewOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postPartitionViewOptions.conflicts());
    }
    if (postPartitionViewOptions.descending() != null) {
        contentJson.addProperty("descending", postPartitionViewOptions.descending());
    }
    if (postPartitionViewOptions.includeDocs() != null) {
        contentJson.addProperty("include_docs", postPartitionViewOptions.includeDocs());
    }
    if (postPartitionViewOptions.inclusiveEnd() != null) {
        contentJson.addProperty("inclusive_end", postPartitionViewOptions.inclusiveEnd());
    }
    if (postPartitionViewOptions.limit() != null) {
        contentJson.addProperty("limit", postPartitionViewOptions.limit());
    }
    if (postPartitionViewOptions.skip() != null) {
        contentJson.addProperty("skip", postPartitionViewOptions.skip());
    }
    if (postPartitionViewOptions.updateSeq() != null) {
        contentJson.addProperty("update_seq", postPartitionViewOptions.updateSeq());
    }
    if (postPartitionViewOptions.endkey() != null) {
        contentJson.add("endkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.endkey()));
    }
    if (postPartitionViewOptions.endkeyDocid() != null) {
        contentJson.addProperty("endkey_docid", postPartitionViewOptions.endkeyDocid());
    }
    if (postPartitionViewOptions.group() != null) {
        contentJson.addProperty("group", postPartitionViewOptions.group());
    }
    if (postPartitionViewOptions.groupLevel() != null) {
        contentJson.addProperty("group_level", postPartitionViewOptions.groupLevel());
    }
    if (postPartitionViewOptions.key() != null) {
        contentJson.add("key", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.key()));
    }
    if (postPartitionViewOptions.keys() != null) {
        contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.keys()));
    }
    if (postPartitionViewOptions.reduce() != null) {
        contentJson.addProperty("reduce", postPartitionViewOptions.reduce());
    }
    if (postPartitionViewOptions.stable() != null) {
        contentJson.addProperty("stable", postPartitionViewOptions.stable());
    }
    if (postPartitionViewOptions.startkey() != null) {
        contentJson.add("startkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionViewOptions.startkey()));
    }
    if (postPartitionViewOptions.startkeyDocid() != null) {
        contentJson.addProperty("startkey_docid", postPartitionViewOptions.startkeyDocid());
    }
    if (postPartitionViewOptions.update() != null) {
        contentJson.addProperty("update", postPartitionViewOptions.update());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<ViewResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) ViewResult(com.ibm.cloud.cloudant.v1.model.ViewResult)

Example 83 with Cloudant

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

the class Cloudant method postRevsDiff.

/**
 * Query the document revisions and possible ancestors missing from the database.
 *
 * The replicator is the primary user of this operation. After receiving a set of new revision IDs from the source
 * database, the replicator sends this set to the destination database's `_revs_diff` to find out which of them
 * already exists there. It can then avoid fetching and sending already-known document bodies.
 *
 * @param postRevsDiffOptions the {@link PostRevsDiffOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Map}
 */
public ServiceCall<Map<String, RevsDiff>> postRevsDiff(PostRevsDiffOptions postRevsDiffOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postRevsDiffOptions, "postRevsDiffOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postRevsDiffOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_revs_diff", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postRevsDiff");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithoutPrettyPrinting().toJson(postRevsDiffOptions.documentRevisions()), "application/json");
    ResponseConverter<Map<String, RevsDiff>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Map<String, RevsDiff>>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RevsDiff(com.ibm.cloud.cloudant.v1.model.RevsDiff) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 84 with Cloudant

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

the class Cloudant method postIndex.

/**
 * Create a new index on a database.
 *
 * Create a new index on a database.
 *
 * @param postIndexOptions the {@link PostIndexOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link IndexResult}
 */
public ServiceCall<IndexResult> postIndex(PostIndexOptions postIndexOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postIndexOptions, "postIndexOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postIndexOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_index", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postIndex");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.add("index", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postIndexOptions.index()));
    if (postIndexOptions.ddoc() != null) {
        contentJson.addProperty("ddoc", postIndexOptions.ddoc());
    }
    if (postIndexOptions.def() != null) {
        contentJson.add("def", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postIndexOptions.def()));
    }
    if (postIndexOptions.name() != null) {
        contentJson.addProperty("name", postIndexOptions.name());
    }
    if (postIndexOptions.partitioned() != null) {
        contentJson.addProperty("partitioned", postIndexOptions.partitioned());
    }
    if (postIndexOptions.type() != null) {
        contentJson.addProperty("type", postIndexOptions.type());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<IndexResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<IndexResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) IndexResult(com.ibm.cloud.cloudant.v1.model.IndexResult)

Example 85 with Cloudant

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

the class Cloudant method getUuids.

/**
 * Retrieve one or more UUIDs.
 *
 * Requests one or more Universally Unique Identifiers (UUIDs) from the instance. The response is a JSON object that
 * provides a list of UUIDs.
 *
 * @param getUuidsOptions the {@link GetUuidsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link UuidsResult}
 */
public ServiceCall<UuidsResult> getUuids(GetUuidsOptions getUuidsOptions) {
    if (getUuidsOptions == null) {
        getUuidsOptions = new GetUuidsOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_uuids"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getUuids");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getUuidsOptions.count() != null) {
        builder.query("count", String.valueOf(getUuidsOptions.count()));
    }
    ResponseConverter<UuidsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<UuidsResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : UuidsResult(com.ibm.cloud.cloudant.v1.model.UuidsResult) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

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