Search in sources :

Example 51 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject)

Example 52 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) CompareReturn(com.ibm.watson.compare_comply.v1.model.CompareReturn)

Example 53 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus)

Example 54 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) FeedbackList(com.ibm.watson.compare_comply.v1.model.FeedbackList)

Example 55 with RequestBuilder

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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Batches(com.ibm.watson.compare_comply.v1.model.Batches)

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