Skip to content

Commit

Permalink
Add GetProject method
Browse files Browse the repository at this point in the history
  • Loading branch information
chughts committed Mar 25, 2022
1 parent a861d50 commit 2603f2b
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 13 deletions.
22 changes: 22 additions & 0 deletions services/discovery/discovery-utils2.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,32 @@ DiscoveryUtils2.prototype = {
},


paramProjectCheck: function(params) {
var response = '';
if (!params.projectId) {
response = 'Missing Project ID ';
}
return response;
},

buildParamsFor: function(msg, config, params, field) {
if (msg.discoveryparams && msg.discoveryparams[field]) {
params[field] = msg.discoveryparams[field];
} else if (config[field]) {
params[field] = config[field];
}
return params;
},


buildParams: function(msg, config) {
var params = {},
me = this;

['projectId'].forEach(function(f) {
params = me.buildParamsFor(msg, config, params, f);
});

return params;
}

Expand Down
36 changes: 34 additions & 2 deletions services/discovery/v2-project-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
</select>
</div>

<div class="form-row">
<label for="node-input-projectId"><i class="fa fa-tag"></i> Project ID</label>
<input type="text" id="node-input-projectId" placeholder="">
</div>


</script>

<script type="text/x-red" data-help-name="watson-discovery-v2-project-manager">
Expand All @@ -57,6 +63,26 @@
<p><b>List Existing Projects</b><p>
<p>For this method the node does not need any input.
</p>
<p>Node output : </p>
<ul>
<li><code>msg.projects</code> : A list of the projects created under
the Discovery service instance.</li>
</ul>
</li>

<br/>

<li>
<p><b>Retrieve project details</b><p>
<p>For this method the node needs an Project ID as input.
</p>
<p>The project being requested can be overridden by specifying
the search id in <code>msg.discoveryparams.projectId</code>
</p>
<p>Node output : </p>
<ul>
<li><code>msg.discovery_response</code> : Details of the requested project.</li>
</ul>
</li>

</ul>
Expand All @@ -74,9 +100,9 @@
// This is the namespace for this version of this Node.
var disV2pm = new DiscoveryExperimentalV1();

//disV2pm.abc = 'abc';
disV2pm.hideAll = function() {

disV2pm.hideAll = function() {
$('#node-input-projectId').parent().hide();
};

disV2pm.showSelectedFields = function(fields) {
Expand All @@ -89,6 +115,11 @@
disV2pm.hideAll();
fields = [];

switch (method) {
case 'getProject':
fields.push('#node-input-projectId');
}

disV2pm.showSelectedFields(fields);
}

Expand Down Expand Up @@ -123,6 +154,7 @@
category: 'IBM Watson',
defaults: {
name: {value: ''},
projectId: {value: ''},
'discovery-method': {value:'listProjects'},
'service-endpoint' :{value: ''}
},
Expand Down
48 changes: 37 additions & 11 deletions services/discovery/v2-project-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ module.exports = function (RED) {
sEndpoint = '';

const ExecutionList = {
'listProjects' : executeProjectList
'listProjects' : executeListProjects,
'getProject' : executeDiscoveryMethod
};

function executeProjectList(node, discovery, params, msg) {
let fields = {
node : node,
discovery : discovery,
params : params,
msg : msg,
method : "listProjects",
response : "projects"
}
function executeListProjects(fields) {
fields.response = "projects";
return executeListMethod(fields)
}

Expand All @@ -58,6 +52,24 @@ module.exports = function (RED) {
}


function executeDiscoveryMethod(fields) {
var p = new Promise(function resolver(resolve, reject){
fields.discovery[fields.method](fields.params)
.then((response) => {
fields.msg.discovery_response = response;
if (response && response.result) {
fields.msg.discovery_response = response.result;
}
resolve();
})
.catch((err) => {
reject(err);
});
});
return p;
}


function initialCheck(k, m) {
var message = '';
if (!k) {
Expand All @@ -74,6 +86,12 @@ module.exports = function (RED) {
function checkParams(method, params) {
var response = '';

switch (method) {
case 'getProject':
response = discoveryutils.paramProjectCheck(params);
break;
}

if (response) {
return Promise.reject(response);
} else {
Expand All @@ -93,7 +111,15 @@ module.exports = function (RED) {
exe = unknownMethod
}

return exe(node, discovery, params, msg);
let fields = {
node : node,
discovery : discovery,
params : params,
msg : msg,
method : method
}

return exe(fields);
}


Expand Down

0 comments on commit 2603f2b

Please sign in to comment.