14
14
15
15
package com .ibm .watson .developer_cloud .spring .boot ;
16
16
17
+ import com .ibm .watson .developer_cloud .assistant .v1 .Assistant ;
17
18
import com .ibm .watson .developer_cloud .conversation .v1 .Conversation ;
18
19
import com .ibm .watson .developer_cloud .discovery .v1 .Discovery ;
19
- import com .ibm .watson .developer_cloud .language_translator .v2 .LanguageTranslator ;
20
+ import com .ibm .watson .developer_cloud .language_translator .v3 .LanguageTranslator ;
20
21
import com .ibm .watson .developer_cloud .natural_language_classifier .v1 .NaturalLanguageClassifier ;
21
22
import com .ibm .watson .developer_cloud .natural_language_understanding .v1 .NaturalLanguageUnderstanding ;
22
23
import com .ibm .watson .developer_cloud .personality_insights .v3 .PersonalityInsights ;
23
24
import com .ibm .watson .developer_cloud .service .WatsonService ;
25
+ import com .ibm .watson .developer_cloud .service .security .IamOptions ;
24
26
import com .ibm .watson .developer_cloud .speech_to_text .v1 .SpeechToText ;
25
27
import com .ibm .watson .developer_cloud .text_to_speech .v1 .TextToSpeech ;
26
28
import com .ibm .watson .developer_cloud .tone_analyzer .v3 .ToneAnalyzer ;
34
36
35
37
@ Configuration
36
38
@ EnableConfigurationProperties ({
39
+ WatsonAssistantConfigurationProperties .class ,
37
40
WatsonConversationConfigurationProperties .class ,
38
41
WatsonDiscoveryConfigurationProperties .class ,
39
42
WatsonLanguageTranslatorConfigurationProperties .class ,
@@ -54,21 +57,41 @@ private void configUrl(WatsonService service, WatsonConfigurationProperties conf
54
57
}
55
58
}
56
59
57
- private void configBasicAuth (WatsonService service , WatsonConfigurationProperties config ) {
60
+ private void configAuth (WatsonService service , WatsonConfigurationProperties config ) {
61
+ String iamApiKey = config .getIamApiKey ();
62
+ if (iamApiKey != null ) {
63
+ IamOptions options = new IamOptions .Builder ().apiKey (iamApiKey ).build ();
64
+ service .setIamCredentials (options );
65
+ return ;
66
+ }
58
67
String username = config .getUsername ();
59
68
String password = config .getPassword ();
60
69
if (username != null && password != null ) {
61
70
service .setUsernameAndPassword (username , password );
71
+ return ;
62
72
}
63
- }
64
-
65
- private void configApiKey (WatsonService service , WatsonConfigurationProperties config ) {
66
73
String apiKey = config .getApiKey ();
67
74
if (apiKey != null ) {
68
75
service .setApiKey (apiKey );
76
+ return ;
69
77
}
70
78
}
71
79
80
+ // Watson Assistant service
81
+
82
+ @ Autowired
83
+ private WatsonAssistantConfigurationProperties assistantConfig ;
84
+
85
+ @ Bean
86
+ @ ConditionalOnMissingBean
87
+ @ ConditionalOnWatsonServiceProperties (prefix = WatsonAssistantConfigurationProperties .PREFIX )
88
+ public Assistant assistant () {
89
+ Assistant service = new Assistant (assistantConfig .getVersionDate ());
90
+ configUrl (service , assistantConfig );
91
+ configAuth (service , assistantConfig );
92
+ return service ;
93
+ }
94
+
72
95
// Watson Conversation service
73
96
74
97
@ Autowired
@@ -80,7 +103,7 @@ private void configApiKey(WatsonService service, WatsonConfigurationProperties c
80
103
public Conversation conversation () {
81
104
Conversation service = new Conversation (conversationConfig .getVersionDate ());
82
105
configUrl (service , conversationConfig );
83
- configBasicAuth (service , conversationConfig );
106
+ configAuth (service , conversationConfig );
84
107
return service ;
85
108
}
86
109
@@ -95,7 +118,7 @@ public Conversation conversation() {
95
118
public Discovery discovery () {
96
119
Discovery service = new Discovery (discoveryConfig .getVersionDate ());
97
120
configUrl (service , discoveryConfig );
98
- configBasicAuth (service , discoveryConfig );
121
+ configAuth (service , discoveryConfig );
99
122
return service ;
100
123
}
101
124
@@ -108,9 +131,9 @@ public Discovery discovery() {
108
131
@ ConditionalOnMissingBean
109
132
@ ConditionalOnWatsonServiceProperties (prefix = WatsonLanguageTranslatorConfigurationProperties .PREFIX )
110
133
public LanguageTranslator languageTranslator () {
111
- LanguageTranslator service = new LanguageTranslator ();
134
+ LanguageTranslator service = new LanguageTranslator (ltConfig . getVersionDate () );
112
135
configUrl (service , ltConfig );
113
- configBasicAuth (service , ltConfig );
136
+ configAuth (service , ltConfig );
114
137
return service ;
115
138
}
116
139
@@ -125,7 +148,7 @@ public LanguageTranslator languageTranslator() {
125
148
public NaturalLanguageClassifier naturalLanguageClassifier () {
126
149
NaturalLanguageClassifier service = new NaturalLanguageClassifier ();
127
150
configUrl (service , nlcConfig );
128
- configBasicAuth (service , nlcConfig );
151
+ configAuth (service , nlcConfig );
129
152
return service ;
130
153
}
131
154
@@ -140,7 +163,7 @@ public NaturalLanguageClassifier naturalLanguageClassifier() {
140
163
public NaturalLanguageUnderstanding naturalLanguageUnderstanding () {
141
164
NaturalLanguageUnderstanding service = new NaturalLanguageUnderstanding (nluConfig .getVersionDate ());
142
165
configUrl (service , nluConfig );
143
- configBasicAuth (service , nluConfig );
166
+ configAuth (service , nluConfig );
144
167
return service ;
145
168
}
146
169
@@ -155,7 +178,7 @@ public NaturalLanguageUnderstanding naturalLanguageUnderstanding() {
155
178
public PersonalityInsights personalityInsights () {
156
179
PersonalityInsights service = new PersonalityInsights (piConfig .getVersionDate ());
157
180
configUrl (service , piConfig );
158
- configBasicAuth (service , piConfig );
181
+ configAuth (service , piConfig );
159
182
return service ;
160
183
}
161
184
@@ -170,7 +193,7 @@ public PersonalityInsights personalityInsights() {
170
193
public SpeechToText speechToText () {
171
194
SpeechToText service = new SpeechToText ();
172
195
configUrl (service , sttConfig );
173
- configBasicAuth (service , sttConfig );
196
+ configAuth (service , sttConfig );
174
197
return service ;
175
198
}
176
199
@@ -185,7 +208,7 @@ public SpeechToText speechToText() {
185
208
public TextToSpeech textToSpeech () {
186
209
TextToSpeech service = new TextToSpeech ();
187
210
configUrl (service , ttsConfig );
188
- configBasicAuth (service , ttsConfig );
211
+ configAuth (service , ttsConfig );
189
212
return service ;
190
213
}
191
214
@@ -200,7 +223,7 @@ public TextToSpeech textToSpeech() {
200
223
public ToneAnalyzer toneAnalyzer () {
201
224
ToneAnalyzer service = new ToneAnalyzer (taConfig .getVersionDate ());
202
225
configUrl (service , taConfig );
203
- configBasicAuth (service , taConfig );
226
+ configAuth (service , taConfig );
204
227
return service ;
205
228
}
206
229
@@ -215,8 +238,7 @@ public ToneAnalyzer toneAnalyzer() {
215
238
public VisualRecognition visualRecognition () {
216
239
VisualRecognition service = new VisualRecognition (vrConfig .getVersionDate ());
217
240
configUrl (service , vrConfig );
218
- configBasicAuth (service , vrConfig );
219
- configApiKey (service , vrConfig );
241
+ configAuth (service , vrConfig );
220
242
return service ;
221
243
}
222
244
0 commit comments