|
1 | 1 | /* |
2 | | - * (C) Copyright IBM Corp. 2019. |
| 2 | + * (C) Copyright IBM Corp. 2020. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
5 | 5 | * the License. You may obtain a copy of the License at |
|
131 | 131 | */ |
132 | 132 | public class Discovery extends BaseService { |
133 | 133 |
|
134 | | - private static final String SERVICE_NAME = "discovery"; |
135 | | - private static final String SERVICE_URL = "https://gateway.watsonplatform.net/discovery/api"; |
| 134 | + private static final String DEFAULT_SERVICE_NAME = "discovery"; |
| 135 | + |
| 136 | + private static final String DEFAULT_SERVICE_URL = "https://gateway.watsonplatform.net/discovery/api"; |
136 | 137 |
|
137 | 138 | private String versionDate; |
138 | 139 |
|
139 | 140 | /** |
140 | | - * Constructs a new `Discovery` client. |
| 141 | + * Constructs a new `Discovery` client using the DEFAULT_SERVICE_NAME. |
141 | 142 | * |
142 | 143 | * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API |
143 | 144 | * calls from failing when the service introduces breaking changes. |
144 | 145 | */ |
145 | 146 | public Discovery(String versionDate) { |
146 | | - this(versionDate, ConfigBasedAuthenticatorFactory.getAuthenticator(SERVICE_NAME)); |
| 147 | + this(versionDate, DEFAULT_SERVICE_NAME, ConfigBasedAuthenticatorFactory.getAuthenticator(DEFAULT_SERVICE_NAME)); |
147 | 148 | } |
148 | 149 |
|
149 | 150 | /** |
150 | | - * Constructs a new `Discovery` client with the specified Authenticator. |
| 151 | + * Constructs a new `Discovery` client with the DEFAULT_SERVICE_NAME |
| 152 | + * and the specified Authenticator. |
151 | 153 | * |
152 | 154 | * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API |
153 | 155 | * calls from failing when the service introduces breaking changes. |
154 | 156 | * @param authenticator the Authenticator instance to be configured for this service |
155 | 157 | */ |
156 | 158 | public Discovery(String versionDate, Authenticator authenticator) { |
157 | | - super(SERVICE_NAME, authenticator); |
158 | | - if ((getServiceUrl() == null) || getServiceUrl().isEmpty()) { |
159 | | - setServiceUrl(SERVICE_URL); |
160 | | - } |
| 159 | + this(versionDate, DEFAULT_SERVICE_NAME, authenticator); |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * Constructs a new `Discovery` client with the specified serviceName. |
| 164 | + * |
| 165 | + * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API |
| 166 | + * calls from failing when the service introduces breaking changes. |
| 167 | + * @param serviceName The name of the service to configure. |
| 168 | + */ |
| 169 | + public Discovery(String versionDate, String serviceName) { |
| 170 | + this(versionDate, serviceName, ConfigBasedAuthenticatorFactory.getAuthenticator(serviceName)); |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Constructs a new `Discovery` client with the specified Authenticator |
| 175 | + * and serviceName. |
| 176 | + * |
| 177 | + * @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API |
| 178 | + * calls from failing when the service introduces breaking changes. |
| 179 | + * @param serviceName The name of the service to configure. |
| 180 | + * @param authenticator the Authenticator instance to be configured for this service |
| 181 | + */ |
| 182 | + public Discovery(String versionDate, String serviceName, Authenticator authenticator) { |
| 183 | + super(serviceName, authenticator); |
| 184 | + setServiceUrl(DEFAULT_SERVICE_URL); |
161 | 185 | com.ibm.cloud.sdk.core.util.Validator.isTrue((versionDate != null) && !versionDate.isEmpty(), |
162 | 186 | "version cannot be null."); |
163 | 187 | this.versionDate = versionDate; |
| 188 | + this.configureService(serviceName); |
164 | 189 | } |
165 | 190 |
|
166 | 191 | /** |
@@ -674,9 +699,7 @@ public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCo |
674 | 699 | } |
675 | 700 | builder.header("Accept", "application/json"); |
676 | 701 | final JsonObject contentJson = new JsonObject(); |
677 | | - if (updateCollectionOptions.name() != null) { |
678 | | - contentJson.addProperty("name", updateCollectionOptions.name()); |
679 | | - } |
| 702 | + contentJson.addProperty("name", updateCollectionOptions.name()); |
680 | 703 | if (updateCollectionOptions.description() != null) { |
681 | 704 | contentJson.addProperty("description", updateCollectionOptions.description()); |
682 | 705 | } |
@@ -1385,6 +1408,7 @@ public ServiceCall<QueryResponse> federatedQuery(FederatedQueryOptions federated |
1385 | 1408 | builder.header("X-Watson-Logging-Opt-Out", federatedQueryOptions.xWatsonLoggingOptOut()); |
1386 | 1409 | } |
1387 | 1410 | final JsonObject contentJson = new JsonObject(); |
| 1411 | + contentJson.addProperty("collection_ids", federatedQueryOptions.collectionIds()); |
1388 | 1412 | if (federatedQueryOptions.filter() != null) { |
1389 | 1413 | contentJson.addProperty("filter", federatedQueryOptions.filter()); |
1390 | 1414 | } |
@@ -1442,9 +1466,6 @@ public ServiceCall<QueryResponse> federatedQuery(FederatedQueryOptions federated |
1442 | 1466 | if (federatedQueryOptions.bias() != null) { |
1443 | 1467 | contentJson.addProperty("bias", federatedQueryOptions.bias()); |
1444 | 1468 | } |
1445 | | - if (federatedQueryOptions.collectionIds() != null) { |
1446 | | - contentJson.addProperty("collection_ids", federatedQueryOptions.collectionIds()); |
1447 | | - } |
1448 | 1469 | builder.bodyJson(contentJson); |
1449 | 1470 | ResponseConverter<QueryResponse> responseConverter = ResponseConverterUtils.getValue( |
1450 | 1471 | new com.google.gson.reflect.TypeToken<QueryResponse>() { |
@@ -1898,7 +1919,7 @@ public ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOpti |
1898 | 1919 | * Create event. |
1899 | 1920 | * |
1900 | 1921 | * The **Events** API can be used to create log entries that are associated with specific queries. For example, you |
1901 | | - * can record which documents in the results set were "clicked" by a user and when that click occured. |
| 1922 | + * can record which documents in the results set were "clicked" by a user and when that click occurred. |
1902 | 1923 | * |
1903 | 1924 | * @param createEventOptions the {@link CreateEventOptions} containing the options for the call |
1904 | 1925 | * @return a {@link ServiceCall} with a response type of {@link CreateEventResponse} |
|
0 commit comments