Skip to content

Commit f7ba9d6

Browse files
authored
Merge pull request #230 from chughts/cffixes
Discovery Node
2 parents 5ad9742 + 791385a commit f7ba9d6

File tree

11 files changed

+954
-85
lines changed

11 files changed

+954
-85
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Node-RED Watson Nodes for IBM Bluemix
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.4.30
11+
- New services utilities to handle node-red app name clash problems
12+
- New V1 Discovery Node
13+
- Implementation of Discovery Node query, list and get details methods
14+
- Fix to Translator Node which was ignoring any override values set in the msg object
15+
1016
### New in version 0.4.29
1117
- Fix to Document Conversion Node to preserve full msg object
1218
- Fix to Language Translator Node train mode documentation

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.4.29",
3+
"version": "0.4.30",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",
@@ -11,7 +11,7 @@
1111
"temp": "^0.8.3",
1212
"qs": "6.x",
1313
"image-type": "^2.0.2",
14-
"watson-developer-cloud": "^2.8.2",
14+
"watson-developer-cloud": "^2.14.3",
1515
"kuromoji": "^0.0.5",
1616
"is-docx": "^0.0.3"
1717
},
@@ -34,6 +34,7 @@
3434
"nodes": {
3535
"watson-conversation-v1":"services/conversation/v1.js",
3636
"watson-conversation-v1-experimental":"services/conversation/v1-exp.js",
37+
"watson-discovery-v1":"services/discovery/v1.js",
3738
"watson-discovery-v1-experimental":"services/discovery/v1-exp.js",
3839
"watson-document-conversion-v1": "services/document_conversion/v1.js",
3940
"watson-concept-insights-v2": "services/concept_insights/v2.js",

services/discovery/discovery-utils.js

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/**
2+
* Copyright 2016 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
function DiscoveryUtils() {}
18+
DiscoveryUtils.prototype = {
19+
20+
buildParams: function(msg, config) {
21+
var params = {};
22+
if (msg.discoveryparams && msg.discoveryparams.environmentname) {
23+
params.name = msg.discoveryparams.environmentname;
24+
} else if (config.environmentname) {
25+
params.name = config.environmentname;
26+
} else if (msg.discoveryparams && msg.discoveryparams.configurationname) {
27+
params.name = msg.discoveryparams.configurationname;
28+
} else if (config.configurationname) {
29+
params.name = config.cofigurationname;
30+
}
31+
32+
if (msg.discoveryparams && msg.discoveryparams.environment_id) {
33+
params.environment_id = msg.discoveryparams.environment_id;
34+
} else if (config.environment_id) {
35+
params.environment_id = config.environment_id;
36+
}
37+
38+
if (msg.discoveryparams && msg.discoveryparams.collection_id) {
39+
params.collection_id = msg.discoveryparams.collection_id;
40+
} else if (config.collection_id) {
41+
params.collection_id = config.collection_id;
42+
}
43+
44+
if (msg.discoveryparams && msg.discoveryparams.configuration_id) {
45+
params.configuration_id = msg.discoveryparams.configuration_id;
46+
} else if (config.configuration_id) {
47+
params.configuration_id = config.configuration_id;
48+
}
49+
50+
if (config.count) {
51+
params.count = config.count;
52+
}
53+
if (config.query) {
54+
params.query = config.query;
55+
}
56+
if (config.filter) {
57+
params.filter = config.filter;
58+
}
59+
if (config.aggregation) {
60+
params.aggregation = config.aggregation;
61+
}
62+
if (config.return) {
63+
params.return = config.return;
64+
}
65+
66+
return params;
67+
},
68+
69+
paramEnvCheck: function (params) {
70+
var response = '';
71+
if (!params.environment_id) {
72+
response = 'Missing Environment ID ';
73+
}
74+
return response;
75+
},
76+
77+
paramCollectionCheck: function (params) {
78+
var response = '';
79+
if (!params.collection_id) {
80+
response = 'Missing Collection ID ';
81+
}
82+
return response;
83+
},
84+
85+
paramConfigurationCheck: function (params) {
86+
var response = '';
87+
if (!params.configuration_id) {
88+
response = 'Missing Configuration ID ';
89+
}
90+
return response;
91+
},
92+
93+
reportError: function (node, msg, message) {
94+
var messageTxt = message.error ? message.error : message;
95+
node.status({fill:'red', shape:'dot', text: messageTxt});
96+
node.error(message, msg);
97+
}
98+
99+
};
100+
101+
var discoveryutils = new DiscoveryUtils();
102+
103+
module.exports = discoveryutils;

services/discovery/v1-exp.html

+143-27
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,168 @@
3232
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
3333
<input type="password" id="node-input-password" placeholder="Password">
3434
</div>
35+
36+
<div class="form-row">
37+
<label for="node-input-discovery-method"><i class="fa fa-book"></i> Method: </label>
38+
<select type="text" id="node-input-discovery-method" style="display: inline-block; width: 70%;">
39+
<option value="listEnvrionments">List existing envionments</option>
40+
<option value="getEnvironmentDetails">Retrieve environment details</option>
41+
<option value="listCollections">List existing collections</option>
42+
<option value="getCollectionDetails">Retrieve collection details</option>
43+
</select>
44+
</div>
45+
3546
<div class="form-row">
3647
<label for="node-input-environmentname"><i class="fa fa-tag"></i> Environment Name</label>
37-
<input type="text" id="node-input-envrionmentname" placeholder="">
48+
<input type="text" id="node-input-environmentname" placeholder="">
49+
</div>
50+
<div class="form-row">
51+
<label for="node-input-environment_id"><i class="fa fa-tag"></i> Environment ID</label>
52+
<input type="text" id="node-input-environment_id" placeholder="">
3853
</div>
54+
<div class="form-row">
55+
<label for="node-input-collection_id"><i class="fa fa-tag"></i> Collection ID</label>
56+
<input type="text" id="node-input-collection_id" placeholder="">
57+
</div>
58+
3959
</script>
4060

4161
<script type="text/x-red" data-help-name="watson-discovery">
4262
<p>This is the Node for the V1 Experimental Watson Discovery service.</p>
43-
<p>This version of the Node will only list the envrionments created for
44-
the service.
45-
</p>
46-
<p>The node does not need any input. If the envrionment name field is left blank
63+
<p>This Experimental node has now been deprecated.</p>
64+
<p>The following methods are available:</p>
65+
<ul>
66+
<li>
67+
<p><b>List Existing Envrionments</b><p>
68+
<p>The node does not need any input. If the envrionment name field is left blank
4769
it will list all envrionments created for the instance of the Discovery service.
4870
If the envrionment name is specified, then only the details for
4971
the Discovery envrionment with the specified name will be returned.
50-
</p>
51-
<p>The environment being requested can be overridden by specifying the search name
52-
in <code>msg.discoveryparams.envrionmentname</code>
53-
</p>
54-
55-
<p>Node output : </p>
56-
<ul>
57-
<li><code>msg.envrionments</code> : A list of the envrionments created under
58-
the Discovery service instance.</li>
72+
</p>
73+
<p>The environment being requested can be overridden by specifying the search name
74+
in <code>msg.discoveryparams.environmentname</code>
75+
</p>
76+
<p>Node output : </p>
77+
<ul>
78+
<li><code>msg.environments</code> : A list of the envrionments created under
79+
the Discovery service instance.</li>
80+
</ul>
81+
</li>
82+
<br/>
83+
<li>
84+
<p><b>Get Envrionment Details</b><p>
85+
<p>The node needs an Environment ID as input.
86+
</p>
87+
<p>The environment being requested can be overridden by specifying the search id
88+
in <code>msg.discoveryparams.environment_id</code>
89+
</p>
90+
<p>Node output : </p>
91+
<ul>
92+
<li><code>msg.environment_details</code> : Details of the requested environment.</li>
93+
</ul>
94+
</li>
95+
<br/>
96+
<li>
97+
<p><b>List Existing Collections</b><p>
98+
<p>The node needs an Environment ID as input.</p>
99+
<p>The Environment ID for the collection list being requested can be overridden by specifying the search id
100+
in <code>msg.discoveryparams.environment_id</code>
101+
</p>
102+
<p>Node output : </p>
103+
<ul>
104+
<li><code>msg.collections</code> : A list of the collections created under
105+
the environment in the Discovery service instance.</li>
106+
</ul>
107+
</li>
108+
<br/>
109+
<li>
110+
<p><b>Get Collections Details</b><p>
111+
<p>The node needs an Environment ID and Collection ID as input.
112+
</p>
113+
<p>The collection being requested can be overridden by specifying the
114+
search ids in
115+
<code>msg.discoveryparams.environment_id/code>
116+
and <code>msg.discoveryparams.collection_id/code>
117+
</p>
118+
<p>Node output : </p>
119+
<ul>
120+
<li><code>msg.collection_details</code> : Details of the requested collection.</li>
121+
</ul>
122+
</li>
123+
<br/>
59124
</ul>
60125
<p>For more information about the Discovery service,
61126
read the service <a href="https://www.ibm.com/watson/developercloud/doc/discovery/">documentation</a>.</p>
127+
62128
</script>
63129

64130
<script type="text/javascript">
131+
132+
// Need to simulate a namespace, so that some of the variables don't leak across nodes
133+
function DiscoveryExperimental () {}
134+
135+
// This is the namespace for this version of this Node.
136+
var disExp = new DiscoveryExperimental();
137+
138+
//disExp.abc = 'abc';
139+
disExp.hideAll = function() {
140+
$('#node-input-environmentname').parent().hide();
141+
$('#node-input-environment_id').parent().hide();
142+
$('#node-input-collection_id').parent().hide();
143+
};
144+
145+
disExp.processSelectedMethod = function(method) {
146+
disExp.hideAll();
147+
switch (method) {
148+
case 'listEnvrionments':
149+
$('#node-input-environmentname').parent().show();
150+
break;
151+
case 'getEnvironmentDetails':
152+
case 'listCollections':
153+
$('#node-input-environment_id').parent().show();
154+
break;
155+
case 'getCollectionDetails':
156+
$('#node-input-environment_id').parent().show();
157+
$('#node-input-collection_id').parent().show();
158+
break;
159+
}
160+
}
161+
162+
disExp.UIListeners = function () {
163+
$('#node-input-discovery-method').change(function(val){
164+
var method = $('#node-input-discovery-method').val();
165+
disExp.processSelectedMethod(method);
166+
});
167+
}
168+
169+
disExp.checkForPrepare = function () {
170+
disExp.hideAll();
171+
disExp.UIListeners();
172+
};
173+
174+
// This is the on edit prepare function, which will be invoked everytime the dialog is shown.
175+
function oneditprepare() {
176+
disExp.checkForPrepare();
177+
$.getJSON('watson-discovery/vcap/')
178+
.done(function (service) {
179+
$('.credentials').toggle(!service);
180+
})
181+
.fail(function () {
182+
$('.credentials').show();
183+
}).always(function () {
184+
$('#credentials-check').hide();
185+
})
186+
}
187+
65188
(function() {
66189
RED.nodes.registerType('watson-discovery', {
67-
category: 'IBM Watson',
190+
category: 'Watson Deprecated',
68191
defaults: {
69192
name: {value: ""},
70-
envrionmentname: {value: ""}
193+
environmentname: {value: ""},
194+
environment_id: {value: ""},
195+
collection_id: {value: ""},
196+
"discovery-method": {value:"listEnvrionments"}
71197
},
72198
credentials: {
73199
username: {type:"text"},
@@ -84,17 +210,7 @@
84210
labelStyle: function() {
85211
return this.name ? "node_label_italic" : "";
86212
},
87-
oneditprepare: function() {
88-
$.getJSON('watson-discovery/vcap/')
89-
.done(function (service) {
90-
$('.credentials').toggle(!service);
91-
})
92-
.fail(function () {
93-
$('.credentials').show();
94-
}).always(function () {
95-
$('#credentials-check').hide();
96-
})
97-
}
213+
oneditprepare: oneditprepare
98214
});
99215
})();
100216
</script>

0 commit comments

Comments
 (0)