use of com.ibm.watson.discovery.v1.model.FederatedQueryNoticesOptions in project java-sdk by watson-developer-cloud.
the class Discovery method federatedQueryNotices.
/**
* Query multiple collection 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 federatedQueryNoticesOptions the {@link FederatedQueryNoticesOptions} containing the
* options for the call
* @return a {@link ServiceCall} with a result of type {@link QueryNoticesResponse}
*/
public ServiceCall<QueryNoticesResponse> federatedQueryNotices(FederatedQueryNoticesOptions federatedQueryNoticesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(federatedQueryNoticesOptions, "federatedQueryNoticesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", federatedQueryNoticesOptions.environmentId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/notices", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "federatedQueryNotices");
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("collection_ids", RequestUtils.join(federatedQueryNoticesOptions.collectionIds(), ","));
if (federatedQueryNoticesOptions.filter() != null) {
builder.query("filter", String.valueOf(federatedQueryNoticesOptions.filter()));
}
if (federatedQueryNoticesOptions.query() != null) {
builder.query("query", String.valueOf(federatedQueryNoticesOptions.query()));
}
if (federatedQueryNoticesOptions.naturalLanguageQuery() != null) {
builder.query("natural_language_query", String.valueOf(federatedQueryNoticesOptions.naturalLanguageQuery()));
}
if (federatedQueryNoticesOptions.aggregation() != null) {
builder.query("aggregation", String.valueOf(federatedQueryNoticesOptions.aggregation()));
}
if (federatedQueryNoticesOptions.count() != null) {
builder.query("count", String.valueOf(federatedQueryNoticesOptions.count()));
}
if (federatedQueryNoticesOptions.xReturn() != null) {
builder.query("return", RequestUtils.join(federatedQueryNoticesOptions.xReturn(), ","));
}
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", String.valueOf(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(), ","));
}
ResponseConverter<QueryNoticesResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<QueryNoticesResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.FederatedQueryNoticesOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testFederatedQueryNoticesWOptions.
// Test the federatedQueryNotices operation with a valid options model parameter
@Test
public void testFederatedQueryNoticesWOptions() 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 federatedQueryNoticesPath = "/v1/environments/testString/notices";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the FederatedQueryNoticesOptions model
FederatedQueryNoticesOptions federatedQueryNoticesOptionsModel = new FederatedQueryNoticesOptions.Builder().environmentId("testString").collectionIds(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).filter("testString").query("testString").naturalLanguageQuery("testString").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).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 federatedQueryNotices() with a valid options model and verify the result
Response<QueryNoticesResponse> response = discoveryService.federatedQueryNotices(federatedQueryNoticesOptionsModel).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, federatedQueryNoticesPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(query.get("collection_ids"), RequestUtils.join(new java.util.ArrayList<String>(java.util.Arrays.asList("testString")), ","));
assertEquals(query.get("filter"), "testString");
assertEquals(query.get("query"), "testString");
assertEquals(query.get("natural_language_query"), "testString");
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("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")), ","));
}
Aggregations