use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.
the class Cloudant method postAllDocsQueriesAsStream.
/**
* Multi-query the list of all documents in a database as stream.
*
* Runs multiple queries using the primary index (all document IDs). Returns a JSON object that contains a list of
* result objects, one for each query, with a structure equivalent to that of a single `_all_docs` request. This
* enables you to request multiple queries in a single request, in place of multiple `POST /{db}/_all_docs` requests.
*
* @param postAllDocsQueriesOptions the {@link PostAllDocsQueriesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link InputStream}
*/
public ServiceCall<InputStream> postAllDocsQueriesAsStream(PostAllDocsQueriesOptions postAllDocsQueriesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsQueriesOptions, "postAllDocsQueriesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postAllDocsQueriesOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs/queries", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocsQueriesAsStream");
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("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postAllDocsQueriesOptions.queries()));
builder.bodyJson(contentJson);
ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class CompareComply method compareDocuments.
/**
* Compare two documents.
*
* <p>Compares two input documents. Documents must be in the same format.
*
* @param compareDocumentsOptions the {@link CompareDocumentsOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link CompareReturn}
*/
public ServiceCall<CompareReturn> compareDocuments(CompareDocumentsOptions compareDocumentsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(compareDocumentsOptions, "compareDocumentsOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/comparison"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "compareDocuments");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
if (compareDocumentsOptions.file1Label() != null) {
builder.query("file_1_label", String.valueOf(compareDocumentsOptions.file1Label()));
}
if (compareDocumentsOptions.file2Label() != null) {
builder.query("file_2_label", String.valueOf(compareDocumentsOptions.file2Label()));
}
if (compareDocumentsOptions.model() != null) {
builder.query("model", String.valueOf(compareDocumentsOptions.model()));
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
okhttp3.RequestBody file1Body = RequestUtils.inputStreamBody(compareDocumentsOptions.file1(), compareDocumentsOptions.file1ContentType());
multipartBuilder.addFormDataPart("file_1", "filename", file1Body);
okhttp3.RequestBody file2Body = RequestUtils.inputStreamBody(compareDocumentsOptions.file2(), compareDocumentsOptions.file2ContentType());
multipartBuilder.addFormDataPart("file_2", "filename", file2Body);
builder.body(multipartBuilder.build());
ResponseConverter<CompareReturn> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CompareReturn>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class CompareComply method createBatch.
/**
* Submit a batch-processing request.
*
* <p>Run Compare and Comply methods over a collection of input documents.
*
* <p>**Important:** Batch processing requires the use of the [IBM Cloud Object Storage
* service](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-about#about-ibm-cloud-object-storage).
* The use of IBM Cloud Object Storage with Compare and Comply is discussed at [Using batch
* processing](https://cloud.ibm.com/docs/compare-comply?topic=compare-comply-batching#before-you-batch).
*
* @param createBatchOptions the {@link CreateBatchOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link BatchStatus}
*/
public ServiceCall<BatchStatus> createBatch(CreateBatchOptions createBatchOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createBatchOptions, "createBatchOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "createBatch");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
builder.query("function", String.valueOf(createBatchOptions.function()));
if (createBatchOptions.model() != null) {
builder.query("model", String.valueOf(createBatchOptions.model()));
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
okhttp3.RequestBody inputCredentialsFileBody = RequestUtils.inputStreamBody(createBatchOptions.inputCredentialsFile(), "application/json");
multipartBuilder.addFormDataPart("input_credentials_file", "filename", inputCredentialsFileBody);
multipartBuilder.addFormDataPart("input_bucket_location", createBatchOptions.inputBucketLocation());
multipartBuilder.addFormDataPart("input_bucket_name", createBatchOptions.inputBucketName());
okhttp3.RequestBody outputCredentialsFileBody = RequestUtils.inputStreamBody(createBatchOptions.outputCredentialsFile(), "application/json");
multipartBuilder.addFormDataPart("output_credentials_file", "filename", outputCredentialsFileBody);
multipartBuilder.addFormDataPart("output_bucket_location", createBatchOptions.outputBucketLocation());
multipartBuilder.addFormDataPart("output_bucket_name", createBatchOptions.outputBucketName());
builder.body(multipartBuilder.build());
ResponseConverter<BatchStatus> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BatchStatus>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class CompareComply method listFeedback.
/**
* List the feedback in a document.
*
* <p>Lists the feedback in a document.
*
* @param listFeedbackOptions the {@link ListFeedbackOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link FeedbackList}
*/
public ServiceCall<FeedbackList> listFeedback(ListFeedbackOptions listFeedbackOptions) {
if (listFeedbackOptions == null) {
listFeedbackOptions = new ListFeedbackOptions.Builder().build();
}
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/feedback"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "listFeedback");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
if (listFeedbackOptions.feedbackType() != null) {
builder.query("feedback_type", String.valueOf(listFeedbackOptions.feedbackType()));
}
if (listFeedbackOptions.documentTitle() != null) {
builder.query("document_title", String.valueOf(listFeedbackOptions.documentTitle()));
}
if (listFeedbackOptions.modelId() != null) {
builder.query("model_id", String.valueOf(listFeedbackOptions.modelId()));
}
if (listFeedbackOptions.modelVersion() != null) {
builder.query("model_version", String.valueOf(listFeedbackOptions.modelVersion()));
}
if (listFeedbackOptions.categoryRemoved() != null) {
builder.query("category_removed", String.valueOf(listFeedbackOptions.categoryRemoved()));
}
if (listFeedbackOptions.categoryAdded() != null) {
builder.query("category_added", String.valueOf(listFeedbackOptions.categoryAdded()));
}
if (listFeedbackOptions.categoryNotChanged() != null) {
builder.query("category_not_changed", String.valueOf(listFeedbackOptions.categoryNotChanged()));
}
if (listFeedbackOptions.typeRemoved() != null) {
builder.query("type_removed", String.valueOf(listFeedbackOptions.typeRemoved()));
}
if (listFeedbackOptions.typeAdded() != null) {
builder.query("type_added", String.valueOf(listFeedbackOptions.typeAdded()));
}
if (listFeedbackOptions.typeNotChanged() != null) {
builder.query("type_not_changed", String.valueOf(listFeedbackOptions.typeNotChanged()));
}
if (listFeedbackOptions.pageLimit() != null) {
builder.query("page_limit", String.valueOf(listFeedbackOptions.pageLimit()));
}
if (listFeedbackOptions.cursor() != null) {
builder.query("cursor", String.valueOf(listFeedbackOptions.cursor()));
}
if (listFeedbackOptions.sort() != null) {
builder.query("sort", String.valueOf(listFeedbackOptions.sort()));
}
if (listFeedbackOptions.includeTotal() != null) {
builder.query("include_total", String.valueOf(listFeedbackOptions.includeTotal()));
}
ResponseConverter<FeedbackList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<FeedbackList>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class CompareComply method listBatches.
/**
* List submitted batch-processing jobs.
*
* <p>Lists batch-processing jobs submitted by users.
*
* @param listBatchesOptions the {@link ListBatchesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Batches}
*/
public ServiceCall<Batches> listBatches(ListBatchesOptions listBatchesOptions) {
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "listBatches");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
builder.query("version", String.valueOf(this.version));
ResponseConverter<Batches> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Batches>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations