Search in sources :

Example 1 with QueryNoticesOptions

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

the class DiscoveryTest method testQueryNoticesWOptions.

// Test the queryNotices operation with a valid options model parameter
@Test
public void testQueryNoticesWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"matching_results\": 15, \"results\": [{\"id\": \"id\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"collection_id\": \"collectionId\", \"result_metadata\": {\"score\": 5, \"confidence\": 10}, \"code\": 4, \"filename\": \"filename\", \"file_type\": \"pdf\", \"sha1\": \"sha1\", \"notices\": [{\"notice_id\": \"noticeId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"document_id\": \"documentId\", \"query_id\": \"queryId\", \"severity\": \"warning\", \"step\": \"step\", \"description\": \"description\"}]}], \"aggregations\": [{\"type\": \"filter\", \"match\": \"match\", \"matching_results\": 15}], \"passages\": [{\"document_id\": \"documentId\", \"passage_score\": 12, \"passage_text\": \"passageText\", \"start_offset\": 11, \"end_offset\": 9, \"field\": \"field\"}], \"duplicates_removed\": 17}";
    String queryNoticesPath = "/v1/environments/testString/collections/testString/notices";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the QueryNoticesOptions model
    QueryNoticesOptions queryNoticesOptionsModel = new QueryNoticesOptions.Builder().environmentId("testString").collectionId("testString").filter("testString").query("testString").naturalLanguageQuery("testString").passages(true).aggregation("testString").count(Long.valueOf("26")).xReturn(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).offset(Long.valueOf("26")).sort(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).highlight(false).passagesFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).passagesCount(Long.valueOf("100")).passagesCharacters(Long.valueOf("50")).deduplicateField("testString").similar(false).similarDocumentIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).similarFields(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Invoke queryNotices() with a valid options model and verify the result
    Response<QueryNoticesResponse> response = discoveryService.queryNotices(queryNoticesOptionsModel).execute();
    assertNotNull(response);
    QueryNoticesResponse responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, queryNoticesPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("filter"), "testString");
    assertEquals(query.get("query"), "testString");
    assertEquals(query.get("natural_language_query"), "testString");
    assertEquals(Boolean.valueOf(query.get("passages")), Boolean.valueOf(true));
    assertEquals(query.get("aggregation"), "testString");
    assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
    assertEquals(query.get("return"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
    assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("26"));
    assertEquals(query.get("sort"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
    assertEquals(Boolean.valueOf(query.get("highlight")), Boolean.valueOf(false));
    assertEquals(query.get("passages.fields"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
    assertEquals(Long.valueOf(query.get("passages.count")), Long.valueOf("100"));
    assertEquals(Long.valueOf(query.get("passages.characters")), Long.valueOf("50"));
    assertEquals(query.get("deduplicate.field"), "testString");
    assertEquals(Boolean.valueOf(query.get("similar")), Boolean.valueOf(false));
    assertEquals(query.get("similar.document_ids"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
    assertEquals(query.get("similar.fields"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) QueryNoticesResponse(com.ibm.watson.discovery.v1.model.QueryNoticesResponse) FederatedQueryNoticesOptions(com.ibm.watson.discovery.v1.model.FederatedQueryNoticesOptions) QueryNoticesOptions(com.ibm.watson.discovery.v1.model.QueryNoticesOptions) Test(org.testng.annotations.Test)

Example 2 with QueryNoticesOptions

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

the class Discovery method queryNotices.

/**
 * Query system notices.
 *
 * <p>Queries for notices (errors or warnings) that might have been generated by the system.
 * Notices are generated when ingesting documents and performing relevance training. See the
 * [Discovery
 * documentation](https://cloud.ibm.com/docs/discovery?topic=discovery-query-concepts#query-concepts)
 * for more details on the query language.
 *
 * @param queryNoticesOptions the {@link QueryNoticesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link QueryNoticesResponse}
 */
public ServiceCall<QueryNoticesResponse> queryNotices(QueryNoticesOptions queryNoticesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(queryNoticesOptions, "queryNoticesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", queryNoticesOptions.environmentId());
    pathParamsMap.put("collection_id", queryNoticesOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/notices", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "queryNotices");
    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 (queryNoticesOptions.filter() != null) {
        builder.query("filter", String.valueOf(queryNoticesOptions.filter()));
    }
    if (queryNoticesOptions.query() != null) {
        builder.query("query", String.valueOf(queryNoticesOptions.query()));
    }
    if (queryNoticesOptions.naturalLanguageQuery() != null) {
        builder.query("natural_language_query", String.valueOf(queryNoticesOptions.naturalLanguageQuery()));
    }
    if (queryNoticesOptions.passages() != null) {
        builder.query("passages", String.valueOf(queryNoticesOptions.passages()));
    }
    if (queryNoticesOptions.aggregation() != null) {
        builder.query("aggregation", String.valueOf(queryNoticesOptions.aggregation()));
    }
    if (queryNoticesOptions.count() != null) {
        builder.query("count", String.valueOf(queryNoticesOptions.count()));
    }
    if (queryNoticesOptions.xReturn() != null) {
        builder.query("return", RequestUtils.join(queryNoticesOptions.xReturn(), ","));
    }
    if (queryNoticesOptions.offset() != null) {
        builder.query("offset", String.valueOf(queryNoticesOptions.offset()));
    }
    if (queryNoticesOptions.sort() != null) {
        builder.query("sort", RequestUtils.join(queryNoticesOptions.sort(), ","));
    }
    if (queryNoticesOptions.highlight() != null) {
        builder.query("highlight", String.valueOf(queryNoticesOptions.highlight()));
    }
    if (queryNoticesOptions.passagesFields() != null) {
        builder.query("passages.fields", RequestUtils.join(queryNoticesOptions.passagesFields(), ","));
    }
    if (queryNoticesOptions.passagesCount() != null) {
        builder.query("passages.count", String.valueOf(queryNoticesOptions.passagesCount()));
    }
    if (queryNoticesOptions.passagesCharacters() != null) {
        builder.query("passages.characters", String.valueOf(queryNoticesOptions.passagesCharacters()));
    }
    if (queryNoticesOptions.deduplicateField() != null) {
        builder.query("deduplicate.field", String.valueOf(queryNoticesOptions.deduplicateField()));
    }
    if (queryNoticesOptions.similar() != null) {
        builder.query("similar", String.valueOf(queryNoticesOptions.similar()));
    }
    if (queryNoticesOptions.similarDocumentIds() != null) {
        builder.query("similar.document_ids", RequestUtils.join(queryNoticesOptions.similarDocumentIds(), ","));
    }
    if (queryNoticesOptions.similarFields() != null) {
        builder.query("similar.fields", RequestUtils.join(queryNoticesOptions.similarFields(), ","));
    }
    ResponseConverter<QueryNoticesResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryNoticesResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) QueryNoticesResponse(com.ibm.watson.discovery.v1.model.QueryNoticesResponse)

Example 3 with QueryNoticesOptions

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

the class DiscoveryTest method testQueryNoticesWOptions.

@Test
public void testQueryNoticesWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"matching_results\": 15, \"notices\": [{\"notice_id\": \"noticeId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"document_id\": \"documentId\", \"collection_id\": \"collectionId\", \"query_id\": \"queryId\", \"severity\": \"warning\", \"step\": \"step\", \"description\": \"description\"}]}";
    String queryNoticesPath = "/v2/projects/testString/notices";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the QueryNoticesOptions model
    QueryNoticesOptions queryNoticesOptionsModel = new QueryNoticesOptions.Builder().projectId("testString").filter("testString").query("testString").naturalLanguageQuery("testString").count(Long.valueOf("26")).offset(Long.valueOf("26")).build();
    // Invoke operation with valid options model (positive test)
    Response<QueryNoticesResponse> response = discoveryService.queryNotices(queryNoticesOptionsModel).execute();
    assertNotNull(response);
    QueryNoticesResponse 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("filter"), "testString");
    assertEquals(query.get("query"), "testString");
    assertEquals(query.get("natural_language_query"), "testString");
    assertEquals(Long.valueOf(query.get("count")), Long.valueOf("26"));
    assertEquals(Long.valueOf(query.get("offset")), Long.valueOf("26"));
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, queryNoticesPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) QueryNoticesResponse(com.ibm.watson.discovery.v2.model.QueryNoticesResponse) QueryNoticesOptions(com.ibm.watson.discovery.v2.model.QueryNoticesOptions) Test(org.testng.annotations.Test)

Aggregations

QueryNoticesResponse (com.ibm.watson.discovery.v1.model.QueryNoticesResponse)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.testng.annotations.Test)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 FederatedQueryNoticesOptions (com.ibm.watson.discovery.v1.model.FederatedQueryNoticesOptions)1 QueryNoticesOptions (com.ibm.watson.discovery.v1.model.QueryNoticesOptions)1 QueryNoticesOptions (com.ibm.watson.discovery.v2.model.QueryNoticesOptions)1 QueryNoticesResponse (com.ibm.watson.discovery.v2.model.QueryNoticesResponse)1 HashMap (java.util.HashMap)1