From d1569975bb18f4359fac18aa98f55b69c248a3ad Mon Sep 17 00:00:00 2001 From: "Chinthakayala, Sheshashailavas (sc2914)" Date: Mon, 28 Aug 2017 05:25:46 -0900 Subject: [CCSDK-28] populated the seed code for dgbuilder updated the code to point to the new package name for sli Change-Id: I3b5a1d05dc5193664fd4a667afdcd0b2354010a4 Issue-ID:{CCSDK-28} Signed-off-by: Chinthakayala, Sheshashailavas (sc2914) Signed-off-by: Chinthakayala, Sheshashailavas (sc2914) --- dgbuilder/core_nodes/deprecated/61-imap.html | 56 +++++++++ dgbuilder/core_nodes/deprecated/61-imap.js | 139 +++++++++++++++++++++++ dgbuilder/core_nodes/deprecated/73-parsexml.html | 53 +++++++++ dgbuilder/core_nodes/deprecated/73-parsexml.js | 47 ++++++++ dgbuilder/core_nodes/deprecated/74-js2xml.html | 51 +++++++++ dgbuilder/core_nodes/deprecated/74-js2xml.js | 39 +++++++ dgbuilder/core_nodes/deprecated/90-httpget.html | 61 ++++++++++ dgbuilder/core_nodes/deprecated/90-httpget.js | 53 +++++++++ 8 files changed, 499 insertions(+) create mode 100644 dgbuilder/core_nodes/deprecated/61-imap.html create mode 100644 dgbuilder/core_nodes/deprecated/61-imap.js create mode 100644 dgbuilder/core_nodes/deprecated/73-parsexml.html create mode 100644 dgbuilder/core_nodes/deprecated/73-parsexml.js create mode 100644 dgbuilder/core_nodes/deprecated/74-js2xml.html create mode 100644 dgbuilder/core_nodes/deprecated/74-js2xml.js create mode 100644 dgbuilder/core_nodes/deprecated/90-httpget.html create mode 100644 dgbuilder/core_nodes/deprecated/90-httpget.js (limited to 'dgbuilder/core_nodes/deprecated') diff --git a/dgbuilder/core_nodes/deprecated/61-imap.html b/dgbuilder/core_nodes/deprecated/61-imap.html new file mode 100644 index 00000000..9702cd64 --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/61-imap.html @@ -0,0 +1,56 @@ + + + + + + + diff --git a/dgbuilder/core_nodes/deprecated/61-imap.js b/dgbuilder/core_nodes/deprecated/61-imap.js new file mode 100644 index 00000000..aa2b4beb --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/61-imap.js @@ -0,0 +1,139 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); +var Imap = require('imap'); +var util = require('util'); + +try { + var emailkey = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js"); +} catch (err) { + //util.log("[61-imap.js] Info : No Email credentials found."); +} + +if (emailkey) { + var imap = new Imap({ + user: emailkey.user, + password: emailkey.pass, + host: emailkey.server||"imap.gmail.com", + port: emailkey.port||"993", + tls: true, + tlsOptions: { rejectUnauthorized: false } + }); + + function openInbox(cb) { + imap.openBox('INBOX', true, cb); + } +} + +function ImapNode(n) { + RED.nodes.createNode(this,n); + this.warn("This node has been deprecated and will be deleted in a future release. Please update your flow to use the 'e-mail in' node."); + this.name = n.name; + this.repeat = n.repeat * 1000 || 300000; + var node = this; + this.interval_id = null; + var oldmail = {}; + + if (!isNaN(this.repeat) && this.repeat > 0) { + node.log("repeat = "+this.repeat); + this.interval_id = setInterval( function() { + node.emit("input",{}); + }, this.repeat ); + } + + this.on("input", function(msg) { + if (imap) { + imap.once('ready', function() { + var pay = {}; + openInbox(function(err, box) { + if (box.messages.total > 0) { + var f = imap.seq.fetch(box.messages.total + ':*', { bodies: ['HEADER.FIELDS (FROM SUBJECT DATE)','TEXT'] }); + f.on('message', function(msg, seqno) { + node.log('message: #'+ seqno); + var prefix = '(#' + seqno + ') '; + msg.on('body', function(stream, info) { + var buffer = ''; + stream.on('data', function(chunk) { + buffer += chunk.toString('utf8'); + }); + stream.on('end', function() { + if (info.which !== 'TEXT') { + pay.from = Imap.parseHeader(buffer).from[0]; + pay.topic = Imap.parseHeader(buffer).subject[0]; + pay.date = Imap.parseHeader(buffer).date[0]; + } else { + var parts = buffer.split("Content-Type"); + for (var p in parts) { + if (parts[p].indexOf("text/plain") >= 0) { + pay.payload = parts[p].split("\n").slice(1,-2).join("\n").trim(); + } + if (parts[p].indexOf("text/html") >= 0) { + pay.html = parts[p].split("\n").slice(1,-2).join("\n").trim(); + } + } + //pay.body = buffer; + } + }); + }); + msg.on('end', function() { + //node.log('Finished: '+prefix); + }); + }); + f.on('error', function(err) { + node.warn('fetch error: ' + err); + }); + f.on('end', function() { + if (JSON.stringify(pay) !== oldmail) { + node.send(pay); + oldmail = JSON.stringify(pay); + node.log('sent new message: '+pay.topic); + } + else { node.log('duplicate not sent: '+pay.topic); } + imap.end(); + }); + } + else { + // node.log("you have achieved inbox zero"); + imap.end(); + } + }); + }); + imap.connect(); + } + else { node.warn("No Email credentials found. See info panel."); } + }); + + if (imap) { + imap.on('error', function(err) { + util.log(err); + }); + } + + this.on("error", function(err) { + node.log("error: ",err); + }); + + this.on("close", function() { + if (this.interval_id != null) { + clearInterval(this.interval_id); + } + if (imap) { imap.destroy(); } + }); + + node.emit("input",{}); +} +RED.nodes.registerType("imap",ImapNode); diff --git a/dgbuilder/core_nodes/deprecated/73-parsexml.html b/dgbuilder/core_nodes/deprecated/73-parsexml.html new file mode 100644 index 00000000..b6fc16fe --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/73-parsexml.html @@ -0,0 +1,53 @@ + + + + + + + diff --git a/dgbuilder/core_nodes/deprecated/73-parsexml.js b/dgbuilder/core_nodes/deprecated/73-parsexml.js new file mode 100644 index 00000000..92850cb6 --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/73-parsexml.js @@ -0,0 +1,47 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(RED) { + "use strict"; + var util = require("util"); + var parseString = require('xml2js').parseString; + var useColors = true; + //util.inspect.styles.boolean = "red"; + + function Xml2jsNode(n) { + RED.nodes.createNode(this,n); + this.warn("This node has been deprecated and will be deleted in a future release. Please update your flow to use the 'xml' node."); + this.useEyes = n.useEyes||false; + var node = this; + this.on("input", function(msg) { + try { + parseString(msg.payload, {strict:true,async:true}, function (err, result) { + //parseString(msg.payload, {strict:false,async:true}, function (err, result) { + if (err) { node.error(err); } + else { + msg.payload = result; + node.send(msg); + if (node.useEyes == true) { + node.log("\n"+util.inspect(msg, {colors:useColors, depth:10})); + } + } + }); + } + catch(e) { util.log("[73-parsexml.js] "+e); } + }); + } + RED.nodes.registerType("xml2js",Xml2jsNode); +} diff --git a/dgbuilder/core_nodes/deprecated/74-js2xml.html b/dgbuilder/core_nodes/deprecated/74-js2xml.html new file mode 100644 index 00000000..f614579b --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/74-js2xml.html @@ -0,0 +1,51 @@ + + + + + + + diff --git a/dgbuilder/core_nodes/deprecated/74-js2xml.js b/dgbuilder/core_nodes/deprecated/74-js2xml.js new file mode 100644 index 00000000..164bafad --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/74-js2xml.js @@ -0,0 +1,39 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +module.exports = function(RED) { + "use strict"; + var js2xmlparser = require("js2xmlparser"); + + function Js2XmlNode(n) { + RED.nodes.createNode(this,n); + this.warn("This node has been deprecated and will be deleted in a future release. Please update your flow to use the 'xml' node."); + this.root = n.root; + var node = this; + + this.on("input", function(msg) { + try { + var root = node.root || typeof msg.payload; + if (typeof msg.payload !== "object") { msg.payload = '"'+msg.payload+'"'; } + console.log(root, typeof msg.payload,msg.payload); + msg.payload = js2xmlparser(root, msg.payload); + node.send(msg); + } + catch(e) { console.log(e); } + }); + } + RED.nodes.registerType("json2xml",Js2XmlNode); +} diff --git a/dgbuilder/core_nodes/deprecated/90-httpget.html b/dgbuilder/core_nodes/deprecated/90-httpget.html new file mode 100644 index 00000000..b1f2e080 --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/90-httpget.html @@ -0,0 +1,61 @@ + + + + + + + diff --git a/dgbuilder/core_nodes/deprecated/90-httpget.js b/dgbuilder/core_nodes/deprecated/90-httpget.js new file mode 100644 index 00000000..63e16b93 --- /dev/null +++ b/dgbuilder/core_nodes/deprecated/90-httpget.js @@ -0,0 +1,53 @@ +/** + * Copyright 2013 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var RED = require(process.env.NODE_RED_HOME+"/red/red"); + +function HttpGet(n) { + RED.nodes.createNode(this,n); + this.warn("This node has been deprecated and will be deleted in a future release. Please update your flow to use the 'http request' node."); + this.baseurl = n.baseurl || ""; + this.append = n.append || ""; + var node = this; + if (this.baseurl.substring(0,5) === "https") { var http = require("https"); } + else { var http = require("http"); } + this.on("input", function(msg) { + msg._payload = msg.payload; + //util.log("[httpget] "+this.baseurl+msg.payload+this.append); + http.get(this.baseurl+msg.payload+this.append, function(res) { + node.log("Http response: " + res.statusCode); + msg.rc = res.statusCode; + msg.payload = ""; + if ((msg.rc != 200) && (msg.rc != 404)) { + node.send(msg); + } + res.setEncoding('utf8'); + res.on('data', function(chunk) { + msg.payload += chunk; + }); + res.on('end', function() { + node.send(msg); + }); + }).on('error', function(e) { + //node.error(e); + msg.rc = 503; + msg.payload = e; + node.send(msg); + }); + }); +} + +RED.nodes.registerType("httpget",HttpGet); -- cgit 1.2.3-korg