Search in sources :

Example 6 with Cloudant

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

the class Cloudant method postSearch.

/**
 * Query a search index.
 *
 * Search indexes, which are defined in design documents, allow databases to be queried by using Lucene Query Parser
 * Syntax. An index function defines a search index, similar to a map function in MapReduce views. The index function
 * decides what data to index and what data to store in the index. The advantage of using the HTTP `POST` method is
 * that the query is submitted as a JSON object in the request body. This avoids the limitations of passing query
 * options as URL query parameters of a `GET` request.
 *
 * @param postSearchOptions the {@link PostSearchOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SearchResult}
 */
public ServiceCall<SearchResult> postSearch(PostSearchOptions postSearchOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postSearchOptions, "postSearchOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postSearchOptions.db());
    pathParamsMap.put("ddoc", postSearchOptions.ddoc());
    pathParamsMap.put("index", postSearchOptions.index());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_search/{index}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postSearch");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("query", postSearchOptions.query());
    if (postSearchOptions.bookmark() != null) {
        contentJson.addProperty("bookmark", postSearchOptions.bookmark());
    }
    if (postSearchOptions.highlightFields() != null) {
        contentJson.add("highlight_fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.highlightFields()));
    }
    if (postSearchOptions.highlightNumber() != null) {
        contentJson.addProperty("highlight_number", postSearchOptions.highlightNumber());
    }
    if (postSearchOptions.highlightPostTag() != null) {
        contentJson.addProperty("highlight_post_tag", postSearchOptions.highlightPostTag());
    }
    if (postSearchOptions.highlightPreTag() != null) {
        contentJson.addProperty("highlight_pre_tag", postSearchOptions.highlightPreTag());
    }
    if (postSearchOptions.highlightSize() != null) {
        contentJson.addProperty("highlight_size", postSearchOptions.highlightSize());
    }
    if (postSearchOptions.includeDocs() != null) {
        contentJson.addProperty("include_docs", postSearchOptions.includeDocs());
    }
    if (postSearchOptions.includeFields() != null) {
        contentJson.add("include_fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.includeFields()));
    }
    if (postSearchOptions.limit() != null) {
        contentJson.addProperty("limit", postSearchOptions.limit());
    }
    if (postSearchOptions.sort() != null) {
        contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.sort()));
    }
    if (postSearchOptions.stale() != null) {
        contentJson.addProperty("stale", postSearchOptions.stale());
    }
    if (postSearchOptions.counts() != null) {
        contentJson.add("counts", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.counts()));
    }
    if (postSearchOptions.drilldown() != null) {
        contentJson.add("drilldown", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.drilldown()));
    }
    if (postSearchOptions.groupField() != null) {
        contentJson.addProperty("group_field", postSearchOptions.groupField());
    }
    if (postSearchOptions.groupLimit() != null) {
        contentJson.addProperty("group_limit", postSearchOptions.groupLimit());
    }
    if (postSearchOptions.groupSort() != null) {
        contentJson.add("group_sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.groupSort()));
    }
    if (postSearchOptions.ranges() != null) {
        contentJson.add("ranges", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postSearchOptions.ranges()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<SearchResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SearchResult>() {
    }.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) SearchResult(com.ibm.cloud.cloudant.v1.model.SearchResult)

Example 7 with Cloudant

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

the class Cloudant method getSchedulerDocument.

/**
 * Retrieve a replication scheduler document.
 *
 * Retrieves information about a replication document from the replicator database. The endpoint returns the document
 * ID, database, replication ID, source and target, and other information.
 *
 * @param getSchedulerDocumentOptions the {@link GetSchedulerDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SchedulerDocument}
 */
public ServiceCall<SchedulerDocument> getSchedulerDocument(GetSchedulerDocumentOptions getSchedulerDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSchedulerDocumentOptions, "getSchedulerDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", getSchedulerDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_scheduler/docs/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSchedulerDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<SchedulerDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SchedulerDocument>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : SchedulerDocument(com.ibm.cloud.cloudant.v1.model.SchedulerDocument) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 8 with Cloudant

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

the class Cloudant method postActivityTrackerEvents.

/**
 * Modify Activity Tracker events configuration.
 *
 * Configure event types that are being sent to IBM Cloud Activity Tracker for the IBM Cloudant instance.
 *
 * @param postActivityTrackerEventsOptions the {@link PostActivityTrackerEventsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> postActivityTrackerEvents(PostActivityTrackerEventsOptions postActivityTrackerEventsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postActivityTrackerEventsOptions, "postActivityTrackerEventsOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/activity_tracker/events"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postActivityTrackerEvents");
    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("types", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postActivityTrackerEventsOptions.types()));
    builder.bodyJson(contentJson);
    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) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 9 with Cloudant

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

the class Cloudant method putCapacityThroughputConfiguration.

/**
 * Update the target provisioned throughput capacity.
 *
 * Sets the target provisioned throughput capacity for an IBM Cloudant instance. When target capacity is changed, the
 * current capacity asynchronously changes to meet the target capacity.
 *
 * @param putCapacityThroughputConfigurationOptions the {@link PutCapacityThroughputConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link CapacityThroughputInformation}
 */
public ServiceCall<CapacityThroughputInformation> putCapacityThroughputConfiguration(PutCapacityThroughputConfigurationOptions putCapacityThroughputConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putCapacityThroughputConfigurationOptions, "putCapacityThroughputConfigurationOptions cannot be null");
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/capacity/throughput"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCapacityThroughputConfiguration");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("blocks", putCapacityThroughputConfigurationOptions.blocks());
    builder.bodyJson(contentJson);
    ResponseConverter<CapacityThroughputInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CapacityThroughputInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : CapacityThroughputInformation(com.ibm.cloud.cloudant.v1.model.CapacityThroughputInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Example 10 with Cloudant

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

the class Cloudant method getSecurity.

/**
 * Retrieve database permissions information.
 *
 * See who has permission to read, write, and manage the database. The credentials you use to log in to the dashboard
 * automatically include `_admin` permissions to all databases you create. Everyone and everything else, including
 * users you share databases with and API keys you create, must be given a permission level explicitly.
 *
 * @param getSecurityOptions the {@link GetSecurityOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Security}
 */
public ServiceCall<Security> getSecurity(GetSecurityOptions getSecurityOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSecurityOptions, "getSecurityOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getSecurityOptions.db());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_security", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSecurity");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Security> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Security>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Security(com.ibm.cloud.cloudant.v1.model.Security)

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