Skip to content

Commit 87386fd

Browse files
committed
Migrate to ibm-watson
1 parent 5f98762 commit 87386fd

File tree

5 files changed

+184
-171
lines changed

5 files changed

+184
-171
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10-
### New in version 0.8.1
10+
### New in version 0.8.2
1111
- Node-RED & IBM-Watson & Use of promises on API invocation & IAM URL construct migration & Removal of default endpoint of
1212
- Document Translator node
13+
- Discovery node
14+
- Discovery Document Loader node
15+
- Discovery Query Builder node
1316

1417

1518
### New in version 0.8.1

services/discovery/discovery-utils.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,29 @@
1414
* limitations under the License.
1515
**/
1616
const pkg = require('../../package.json'),
17-
DiscoveryV1 = require('watson-developer-cloud/discovery/v1');
17+
DiscoveryV1 = require('ibm-watson/discovery/v1'),
18+
{ IamAuthenticator } = require('ibm-watson/auth');
19+
1820

1921
function DiscoveryUtils() {}
2022
DiscoveryUtils.prototype = {
2123

2224
buildService: function(username, password, apikey, endpoint) {
25+
let authSettings = {};
2326
let serviceSettings = {
24-
version_date: '2018-12-03',
27+
version: '2019-04-30',
2528
headers: {
2629
'User-Agent': pkg.name + '-' + pkg.version
2730
}
2831
};
2932

3033
if (apikey) {
31-
serviceSettings.iam_apikey = apikey;
34+
authSettings.apikey = apikey;
3235
} else {
33-
serviceSettings.username = username;
34-
serviceSettings.password = password;
36+
authSettings.username = username;
37+
authSettings.password = password;
3538
}
39+
serviceSettings.authenticator = new IamAuthenticator(authSettings);
3640

3741
if (endpoint) {
3842
serviceSettings.url = endpoint;
@@ -64,7 +68,7 @@ DiscoveryUtils.prototype = {
6468
targetField = 'query';
6569

6670
if (config.nlp_query || (msg.discoveryparams && msg.discoveryparams.nlp_query)) {
67-
targetField = 'natural_language_query';
71+
targetField = 'naturalLanguageQuery';
6872
}
6973
if (msg.discoveryparams && msg.discoveryparams[sourceField]) {
7074
params[targetField] = msg.discoveryparams[sourceField];
@@ -83,7 +87,7 @@ DiscoveryUtils.prototype = {
8387
params.file = this.isJsonObject(msg.payload) ?
8488
JSON.stringify(msg.payload) :
8589
msg.payload;
86-
params.file_content_type = 'application/json';
90+
params.fileContentType = 'application/json';
8791
}
8892
return params;
8993
},
@@ -149,7 +153,7 @@ DiscoveryUtils.prototype = {
149153
params = me.buildParamsForName(msg, config, params);
150154
params = me.buildParamsForQuery(msg, config, params);
151155

152-
['environment_id', 'collection_id', 'configuration_id',
156+
['environmentId', 'collectionId', 'configurationId',
153157
'collection_name', 'language_code',
154158
'passages', 'description', 'size', 'filename',
155159
'highlight'
@@ -173,10 +177,10 @@ DiscoveryUtils.prototype = {
173177
buildMsgOverrides: function(msg, config) {
174178
var params = {};
175179
if (config.environment) {
176-
params.environment_id = config.environment;
180+
params.environmentId = config.environment;
177181
}
178182
if (config.collection) {
179-
params.collection_id = config.collection;
183+
params.collectionId = config.collection;
180184
}
181185
if (config.passages) {
182186
params.passages = config.passages;
@@ -222,7 +226,7 @@ DiscoveryUtils.prototype = {
222226

223227
paramEnvCheck: function(params) {
224228
var response = '';
225-
if (!params.environment_id) {
229+
if (!params.environmentId) {
226230
response = 'Missing Environment ID ';
227231
}
228232
return response;
@@ -262,15 +266,15 @@ DiscoveryUtils.prototype = {
262266

263267
paramCollectionCheck: function(params) {
264268
var response = '';
265-
if (!params.collection_id) {
269+
if (!params.collectionId) {
266270
response = 'Missing Collection ID ';
267271
}
268272
return response;
269273
},
270274

271275
paramConfigurationCheck: function(params) {
272276
var response = '';
273-
if (!params.configuration_id) {
277+
if (!params.configurationId) {
274278
response = 'Missing Configuration ID ';
275279
}
276280
return response;

services/discovery/v1.html

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@
3838
</div>
3939

4040
<div class="form-row credentials">
41-
<label>&nbsp;</label>
42-
<input type="checkbox" id="node-input-default-endpoint" style="display: inline-block; width: auto; vertical-align: top;">
43-
<label for="node-input-default-endpoint" style="width: 70%;"> Use Default Service Endpoint</label>
44-
</div>
45-
<div class="form-row">
4641
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
4742
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/discovery/api">
4843
</div>
@@ -66,6 +61,7 @@
6661
<option value="createConfiguration">Create new configuration</option>
6762
<option value="listConfigurations">List existing configurations</option>
6863
<option value="getConfigurationDetails">Retrieve configuration details</option>
64+
<option value="deleteConfiguration">Delete configuration</option>
6965
</select>
7066
</div>
7167

@@ -74,24 +70,24 @@
7470
<input type="text" id="node-input-environmentname" placeholder="">
7571
</div>
7672
<div class="form-row">
77-
<label for="node-input-environment_id"><i class="fa fa-tag"></i> Environment ID</label>
78-
<input type="text" id="node-input-environment_id" placeholder="">
73+
<label for="node-input-environmentId"><i class="fa fa-tag"></i> Environment ID</label>
74+
<input type="text" id="node-input-environmentId" placeholder="">
7975
</div>
8076
<div class="form-row">
8177
<label for="node-input-collection_name"><i class="fa fa-tag"></i> Collection Name</label>
8278
<input type="text" id="node-input-collection_name" placeholder="">
8379
</div>
8480
<div class="form-row">
85-
<label for="node-input-collection_id"><i class="fa fa-tag"></i> Collection ID</label>
86-
<input type="text" id="node-input-collection_id" placeholder="">
81+
<label for="node-input-collectionId"><i class="fa fa-tag"></i> Collection ID</label>
82+
<input type="text" id="node-input-collectionId" placeholder="">
8783
</div>
8884
<div class="form-row">
8985
<label for="node-input-configurationname"><i class="fa fa-tag"></i> Configuration Name</label>
9086
<input type="text" id="node-input-configurationname" placeholder="">
9187
</div>
9288
<div class="form-row">
93-
<label for="node-input-configuration_id"><i class="fa fa-tag"></i> Configuration ID</label>
94-
<input type="text" id="node-input-configuration_id" placeholder="">
89+
<label for="node-input-configurationId"><i class="fa fa-tag"></i> Configuration ID</label>
90+
<input type="text" id="node-input-configurationId" placeholder="">
9591
</div>
9692

9793
<div class="form-row">
@@ -208,7 +204,7 @@
208204
<p>For this method the node needs an Environment ID as input.
209205
</p>
210206
<p>The environment being requested can be overridden by specifying the search id
211-
in <code>msg.discoveryparams.environment_id</code>
207+
in <code>msg.discoveryparams.environmentId</code>
212208
</p>
213209
<p>Node output : </p>
214210
<ul>
@@ -221,10 +217,10 @@
221217
Description, Configuration ID and Language Code as input.
222218
</p>
223219
<p>The fields can be overridden by specifying
224-
in <code>msg.discoveryparams.environment_id</code>
220+
in <code>msg.discoveryparams.environmentId</code>
225221
, <code>msg.discoveryparams.collection_name</code>
226222
, <code>msg.discoveryparams.description</code>
227-
, <code>msg.discoveryparams.configuration_id</code>
223+
, <code>msg.discoveryparams.configurationId</code>
228224
and <code>msg.discoveryparams.language_code</code>
229225
</p>
230226

@@ -239,7 +235,7 @@
239235
<p><b>List Existing Collections</b><p>
240236
<p>For this method the node needs an Environment ID as input.</p>
241237
<p>The Environment ID for the collection list being requested can be overridden by specifying the search id
242-
in <code>msg.discoveryparams.environment_id</code>
238+
in <code>msg.discoveryparams.environmentId</code>
243239
</p>
244240
<p>Node output : </p>
245241
<ul>
@@ -254,8 +250,8 @@
254250
</p>
255251
<p>The collection being requested can be overridden by specifying the
256252
search ids in
257-
<code>msg.discoveryparams.environment_id</code>
258-
and <code>msg.discoveryparams.collection_id</code>
253+
<code>msg.discoveryparams.environmentId</code>
254+
and <code>msg.discoveryparams.collectionId</code>
259255
</p>
260256
<p>Node output : </p>
261257
<ul>
@@ -270,7 +266,7 @@
270266
configuration with the given name.</p>
271267
<p>The Environment ID for the configuration list being requested can be
272268
overridden by specifying the environment id in
273-
<code>msg.discoveryparams.environment_id</code>
269+
<code>msg.discoveryparams.environmentId</code>
274270
The configuration name can be overridden by specifying the name inspect
275271
<code>msg.discoveryparams.configuration_name</code>
276272
</p>
@@ -288,9 +284,9 @@
288284
<p>The Environment and Configuration IDs for the configuration being
289285
requested can be
290286
overridden by specifying the environment id in
291-
<code>msg.discoveryparams.environment_id</code>
287+
<code>msg.discoveryparams.environmentId</code>
292288
and the configuration id in
293-
<code>msg.discoveryparams.configuration_id</code>
289+
<code>msg.discoveryparams.configurationId</code>
294290
</p>
295291
<p>Node output : </p>
296292
<ul>
@@ -299,14 +295,31 @@
299295
</ul>
300296
</li>
301297
<br/>
298+
<li>
299+
<p><b>Delete Configuration</b><p>
300+
<p>For this method node needs an Environment ID and Configuration ID as input.</p>
301+
<p>The Environment and Configuration IDs for the configuration being
302+
deleted can be
303+
overridden by specifying the environment id in
304+
<code>msg.discoveryparams.environmentId</code>
305+
and the configuration id in
306+
<code>msg.discoveryparams.configurationId</code>
307+
</p>
308+
<p>Node output : </p>
309+
<ul>
310+
<li><code>msg.configuration</code> : Details the
311+
deleted configuration.</li>
312+
</ul>
313+
</li>
314+
<br/>
302315
<li>
303316
<p><b>Search in Collection</b><p>
304317
<p>For this method the node needs an Environment ID and Collection ID as input.
305318
</p>
306319
<p>The collection being requested can be overridden by specifying the
307320
search ids in
308-
<code>msg.discoveryparams.environment_id</code>
309-
and <code>msg.discoveryparams.collection_id</code>
321+
<code>msg.discoveryparams.environmentId</code>
322+
and <code>msg.discoveryparams.collectionId</code>
310323
</p>
311324
<p>Optionally you can specify the number of documents to retrieve, a
312325
query to find the most relevant search results, whether to
@@ -351,11 +364,11 @@
351364
//disV1.abc = 'abc';
352365
disV1.hideAll = function() {
353366
$('#node-input-environmentname').parent().hide();
354-
$('#node-input-environment_id').parent().hide();
367+
$('#node-input-environmentId').parent().hide();
355368
$('#node-input-collection_name').parent().hide();
356-
$('#node-input-collection_id').parent().hide();
369+
$('#node-input-collectionId').parent().hide();
357370
$('#node-input-configurationname').parent().hide();
358-
$('#node-input-configuration_id').parent().hide();
371+
$('#node-input-configurationId').parent().hide();
359372
$('#node-input-language_code').parent().hide();
360373
$('#node-input-count').parent().hide();
361374
$('#node-input-passages').parent().hide();
@@ -387,35 +400,36 @@
387400
fields.push('#node-input-environmentname');
388401
break;
389402
case 'createCollection':
390-
fields.push('#node-input-environment_id'
391-
+ ', #node-input-configuration_id'
403+
fields.push('#node-input-environmentId'
404+
+ ', #node-input-configurationId'
392405
+ ', #node-input-language_code'
393406
+ ', #node-input-collection_name'
394407
+ ', #node-input-description');
395408
break;
396-
case 'createConfiguration':
409+
case 'listConfigurations':
397410
case 'getEnvironmentDetails':
398411
case 'listCollections':
399412
case 'deleteEnvironment':
400-
fields.push('#node-input-environment_id');
413+
fields.push('#node-input-environmentId');
401414
break;
402415
case 'getCollectionDetails':
403416
case 'deleteCollection':
404-
fields.push('#node-input-environment_id'
405-
+ ', #node-input-collection_id');
417+
fields.push('#node-input-environmentId'
418+
+ ', #node-input-collectionId');
406419
break;
407-
case 'listConfigurations':
408-
fields.push('#node-input-environment_id'
420+
case 'createConfiguration':
421+
fields.push('#node-input-environmentId'
409422
+ ', #node-input-configurationname');
410423
break;
411424
case 'getConfigurationDetails':
412-
fields.push('#node-input-environment_id'
413-
+ ', #node-input-configuration_id');
425+
case 'deleteConfiguration':
426+
fields.push('#node-input-environmentId'
427+
+ ', #node-input-configurationId');
414428
break;
415429
case 'query':
416-
case 'queryNotices':
417-
fields.push('#node-input-environment_id'
418-
+ ', #node-input-collection_id'
430+
case 'queryNotices':
431+
fields.push('#node-input-environmentId'
432+
+ ', #node-input-collectionId'
419433
+ ', #node-input-count'
420434
+ ', #node-input-passages'
421435
+ ', #node-input-nlp_query'
@@ -433,15 +447,6 @@
433447
var method = $('#node-input-discovery-method').val();
434448
disV1.processSelectedMethod(method);
435449
});
436-
437-
$('input#node-input-default-endpoint').change(function () {
438-
var checked = $('input#node-input-default-endpoint').prop('checked')
439-
if (checked) {
440-
$('#node-input-service-endpoint').parent().hide();
441-
} else {
442-
$('#node-input-service-endpoint').parent().show();
443-
}
444-
});
445450
}
446451

447452
disV1.checkForPrepare = function () {
@@ -469,10 +474,10 @@
469474
defaults: {
470475
name: {value: ''},
471476
environmentname: {value: ''},
472-
environment_id: {value: ''},
473-
collection_id: {value: ''},
477+
environmentId: {value: ''},
478+
collectionId: {value: ''},
474479
configurationname: {value: ''},
475-
configuration_id: {value: ''},
480+
configurationId: {value: ''},
476481
language_code: {value: 'en'},
477482
collection_name: {value: ''},
478483
count: {value: '1'},
@@ -485,8 +490,7 @@
485490
description: {value: ''},
486491
size: {value: 'LT'},
487492
'discovery-method': {value:'query'},
488-
'default-endpoint' :{value: true},
489-
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/discovery/api'}
493+
'service-endpoint' :{value: ''}
490494
},
491495
credentials: {
492496
username: {type:'text'},

0 commit comments

Comments
 (0)