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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations