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.
*
* 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 queryNoticesOptions the {@link QueryNoticesOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link QueryNoticesResponse}
*/
public ServiceCall<QueryNoticesResponse> queryNotices(QueryNoticesOptions queryNoticesOptions) {
Validator.notNull(queryNoticesOptions, "queryNoticesOptions cannot be null");
String[] pathSegments = { "v1/environments", "collections", "notices" };
String[] pathParameters = { queryNoticesOptions.environmentId(), queryNoticesOptions.collectionId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (queryNoticesOptions.filter() != null) {
builder.query("filter", queryNoticesOptions.filter());
}
if (queryNoticesOptions.query() != null) {
builder.query("query", queryNoticesOptions.query());
}
if (queryNoticesOptions.naturalLanguageQuery() != null) {
builder.query("natural_language_query", queryNoticesOptions.naturalLanguageQuery());
}
if (queryNoticesOptions.passages() != null) {
builder.query("passages", String.valueOf(queryNoticesOptions.passages()));
}
if (queryNoticesOptions.aggregation() != null) {
builder.query("aggregation", queryNoticesOptions.aggregation());
}
if (queryNoticesOptions.count() != null) {
builder.query("count", String.valueOf(queryNoticesOptions.count()));
}
if (queryNoticesOptions.returnFields() != null) {
builder.query("return_fields", RequestUtils.join(queryNoticesOptions.returnFields(), ","));
}
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", 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(), ","));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(QueryNoticesResponse.class));
}
use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse 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")), ","));
}
use of com.ibm.watson.discovery.v1.model.QueryNoticesResponse 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