Search in sources :

Example 16 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method getAllDbs.

/**
 * Query a list of all database names in the instance.
 *
 * @param getAllDbsOptions the {@link GetAllDbsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link List}
 */
public ServiceCall<List<String>> getAllDbs(GetAllDbsOptions getAllDbsOptions) {
    if (getAllDbsOptions == null) {
        getAllDbsOptions = new GetAllDbsOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_all_dbs"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getAllDbs");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getAllDbsOptions.descending() != null) {
        builder.query("descending", String.valueOf(getAllDbsOptions.descending()));
    }
    if (getAllDbsOptions.endkey() != null) {
        builder.query("endkey", String.valueOf(getAllDbsOptions.endkey()));
    }
    if (getAllDbsOptions.limit() != null) {
        builder.query("limit", String.valueOf(getAllDbsOptions.limit()));
    }
    if (getAllDbsOptions.skip() != null) {
        builder.query("skip", String.valueOf(getAllDbsOptions.skip()));
    }
    if (getAllDbsOptions.startkey() != null) {
        builder.query("startkey", String.valueOf(getAllDbsOptions.startkey()));
    }
    ResponseConverter<List<String>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<List<String>>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) List(java.util.List)

Example 17 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method postPartitionSearchAsStream.

/**
 * Query a database partition search index as stream.
 *
 * Partitioned Search indexes, which are defined in design documents, allow partition databases to be queried by using
 * Lucene Query Parser Syntax. Search indexes are defined by an index function, similar to a map function in MapReduce
 * views. The index function decides what data to index and store in the index.
 *
 * @param postPartitionSearchOptions the {@link PostPartitionSearchOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link InputStream}
 */
public ServiceCall<InputStream> postPartitionSearchAsStream(PostPartitionSearchOptions postPartitionSearchOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionSearchOptions, "postPartitionSearchOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postPartitionSearchOptions.db());
    pathParamsMap.put("partition_key", postPartitionSearchOptions.partitionKey());
    pathParamsMap.put("ddoc", postPartitionSearchOptions.ddoc());
    pathParamsMap.put("index", postPartitionSearchOptions.index());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_design/{ddoc}/_search/{index}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionSearchAsStream");
    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", postPartitionSearchOptions.query());
    if (postPartitionSearchOptions.bookmark() != null) {
        contentJson.addProperty("bookmark", postPartitionSearchOptions.bookmark());
    }
    if (postPartitionSearchOptions.highlightFields() != null) {
        contentJson.add("highlight_fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionSearchOptions.highlightFields()));
    }
    if (postPartitionSearchOptions.highlightNumber() != null) {
        contentJson.addProperty("highlight_number", postPartitionSearchOptions.highlightNumber());
    }
    if (postPartitionSearchOptions.highlightPostTag() != null) {
        contentJson.addProperty("highlight_post_tag", postPartitionSearchOptions.highlightPostTag());
    }
    if (postPartitionSearchOptions.highlightPreTag() != null) {
        contentJson.addProperty("highlight_pre_tag", postPartitionSearchOptions.highlightPreTag());
    }
    if (postPartitionSearchOptions.highlightSize() != null) {
        contentJson.addProperty("highlight_size", postPartitionSearchOptions.highlightSize());
    }
    if (postPartitionSearchOptions.includeDocs() != null) {
        contentJson.addProperty("include_docs", postPartitionSearchOptions.includeDocs());
    }
    if (postPartitionSearchOptions.includeFields() != null) {
        contentJson.add("include_fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionSearchOptions.includeFields()));
    }
    if (postPartitionSearchOptions.limit() != null) {
        contentJson.addProperty("limit", postPartitionSearchOptions.limit());
    }
    if (postPartitionSearchOptions.sort() != null) {
        contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionSearchOptions.sort()));
    }
    if (postPartitionSearchOptions.stale() != null) {
        contentJson.addProperty("stale", postPartitionSearchOptions.stale());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject)

Example 18 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method postFindAsStream.

/**
 * Query an index by using selector syntax as stream.
 *
 * 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 postFindOptions the {@link PostFindOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link InputStream}
 */
public ServiceCall<InputStream> postFindAsStream(PostFindOptions postFindOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postFindOptions, "postFindOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postFindOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_find", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postFindAsStream");
    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(postFindOptions.selector()));
    if (postFindOptions.bookmark() != null) {
        contentJson.addProperty("bookmark", postFindOptions.bookmark());
    }
    if (postFindOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postFindOptions.conflicts());
    }
    if (postFindOptions.executionStats() != null) {
        contentJson.addProperty("execution_stats", postFindOptions.executionStats());
    }
    if (postFindOptions.fields() != null) {
        contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postFindOptions.fields()));
    }
    if (postFindOptions.limit() != null) {
        contentJson.addProperty("limit", postFindOptions.limit());
    }
    if (postFindOptions.skip() != null) {
        contentJson.addProperty("skip", postFindOptions.skip());
    }
    if (postFindOptions.sort() != null) {
        contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postFindOptions.sort()));
    }
    if (postFindOptions.stable() != null) {
        contentJson.addProperty("stable", postFindOptions.stable());
    }
    if (postFindOptions.update() != null) {
        contentJson.addProperty("update", postFindOptions.update());
    }
    if (postFindOptions.useIndex() != null) {
        contentJson.add("use_index", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postFindOptions.useIndex()));
    }
    if (postFindOptions.r() != null) {
        contentJson.addProperty("r", postFindOptions.r());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject)

Example 19 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder 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 20 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder 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)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)422 HashMap (java.util.HashMap)324 JsonObject (com.google.gson.JsonObject)111 MultipartBody (okhttp3.MultipartBody)30 InputStream (java.io.InputStream)27 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)12 Ok (com.ibm.cloud.cloudant.v1.model.Ok)8 MetricResponse (com.ibm.watson.discovery.v1.model.MetricResponse)4 DeleteModelResults (com.ibm.watson.natural_language_understanding.v1.model.DeleteModelResults)4 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)4 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 TagsSubscriptionList (com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList)3 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)3 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)3 Entity (com.ibm.watson.assistant.v1.model.Entity)3 Intent (com.ibm.watson.assistant.v1.model.Intent)3 Value (com.ibm.watson.assistant.v1.model.Value)3 DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)3 TokenDictStatusResponse (com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)3