Skip to content

Commit 8fe491a

Browse files
committed
refactor: Modify constructors in service classes
1 parent a677485 commit 8fe491a

14 files changed

Lines changed: 532 additions & 259 deletions

File tree

‎assistant/src/main/java/com/ibm/watson/assistant/v1/Assistant.java‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019.
2+
* (C) Copyright IBM Corp. 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -99,36 +99,61 @@
9999
*/
100100
public class Assistant extends BaseService {
101101

102-
private static final String SERVICE_NAME = "assistant";
103-
private static final String SERVICE_URL = "https://gateway.watsonplatform.net/assistant/api";
102+
private static final String DEFAULT_SERVICE_NAME = "conversation";
103+
104+
private static final String DEFAULT_SERVICE_URL = "https://gateway.watsonplatform.net/assistant/api";
104105

105106
private String versionDate;
106107

107108
/**
108-
* Constructs a new `Assistant` client.
109+
* Constructs a new `Assistant` client using the DEFAULT_SERVICE_NAME.
109110
*
110111
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
111112
* calls from failing when the service introduces breaking changes.
112113
*/
113114
public Assistant(String versionDate) {
114-
this(versionDate, ConfigBasedAuthenticatorFactory.getAuthenticator(SERVICE_NAME));
115+
this(versionDate, DEFAULT_SERVICE_NAME, ConfigBasedAuthenticatorFactory.getAuthenticator(DEFAULT_SERVICE_NAME));
115116
}
116117

117118
/**
118-
* Constructs a new `Assistant` client with the specified Authenticator.
119+
* Constructs a new `Assistant` client with the DEFAULT_SERVICE_NAME
120+
* and the specified Authenticator.
119121
*
120122
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
121123
* calls from failing when the service introduces breaking changes.
122124
* @param authenticator the Authenticator instance to be configured for this service
123125
*/
124126
public Assistant(String versionDate, Authenticator authenticator) {
125-
super(SERVICE_NAME, authenticator);
126-
if ((getServiceUrl() == null) || getServiceUrl().isEmpty()) {
127-
setServiceUrl(SERVICE_URL);
128-
}
127+
this(versionDate, DEFAULT_SERVICE_NAME, authenticator);
128+
}
129+
130+
/**
131+
* Constructs a new `Assistant` client with the specified serviceName.
132+
*
133+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
134+
* calls from failing when the service introduces breaking changes.
135+
* @param serviceName The name of the service to configure.
136+
*/
137+
public Assistant(String versionDate, String serviceName) {
138+
this(versionDate, serviceName, ConfigBasedAuthenticatorFactory.getAuthenticator(serviceName));
139+
}
140+
141+
/**
142+
* Constructs a new `Assistant` client with the specified Authenticator
143+
* and serviceName.
144+
*
145+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
146+
* calls from failing when the service introduces breaking changes.
147+
* @param serviceName The name of the service to configure.
148+
* @param authenticator the Authenticator instance to be configured for this service
149+
*/
150+
public Assistant(String versionDate, String serviceName, Authenticator authenticator) {
151+
super(serviceName, authenticator);
152+
setServiceUrl(DEFAULT_SERVICE_URL);
129153
com.ibm.cloud.sdk.core.util.Validator.isTrue((versionDate != null) && !versionDate.isEmpty(),
130154
"version cannot be null.");
131155
this.versionDate = versionDate;
156+
this.configureService(serviceName);
132157
}
133158

134159
/**
@@ -2039,6 +2064,8 @@ public ServiceCall<LogCollection> listAllLogs(ListAllLogsOptions listAllLogsOpti
20392064
* For more information about personal data and customer IDs, see [Information
20402065
* security](https://cloud.ibm.com/docs/services/assistant?topic=assistant-information-security#information-security).
20412066
*
2067+
* This operation is limited to 4 requests per minute. For more information, see **Rate limiting**.
2068+
*
20422069
* @param deleteUserDataOptions the {@link DeleteUserDataOptions} containing the options for the call
20432070
* @return a {@link ServiceCall} with a response type of Void
20442071
*/

‎assistant/src/main/java/com/ibm/watson/assistant/v2/Assistant.java‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019.
2+
* (C) Copyright IBM Corp. 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -41,36 +41,61 @@
4141
*/
4242
public class Assistant extends BaseService {
4343

44-
private static final String SERVICE_NAME = "assistant";
45-
private static final String SERVICE_URL = "https://gateway.watsonplatform.net/assistant/api";
44+
private static final String DEFAULT_SERVICE_NAME = "conversation";
45+
46+
private static final String DEFAULT_SERVICE_URL = "https://gateway.watsonplatform.net/assistant/api";
4647

4748
private String versionDate;
4849

4950
/**
50-
* Constructs a new `Assistant` client.
51+
* Constructs a new `Assistant` client using the DEFAULT_SERVICE_NAME.
5152
*
5253
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
5354
* calls from failing when the service introduces breaking changes.
5455
*/
5556
public Assistant(String versionDate) {
56-
this(versionDate, ConfigBasedAuthenticatorFactory.getAuthenticator(SERVICE_NAME));
57+
this(versionDate, DEFAULT_SERVICE_NAME, ConfigBasedAuthenticatorFactory.getAuthenticator(DEFAULT_SERVICE_NAME));
5758
}
5859

5960
/**
60-
* Constructs a new `Assistant` client with the specified Authenticator.
61+
* Constructs a new `Assistant` client with the DEFAULT_SERVICE_NAME
62+
* and the specified Authenticator.
6163
*
6264
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
6365
* calls from failing when the service introduces breaking changes.
6466
* @param authenticator the Authenticator instance to be configured for this service
6567
*/
6668
public Assistant(String versionDate, Authenticator authenticator) {
67-
super(SERVICE_NAME, authenticator);
68-
if ((getServiceUrl() == null) || getServiceUrl().isEmpty()) {
69-
setServiceUrl(SERVICE_URL);
70-
}
69+
this(versionDate, DEFAULT_SERVICE_NAME, authenticator);
70+
}
71+
72+
/**
73+
* Constructs a new `Assistant` client with the specified serviceName.
74+
*
75+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
76+
* calls from failing when the service introduces breaking changes.
77+
* @param serviceName The name of the service to configure.
78+
*/
79+
public Assistant(String versionDate, String serviceName) {
80+
this(versionDate, serviceName, ConfigBasedAuthenticatorFactory.getAuthenticator(serviceName));
81+
}
82+
83+
/**
84+
* Constructs a new `Assistant` client with the specified Authenticator
85+
* and serviceName.
86+
*
87+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
88+
* calls from failing when the service introduces breaking changes.
89+
* @param serviceName The name of the service to configure.
90+
* @param authenticator the Authenticator instance to be configured for this service
91+
*/
92+
public Assistant(String versionDate, String serviceName, Authenticator authenticator) {
93+
super(serviceName, authenticator);
94+
setServiceUrl(DEFAULT_SERVICE_URL);
7195
com.ibm.cloud.sdk.core.util.Validator.isTrue((versionDate != null) && !versionDate.isEmpty(),
7296
"version cannot be null.");
7397
this.versionDate = versionDate;
98+
this.configureService(serviceName);
7499
}
75100

76101
/**

‎compare-comply/src/main/java/com/ibm/watson/compare_comply/v1/CompareComply.java‎

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019.
2+
* (C) Copyright IBM Corp. 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -57,36 +57,61 @@
5757
*/
5858
public class CompareComply extends BaseService {
5959

60-
private static final String SERVICE_NAME = "compare_comply";
61-
private static final String SERVICE_URL = "https://gateway.watsonplatform.net/compare-comply/api";
60+
private static final String DEFAULT_SERVICE_NAME = "compare-comply";
61+
62+
private static final String DEFAULT_SERVICE_URL = "https://gateway.watsonplatform.net/compare-comply/api";
6263

6364
private String versionDate;
6465

6566
/**
66-
* Constructs a new `CompareComply` client.
67+
* Constructs a new `CompareComply` client using the DEFAULT_SERVICE_NAME.
6768
*
6869
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
6970
* calls from failing when the service introduces breaking changes.
7071
*/
7172
public CompareComply(String versionDate) {
72-
this(versionDate, ConfigBasedAuthenticatorFactory.getAuthenticator(SERVICE_NAME));
73+
this(versionDate, DEFAULT_SERVICE_NAME, ConfigBasedAuthenticatorFactory.getAuthenticator(DEFAULT_SERVICE_NAME));
7374
}
7475

7576
/**
76-
* Constructs a new `CompareComply` client with the specified Authenticator.
77+
* Constructs a new `CompareComply` client with the DEFAULT_SERVICE_NAME
78+
* and the specified Authenticator.
7779
*
7880
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
7981
* calls from failing when the service introduces breaking changes.
8082
* @param authenticator the Authenticator instance to be configured for this service
8183
*/
8284
public CompareComply(String versionDate, Authenticator authenticator) {
83-
super(SERVICE_NAME, authenticator);
84-
if ((getServiceUrl() == null) || getServiceUrl().isEmpty()) {
85-
setServiceUrl(SERVICE_URL);
86-
}
85+
this(versionDate, DEFAULT_SERVICE_NAME, authenticator);
86+
}
87+
88+
/**
89+
* Constructs a new `CompareComply` client with the specified serviceName.
90+
*
91+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
92+
* calls from failing when the service introduces breaking changes.
93+
* @param serviceName The name of the service to configure.
94+
*/
95+
public CompareComply(String versionDate, String serviceName) {
96+
this(versionDate, serviceName, ConfigBasedAuthenticatorFactory.getAuthenticator(serviceName));
97+
}
98+
99+
/**
100+
* Constructs a new `CompareComply` client with the specified Authenticator
101+
* and serviceName.
102+
*
103+
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
104+
* calls from failing when the service introduces breaking changes.
105+
* @param serviceName The name of the service to configure.
106+
* @param authenticator the Authenticator instance to be configured for this service
107+
*/
108+
public CompareComply(String versionDate, String serviceName, Authenticator authenticator) {
109+
super(serviceName, authenticator);
110+
setServiceUrl(DEFAULT_SERVICE_URL);
87111
com.ibm.cloud.sdk.core.util.Validator.isTrue((versionDate != null) && !versionDate.isEmpty(),
88112
"version cannot be null.");
89113
this.versionDate = versionDate;
114+
this.configureService(serviceName);
90115
}
91116

92117
/**

‎discovery/src/main/java/com/ibm/watson/discovery/v1/Discovery.java‎

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* (C) Copyright IBM Corp. 2019.
2+
* (C) Copyright IBM Corp. 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
55
* the License. You may obtain a copy of the License at
@@ -131,36 +131,61 @@
131131
*/
132132
public class Discovery extends BaseService {
133133

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";
136137

137138
private String versionDate;
138139

139140
/**
140-
* Constructs a new `Discovery` client.
141+
* Constructs a new `Discovery` client using the DEFAULT_SERVICE_NAME.
141142
*
142143
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
143144
* calls from failing when the service introduces breaking changes.
144145
*/
145146
public Discovery(String versionDate) {
146-
this(versionDate, ConfigBasedAuthenticatorFactory.getAuthenticator(SERVICE_NAME));
147+
this(versionDate, DEFAULT_SERVICE_NAME, ConfigBasedAuthenticatorFactory.getAuthenticator(DEFAULT_SERVICE_NAME));
147148
}
148149

149150
/**
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.
151153
*
152154
* @param versionDate The version date (yyyy-MM-dd) of the REST API to use. Specifying this value will keep your API
153155
* calls from failing when the service introduces breaking changes.
154156
* @param authenticator the Authenticator instance to be configured for this service
155157
*/
156158
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);
161185
com.ibm.cloud.sdk.core.util.Validator.isTrue((versionDate != null) && !versionDate.isEmpty(),
162186
"version cannot be null.");
163187
this.versionDate = versionDate;
188+
this.configureService(serviceName);
164189
}
165190

166191
/**
@@ -674,9 +699,7 @@ public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCo
674699
}
675700
builder.header("Accept", "application/json");
676701
final JsonObject contentJson = new JsonObject();
677-
if (updateCollectionOptions.name() != null) {
678-
contentJson.addProperty("name", updateCollectionOptions.name());
679-
}
702+
contentJson.addProperty("name", updateCollectionOptions.name());
680703
if (updateCollectionOptions.description() != null) {
681704
contentJson.addProperty("description", updateCollectionOptions.description());
682705
}
@@ -1385,6 +1408,7 @@ public ServiceCall<QueryResponse> federatedQuery(FederatedQueryOptions federated
13851408
builder.header("X-Watson-Logging-Opt-Out", federatedQueryOptions.xWatsonLoggingOptOut());
13861409
}
13871410
final JsonObject contentJson = new JsonObject();
1411+
contentJson.addProperty("collection_ids", federatedQueryOptions.collectionIds());
13881412
if (federatedQueryOptions.filter() != null) {
13891413
contentJson.addProperty("filter", federatedQueryOptions.filter());
13901414
}
@@ -1442,9 +1466,6 @@ public ServiceCall<QueryResponse> federatedQuery(FederatedQueryOptions federated
14421466
if (federatedQueryOptions.bias() != null) {
14431467
contentJson.addProperty("bias", federatedQueryOptions.bias());
14441468
}
1445-
if (federatedQueryOptions.collectionIds() != null) {
1446-
contentJson.addProperty("collection_ids", federatedQueryOptions.collectionIds());
1447-
}
14481469
builder.bodyJson(contentJson);
14491470
ResponseConverter<QueryResponse> responseConverter = ResponseConverterUtils.getValue(
14501471
new com.google.gson.reflect.TypeToken<QueryResponse>() {
@@ -1898,7 +1919,7 @@ public ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOpti
18981919
* Create event.
18991920
*
19001921
* 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.
19021923
*
19031924
* @param createEventOptions the {@link CreateEventOptions} containing the options for the call
19041925
* @return a {@link ServiceCall} with a response type of {@link CreateEventResponse}

0 commit comments

Comments
 (0)