use of com.ibm.watson.discovery.v2.model.QueryCollectionNoticesOptions 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);
}
use of com.ibm.watson.discovery.v2.model.QueryCollectionNoticesOptions in project java-sdk by watson-developer-cloud.
the class Discovery method queryCollectionNotices.
/**
* Query collection notices.
*
* <p>Finds collection-level notices (errors and warnings) that are generated when documents are
* ingested.
*
* @param queryCollectionNoticesOptions the {@link QueryCollectionNoticesOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a result of type {@link QueryNoticesResponse}
*/
public ServiceCall<QueryNoticesResponse> queryCollectionNotices(QueryCollectionNoticesOptions queryCollectionNoticesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(queryCollectionNoticesOptions, "queryCollectionNoticesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("project_id", queryCollectionNoticesOptions.projectId());
pathParamsMap.put("collection_id", queryCollectionNoticesOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}/notices", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "queryCollectionNotices");
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 (queryCollectionNoticesOptions.filter() != null) {
builder.query("filter", String.valueOf(queryCollectionNoticesOptions.filter()));
}
if (queryCollectionNoticesOptions.query() != null) {
builder.query("query", String.valueOf(queryCollectionNoticesOptions.query()));
}
if (queryCollectionNoticesOptions.naturalLanguageQuery() != null) {
builder.query("natural_language_query", String.valueOf(queryCollectionNoticesOptions.naturalLanguageQuery()));
}
if (queryCollectionNoticesOptions.count() != null) {
builder.query("count", String.valueOf(queryCollectionNoticesOptions.count()));
}
if (queryCollectionNoticesOptions.offset() != null) {
builder.query("offset", String.valueOf(queryCollectionNoticesOptions.offset()));
}
ResponseConverter<QueryNoticesResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryNoticesResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations