Search in sources :

Example 6 with QueryNoticesResponse

use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse 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)

Example 7 with QueryNoticesResponse

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

the class DiscoveryTest method testQueryCollectionNoticesWOptions.

@Test
public void testQueryCollectionNoticesWOptions() 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 queryCollectionNoticesPath = "/v2/projects/testString/collections/testString/notices";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the QueryCollectionNoticesOptions model
    QueryCollectionNoticesOptions queryCollectionNoticesOptionsModel = new QueryCollectionNoticesOptions.Builder().projectId("testString").collectionId("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.queryCollectionNotices(queryCollectionNoticesOptionsModel).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, queryCollectionNoticesPath);
}
Also used : QueryCollectionNoticesOptions(com.ibm.watson.discovery.v2.model.QueryCollectionNoticesOptions) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) QueryNoticesResponse(com.ibm.watson.discovery.v2.model.QueryNoticesResponse) Test(org.testng.annotations.Test)

Example 8 with QueryNoticesResponse

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

the class Discovery method queryNotices.

/**
 * Query project notices.
 *
 * <p>Finds project-level notices (errors and warnings). Currently, project-level notices are
 * generated by relevancy training.
 *
 * @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("project_id", queryNoticesOptions.projectId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/notices", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "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.count() != null) {
        builder.query("count", String.valueOf(queryNoticesOptions.count()));
    }
    if (queryNoticesOptions.offset() != null) {
        builder.query("offset", String.valueOf(queryNoticesOptions.offset()));
    }
    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.v2.model.QueryNoticesResponse)

Example 9 with QueryNoticesResponse

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

the class DiscoveryServiceIT method queryNoticesCountIsSuccessful.

// queryNotices tests
@Test
public void queryNoticesCountIsSuccessful() {
    String collectionId = setupTestDocuments();
    QueryNoticesOptions.Builder queryBuilder = new QueryNoticesOptions.Builder(environmentId, collectionId);
    queryBuilder.count(5L);
    QueryNoticesResponse queryResponse = discovery.queryNotices(queryBuilder.build()).execute();
    assertTrue(queryResponse.getResults().size() <= 5);
}
Also used : QueryNoticesResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesResponse) QueryNoticesOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 10 with QueryNoticesResponse

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

the class Discovery method federatedQueryNotices.

/**
 * Query multiple collection system notices.
 *
 * 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 service
 * documentation](https://console.bluemix.net/docs/services/discovery/using.html) for more details on the query
 * language.
 *
 * @param federatedQueryNoticesOptions the {@link FederatedQueryNoticesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link QueryNoticesResponse}
 */
public ServiceCall<QueryNoticesResponse> federatedQueryNotices(FederatedQueryNoticesOptions federatedQueryNoticesOptions) {
    Validator.notNull(federatedQueryNoticesOptions, "federatedQueryNoticesOptions cannot be null");
    String[] pathSegments = { "v1/environments", "notices" };
    String[] pathParameters = { federatedQueryNoticesOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    builder.query("collection_ids", RequestUtils.join(federatedQueryNoticesOptions.collectionIds(), ","));
    if (federatedQueryNoticesOptions.filter() != null) {
        builder.query("filter", federatedQueryNoticesOptions.filter());
    }
    if (federatedQueryNoticesOptions.query() != null) {
        builder.query("query", federatedQueryNoticesOptions.query());
    }
    if (federatedQueryNoticesOptions.naturalLanguageQuery() != null) {
        builder.query("natural_language_query", federatedQueryNoticesOptions.naturalLanguageQuery());
    }
    if (federatedQueryNoticesOptions.aggregation() != null) {
        builder.query("aggregation", federatedQueryNoticesOptions.aggregation());
    }
    if (federatedQueryNoticesOptions.count() != null) {
        builder.query("count", String.valueOf(federatedQueryNoticesOptions.count()));
    }
    if (federatedQueryNoticesOptions.returnFields() != null) {
        builder.query("return_fields", RequestUtils.join(federatedQueryNoticesOptions.returnFields(), ","));
    }
    if (federatedQueryNoticesOptions.offset() != null) {
        builder.query("offset", String.valueOf(federatedQueryNoticesOptions.offset()));
    }
    if (federatedQueryNoticesOptions.sort() != null) {
        builder.query("sort", RequestUtils.join(federatedQueryNoticesOptions.sort(), ","));
    }
    if (federatedQueryNoticesOptions.highlight() != null) {
        builder.query("highlight", String.valueOf(federatedQueryNoticesOptions.highlight()));
    }
    if (federatedQueryNoticesOptions.deduplicateField() != null) {
        builder.query("deduplicate.field", federatedQueryNoticesOptions.deduplicateField());
    }
    if (federatedQueryNoticesOptions.similar() != null) {
        builder.query("similar", String.valueOf(federatedQueryNoticesOptions.similar()));
    }
    if (federatedQueryNoticesOptions.similarDocumentIds() != null) {
        builder.query("similar.document_ids", RequestUtils.join(federatedQueryNoticesOptions.similarDocumentIds(), ","));
    }
    if (federatedQueryNoticesOptions.similarFields() != null) {
        builder.query("similar.fields", RequestUtils.join(federatedQueryNoticesOptions.similarFields(), ","));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryNoticesResponse.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) QueryNoticesResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesResponse)

Aggregations

RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 QueryNoticesResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesResponse)5 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 QueryNoticesResponse (com.ibm.watson.discovery.v1.model.QueryNoticesResponse)4 QueryNoticesResponse (com.ibm.watson.discovery.v2.model.QueryNoticesResponse)4 HashMap (java.util.HashMap)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 Test (org.testng.annotations.Test)4 Test (org.junit.Test)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 FederatedQueryNoticesOptions (com.ibm.watson.developer_cloud.discovery.v1.model.FederatedQueryNoticesOptions)2 QueryNoticesOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 FederatedQueryNoticesOptions (com.ibm.watson.discovery.v1.model.FederatedQueryNoticesOptions)2 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)1 QueryNoticesOptions (com.ibm.watson.discovery.v1.model.QueryNoticesOptions)1 QueryCollectionNoticesOptions (com.ibm.watson.discovery.v2.model.QueryCollectionNoticesOptions)1 QueryNoticesOptions (com.ibm.watson.discovery.v2.model.QueryNoticesOptions)1