Skip to content

Commit 6d1fdd2

Browse files
committed
Initial commit
0 parents  commit 6d1fdd2

13 files changed

+3475
-0
lines changed

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) International Business Machines Corp. 2017
2+
All Rights Reserved
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5+
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
13+
IN THE SOFTWARE.

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# README #
2+
3+
### Node.js Toolkit ###
4+
The toolkit is a Node.js wrapper over the XMLSERVICE open source project from IBM.
5+
6+
###Documentation###
7+
* https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/IBM%20i%20Technology%20Updates/page/Access%20IBM%20i%20Native%20Objects
8+
9+
###API Reference###
10+
* https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/IBM%20i%20Technology%20Updates/page/Toolkit%20for%20i%20APIs
11+
12+
13+
###Installation###
14+
15+
Clone the project to your system and update your Node.js code to refer to the path of Node.js toolkit.
16+
17+
#License
18+
MIT. View [`LICENSE`](https://bitbucket.org/litmis/nodejs-itoolkit/LICENSE) file.

contributors.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Tony Cairns
2+
Xu Meng

lib/idataq.js

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright (c) International Business Machines Corp. 2017
2+
// All Rights Reserved
3+
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
5+
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
6+
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9+
10+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
12+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
13+
// IN THE SOFTWARE.
14+
15+
var xt = require('./itoolkit');
16+
var timeoutMsg = "Timeout!";
17+
var retryInterval = 100; // wait 0.1 second to retry to get result in sync mode.
18+
var retryTimes = Math.round(xt.timeout / retryInterval);
19+
20+
function iDataQueue(conn) {
21+
this.conn = conn; //Pass in the connection object.
22+
this.errno = [
23+
[0, "10i0"],
24+
[0, "10i0", {"setlen":"rec2"}],
25+
["", "7A"],
26+
["", "1A"]
27+
];
28+
}
29+
30+
iDataQueue.prototype.sendToDataQueue = function(name, lib, data, cb) {
31+
var pgm = new xt.iPgm("QSNDDTAQ", {"lib":"QSYS"});
32+
pgm.addParam(name, "10A");
33+
pgm.addParam(lib == ""?"*CURLIB":lib, "10A");
34+
pgm.addParam(data.length, "5p0");
35+
pgm.addParam(data, data.length + "A");
36+
37+
this.conn.add(pgm.toXML());
38+
var async = cb && xt.getClass(cb) == "Function"; //If there is a callback function param, then it is in asynchronized mode.
39+
var rtValue; // The returned value.
40+
var stop = 0; // A flag indicating whether the process is finished.
41+
var retry = 0; // How many times we have retried.
42+
function toJson(str) { // Convert the XML output into JSON
43+
var output = xt.xmlToJson(str);
44+
if(output[0].hasOwnProperty("success") && output[0].success == true)
45+
rtValue = true;
46+
else
47+
rtValue = str;
48+
if(async) // If it is in asynchronized mode.
49+
cb(rtValue); // Run the call back function against the returned value.
50+
stop = 1;
51+
}
52+
function waitForResult() {
53+
retry++;
54+
if(stop == 0)
55+
setTimeout(waitForResult, retryInterval); // Check whether the result is retrieved
56+
else if(retry >= retryTimes)
57+
return timeoutMsg;
58+
else
59+
return rtValue;
60+
}
61+
this.conn.run(toJson, !async); // Post the input XML and get the response.
62+
if(!async) // If it is in synchronized mode.
63+
return waitForResult(); // Run the user defined call back function against the returned value.
64+
}
65+
66+
iDataQueue.prototype.receiveFromDataQueue = function(name, lib, length, cb) {
67+
var pgm = new xt.iPgm("QRCVDTAQ", {"lib":"QSYS"});
68+
pgm.addParam(name, "10A");
69+
pgm.addParam(lib == ""?"*CURLIB":lib, "10A");
70+
pgm.addParam(length, "5p0");
71+
pgm.addParam("", length + 1 + "A");
72+
pgm.addParam(0, "5p0");
73+
74+
this.conn.add(pgm.toXML());
75+
var async = cb && xt.getClass(cb) == "Function"; //If there is a callback function param, then it is in asynchronized mode.
76+
var rtValue; // The returned value.
77+
var stop = 0; // A flag indicating whether the process is finished.
78+
var retry = 0; // How many times we have retried.
79+
function toJson(str) { // Convert the XML output into JSON
80+
var output = xt.xmlToJson(str);
81+
if(output[0].hasOwnProperty("success") && output[0].success == true)
82+
rtValue = output[0].data[3].value;
83+
else
84+
rtValue = str;
85+
if(async) // If it is in asynchronized mode.
86+
cb(rtValue); // Run the call back function against the returned value.
87+
stop = 1;
88+
}
89+
function waitForResult() {
90+
retry++;
91+
if(stop == 0)
92+
setTimeout(waitForResult, retryInterval); // Check whether the result is retrieved
93+
else if(retry >= retryTimes)
94+
return timeoutMsg;
95+
else
96+
return rtValue;
97+
}
98+
this.conn.run(toJson, !async); // Post the input XML and get the response.
99+
if(!async) // If it is in synchronized mode.
100+
return waitForResult(); // Run the user defined call back function against the returned value.
101+
}
102+
103+
iDataQueue.prototype.clearDataQueue= function(name, lib, cb) {
104+
var pgm = new xt.iPgm("QCLRDTAQ", {"lib":"QSYS"});
105+
pgm.addParam(name, "10A");
106+
pgm.addParam(lib == ""?"*CURLIB":lib, "10A");
107+
108+
this.conn.add(pgm.toXML());
109+
var async = cb && xt.getClass(cb) == "Function"; //If there is a callback function param, then it is in asynchronized mode.
110+
var rtValue; // The returned value.
111+
var stop = 0; // A flag indicating whether the process is finished.
112+
var retry = 0; // How many times we have retried.
113+
function toJson(str) { // Convert the XML output into JSON
114+
var output = xt.xmlToJson(str);
115+
if(output[0].hasOwnProperty("success") && output[0].success == true)
116+
rtValue = true;
117+
else
118+
rtValue = str;
119+
if(async) // If it is in asynchronized mode.
120+
cb(rtValue); // Run the call back function against the returned value.
121+
stop = 1;
122+
}
123+
function waitForResult() {
124+
retry++;
125+
if(stop == 0)
126+
setTimeout(waitForResult, retryInterval); // Check whether the result is retrieved
127+
else if(retry >= retryTimes)
128+
return timeoutMsg;
129+
else
130+
return rtValue;
131+
}
132+
this.conn.run(toJson, !async); // Post the input XML and get the response.
133+
if(!async) // If it is in synchronized mode.
134+
return waitForResult(); // Run the user defined call back function against the returned value.
135+
}
136+
137+
exports.iDataQueue = iDataQueue;

0 commit comments

Comments
 (0)