Search in sources :

Example 1 with ListFeedbackOptions

use of com.ibm.watson.compare_comply.v1.model.ListFeedbackOptions 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 2 with ListFeedbackOptions

use of com.ibm.watson.compare_comply.v1.model.ListFeedbackOptions in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testListFeedbackWOptions.

@Test
public void testListFeedbackWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"feedback\": [{\"feedback_id\": \"feedbackId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"comment\": \"comment\", \"feedback_data\": {\"feedback_type\": \"feedbackType\", \"document\": {\"title\": \"title\", \"hash\": \"hash\"}, \"model_id\": \"modelId\", \"model_version\": \"modelVersion\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"original_labels\": {\"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}, \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}], \"categories\": [{\"label\": \"Amendments\", \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}]}, \"updated_labels\": {\"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}, \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}], \"categories\": [{\"label\": \"Amendments\", \"provenance_ids\": [\"provenanceIds\"], \"modification\": \"added\"}]}, \"pagination\": {\"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\", \"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5}}}]}";
    String listFeedbackPath = "/v1/feedback";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ListFeedbackOptions model
    ListFeedbackOptions listFeedbackOptionsModel = new ListFeedbackOptions.Builder().feedbackType("testString").documentTitle("testString").modelId("testString").modelVersion("testString").categoryRemoved("testString").categoryAdded("testString").categoryNotChanged("testString").typeRemoved("testString").typeAdded("testString").typeNotChanged("testString").pageLimit(Long.valueOf("100")).cursor("testString").sort("testString").includeTotal(true).build();
    // Invoke operation with valid options model (positive test)
    Response<FeedbackList> response = compareComplyService.listFeedback(listFeedbackOptionsModel).execute();
    assertNotNull(response);
    FeedbackList responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("feedback_type"), "testString");
    assertEquals(query.get("document_title"), "testString");
    assertEquals(query.get("model_id"), "testString");
    assertEquals(query.get("model_version"), "testString");
    assertEquals(query.get("category_removed"), "testString");
    assertEquals(query.get("category_added"), "testString");
    assertEquals(query.get("category_not_changed"), "testString");
    assertEquals(query.get("type_removed"), "testString");
    assertEquals(query.get("type_added"), "testString");
    assertEquals(query.get("type_not_changed"), "testString");
    assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("100"));
    assertEquals(query.get("cursor"), "testString");
    assertEquals(query.get("sort"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_total")), Boolean.valueOf(true));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, listFeedbackPath);
}
Also used : ListFeedbackOptions(com.ibm.watson.compare_comply.v1.model.ListFeedbackOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) FeedbackList(com.ibm.watson.compare_comply.v1.model.FeedbackList) Test(org.testng.annotations.Test)

Aggregations

FeedbackList (com.ibm.watson.compare_comply.v1.model.FeedbackList)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ListFeedbackOptions (com.ibm.watson.compare_comply.v1.model.ListFeedbackOptions)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Test (org.testng.annotations.Test)1