use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method queryNoticesIsSuccessful.
@Test
public void queryNoticesIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(queryNoticesResp));
QueryNoticesOptions.Builder builder = new QueryNoticesOptions.Builder(environmentId, collectionId);
QueryNoticesResponse response = discoveryService.queryNotices(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(Q5_PATH, request.getPath());
assertEquals(GET, request.getMethod());
}
use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method federatedQueryNoticesIsSuccessful.
@Test
public void federatedQueryNoticesIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(queryNoticesResp));
FederatedQueryNoticesOptions.Builder builder = new FederatedQueryNoticesOptions.Builder(environmentId, new ArrayList<>(Arrays.asList(collectionId)));
QueryNoticesResponse response = discoveryService.federatedQueryNotices(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(Q4_PATH, request.getPath());
assertEquals(GET, request.getMethod());
}
use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse 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")), ","));
}
use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse 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);
}
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.
*
* <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);
}
Aggregations