services.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  1. const express = require("express");
  2. const execSync = require('child_process').execSync;
  3. var parser = require('xml2json');
  4. const fs = require('fs');
  5. var cors = require('cors');
  6. const bodyParser = require("body-parser");
  7. var mysql = require('mysql2/promise');
  8. const bluebird = require('bluebird');
  9. const app = express();
  10. app.use(cors());
  11. const port = 3001;
  12. app.use(bodyParser.urlencoded({ extended: false }));
  13. app.use(bodyParser.json());
  14. let conf = {
  15. connectionLimit : 10,
  16. host : '127.0.0.1',
  17. user : 'ds',
  18. password : 'EmcoAdmin!',
  19. database : 'modeler',
  20. Promise: bluebird
  21. }
  22. const jsn = require("./base.json");
  23. const di = require("./di.json");
  24. const ia = require("./ia.json");
  25. const mach = require("./machinery.json");
  26. const mt = require("./mt.json");
  27. let ns_array = [];
  28. let nsray = [];
  29. nsray.push(jsn);
  30. nsray.push(di);
  31. nsray.push(ia);
  32. nsray.push(mach);
  33. nsray.push(mt);
  34. /*
  35. async function gen_query(sql, params){
  36. const connection = await mysql.createConnection(conf);
  37. const [results, ] = await connection.execute(sql, params);
  38. //console.log(results);
  39. return results;
  40. }*/
  41. function database_connection() {
  42. pool = mysql.createPool(conf);
  43. pool.getConnection(function(err, connection) {
  44. if(err) {
  45. logger.error('[ERROR] Connecting to database "' + err.toString() + '"');
  46. setTimeout(function() { database_connection(); }, 2500);
  47. }
  48. else
  49. {
  50. pool.query('SET NAMES utf8');
  51. pool.query('SET CHARACTER SET utf8');
  52. logger.trace('[INFO] Connected to database and set utf8!');
  53. }
  54. })};
  55. database_connection();
  56. function inverse(dev){
  57. if("IsForward" in dev){
  58. if(dev.IsForward === "false"){
  59. return true;
  60. }else{
  61. return false;
  62. }
  63. }else{
  64. return false;
  65. }
  66. }
  67. function forward(dev){
  68. var b = true;
  69. if("IsForward" in dev){
  70. if(dev.IsForward === "false"){
  71. b = false;
  72. }
  73. }else{
  74. b = true;
  75. }
  76. return b;
  77. }
  78. function sortNS(files){
  79. let nsets = [];
  80. for(let x = 0; x<files.length; x++){
  81. if("RequiredModel" in files[x].UANodeSet.Models.Model){
  82. if(Array.isArray(files[x].UANodeSet.Models.Model.RequiredModel)){
  83. var len = files[x].UANodeSet.Models.Model.RequiredModel.length;
  84. for(let y = 0; y < len; y++){
  85. files[x].UANodeSet.Models.Model.RequiredModel[y]
  86. }
  87. }else{
  88. }
  89. }else{
  90. nsets.push(files[x].UANodeSet.Models.Model.ModelUri);
  91. }
  92. }
  93. }
  94. function get_Children(jsnob, nid, ret_obj){
  95. const entities = ['UAObjectType','UAObject','UAVariableType','UAVariable', 'UADataType', 'UAReferenceType', 'UAMethod'];
  96. const set = jsnob.UANodeSet;
  97. for(let y = 0; y< entities.length; y++){
  98. if(entities[y] in set){
  99. try{
  100. const entry = set[entities[y]];
  101. if(Array.isArray(entry)){
  102. for (let i = 0; i < entry.length;i++){
  103. if(Object.keys(entry[i].References).length === 0){
  104. }else{
  105. if(Array.isArray(entry[i].References.Reference)){
  106. for (let x = 0; x < entry[i].References.Reference.length;x++){
  107. if(entry[i].References.Reference[x].$t === nid){
  108. if(inverse(entry[i].References.Reference[x])){
  109. let zobj= overwriteNode(entry[i], nid, entities[y], getIndexArray(jsnob));
  110. if(!checkDouble(zobj,ret_obj)){
  111. ret_obj.push(zobj);
  112. }
  113. }
  114. }
  115. }
  116. }else{
  117. if(entry[i].References.Reference.$t === nid){
  118. if(inverse(entry[i].References.Reference)){
  119. let zobj= overwriteNode(entry[i], nid, entities[y], getIndexArray(jsnob));
  120. if(!checkDouble(zobj,ret_obj)){
  121. ret_obj.push(zobj);
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }else{
  129. if(Object.keys(entry.References).length === 0){
  130. }else{
  131. if(Array.isArray(entry.References.Reference)){
  132. for (let x = 0; x < entry.References.Reference.length;x++){
  133. if(entry.References.Reference[x].$t === nid){
  134. if(inverse(entry.References.Reference[x])){
  135. let zobj= overwriteNode(entry, nid, entities[y], getIndexArray(jsnob));
  136. if(!checkDouble(zobj,ret_obj)){
  137. ret_obj.push(zobj);
  138. }
  139. }
  140. }
  141. }
  142. }else{
  143. if(entry.References.Reference.$t === nid){
  144. if(inverse(entry.References.Reference)){
  145. let zobj= overwriteNode(entry, nid, entities[i], getIndexArray(jsnob));
  146. if(!checkDouble(zobj,ret_obj)){
  147. ret_obj.push(zobj);
  148. }
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }catch(err){
  155. console.log(err);
  156. }
  157. }
  158. }
  159. }
  160. function getAllChildren(nid, ret_obj){
  161. for(let ix = 0; ix < ns_array.length; ix++){
  162. get_Children(ns_array[ix][0], nid, ret_obj);
  163. }
  164. }
  165. function getIndexObj(jsnob, ns){
  166. var uri = ns.UANodeSet.Models.Model.ModelUri;
  167. if(uri == "http://opcfoundation.org/UA/"){
  168. return 0;
  169. }
  170. console.log(uri);
  171. let uris = {};
  172. if(jsnob.UANodeSet.NamespaceUris != undefined){
  173. uris = jsnob.UANodeSet.NamespaceUris.Uri;
  174. console.log(uris);
  175. }else{
  176. return 0;
  177. }
  178. for(let i = 0; i < uris.length; i++){
  179. console.log(uris[i]);
  180. if(uris[i] == uri){
  181. return i+1;
  182. }
  183. }
  184. return undefined;
  185. }
  186. function getIndexName(jsnob, name){
  187. if(name == "http://opcfoundation.org/UA/"){
  188. return 0;
  189. }
  190. let uris = {};
  191. if(jsnob.UANodeSet.NamespaceUris != undefined){
  192. uris = jsnob.UANodeSet.NamespaceUris.Uri;
  193. }else{
  194. return 0;
  195. }
  196. for(let i = 0; i < uris.length; i++){
  197. if(uris[i] == name){
  198. return i+1;
  199. }
  200. }
  201. return undefined;
  202. }
  203. function getIndexArray(tobj){
  204. for(let i = 0; i < ns_array.length;i++){
  205. console.log(ns_array[i][1]);
  206. if(tobj.UANodeSet.Models.Model.ModelUri === ns_array[i][0].UANodeSet.Models.Model.ModelUri){
  207. return i;
  208. }
  209. }
  210. return undefined;
  211. }
  212. function getNode(jsnob, ns, id){
  213. let uris = {};
  214. var ns_uri = '';
  215. if(jsnob.UANodeSet.NamespaceUris){
  216. uris = jsnob.UANodeSet.NamespaceUris.Uri;
  217. ns_uri = uris[ns-1];
  218. }
  219. for(let i = 0; i < ns_array.length; i++){
  220. if(ns_array[i][0].UANodeSet.Models.Model.ModelUri == ns_uri){
  221. return i;
  222. }
  223. }
  224. return -1;
  225. }
  226. function overwriteNode(nobj, nid, nc, ns){
  227. var nclass = "";
  228. switch(nc){
  229. case "UAObjectType":
  230. case "UAObject":
  231. case "UAVariableType":
  232. case "UADataType":
  233. case "UAReferenceType": nclass = "Object"; break;
  234. case "UAVariable": nclass = "Variable"; break;
  235. case "UAMethod": nclass = "Method"; break;
  236. default: nclass = "Object";
  237. }
  238. const node = {
  239. id:nobj.NodeId,
  240. text:nobj.DisplayName,
  241. children: true,
  242. data:{
  243. browsename: nobj.BrowseName,
  244. namespace: ns,
  245. elementclass: nc,
  246. nodeclass: nclass,
  247. parentNode: nid,
  248. parentid: "ParentNodeId" in nobj ? nobj.ParentNodeId : null,
  249. description: "Description" in nobj ? nobj.Description : null,
  250. notifier: "EventNotifier" in nobj ? nobj.EventNotifier : null, //Object
  251. isabstract: "IsAbstract" in nobj ? nobj.IsAbstract : null, //ObjectType
  252. datatype: "DataType" in nobj ? nobj.DataType : null, //Variable
  253. value: "Value" in nobj ? nobj.Value : null, //Variable
  254. arraydimensions: "ArrayDimensions" in nobj ? nobj.ArrayDimensions : null, //Variable
  255. references: "References" in nobj ? nobj.References : null
  256. }
  257. }
  258. return node;
  259. }
  260. function searchNode(id){
  261. const entities = ['UAObjectType','UAObject','UAVariableType','UAVariable', 'UADataType', 'UAReferenceType', 'UAMethod']; //7
  262. var nid = "";
  263. var jsnob = {};
  264. if(id.includes("ns=")){
  265. var ns = id.substring(id.length - 4);
  266. const ns1 = ns.split(";");
  267. var nsidx = parseInt(ns1[0]);
  268. jsnob = ns_array[nsidx][0];
  269. }else{
  270. nid = id;
  271. jsnob = ns_array[0][0];
  272. }
  273. const set = jsnob.UANodeSet;
  274. for(let i = 0; i< entities.length; i++){
  275. if(entities[i] in set){
  276. console.log(set.Models.Model.ModelUri+" has a "+entities[i]);
  277. if(Array.isArray(set[entities[i]])){
  278. for(let x = 0; x < set[entities[i]].length;x++){
  279. if(set[entities[i]][x].NodeId === nid){
  280. let nobj = set[entities[i]][x];
  281. const node = overwriteNode(nobj, null, entities[i], getIndexArray(jsnob));
  282. return node;
  283. }
  284. }
  285. }
  286. }
  287. }
  288. return null;
  289. }
  290. function p2json(name, shorty){
  291. try{
  292. const nn = name+".xml";
  293. var nnn = shorty+".json";
  294. fs.readFile( nn, function(err, data){
  295. //fs.readFile( "Opc.Ua.NodeSet2.xml", function(err, data){
  296. let jsn = parser.toJson(data);
  297. fs.writeFileSync(nnn, jsn);
  298. });
  299. }catch(err){
  300. console.log('not work');}
  301. }
  302. /*
  303. function listObjType(){
  304. var keys = [];
  305. console.log("ObjectTypes:");
  306. let obj = jsn.UANodeSet.UAObjectType; //base
  307. var sz = obj.length;
  308. console.log(sz);
  309. for(let i = 0; i < sz; i++){
  310. let arr = Object.keys(obj[i]);
  311. for(let x = 0; x < arr.length; x++){
  312. if(!keys.includes(arr[x])){
  313. keys.push(arr[x]);
  314. }
  315. }
  316. }
  317. obj = di.UANodeSet.UAObjectType; //base
  318. sz = obj.length;
  319. console.log(sz);
  320. for(let i = 0; i < sz; i++){
  321. let arr = Object.keys(obj[i]);
  322. for(let x = 0; x < arr.length; x++){
  323. if(!keys.includes(arr[x])){
  324. keys.push(arr[x]);
  325. }
  326. }
  327. }
  328. obj = ia.UANodeSet.UAObjectType; //base
  329. sz = obj.length;
  330. console.log(sz);
  331. for(let i = 0; i < sz; i++){
  332. let arr = Object.keys(obj[i]);
  333. for(let x = 0; x < arr.length; x++){
  334. if(!keys.includes(arr[x])){
  335. keys.push(arr[x]);
  336. }
  337. }
  338. }
  339. obj = mach.UANodeSet.UAObjectType; //base
  340. sz = obj.length;
  341. console.log(sz);
  342. for(let i = 0; i < sz; i++){
  343. let arr = Object.keys(obj[i]);
  344. for(let x = 0; x < arr.length; x++){
  345. if(!keys.includes(arr[x])){
  346. keys.push(arr[x]);
  347. }
  348. }
  349. }
  350. obj = mt.UANodeSet.UAObjectType; //base
  351. sz = obj.length;
  352. console.log(sz);
  353. for(let i = 0; i < sz; i++){
  354. let arr = Object.keys(obj[i]);
  355. for(let x = 0; x < arr.length; x++){
  356. if(!keys.includes(arr[x])){
  357. keys.push(arr[x]);
  358. }
  359. }
  360. }
  361. console.log(keys);
  362. }
  363. listObjType();
  364. function listObj(){
  365. var keys = [];
  366. console.log("Objects:");
  367. let obj = jsn.UANodeSet.UAObject; //base
  368. var sz = obj.length;
  369. console.log(sz);
  370. for(let i = 0; i < sz; i++){
  371. let arr = Object.keys(obj[i]);
  372. for(let x = 0; x < arr.length; x++){
  373. if(!keys.includes(arr[x])){
  374. keys.push(arr[x]);
  375. }
  376. }
  377. }
  378. obj = di.UANodeSet.UAObject; //base
  379. sz = obj.length;
  380. console.log(sz);
  381. for(let i = 0; i < sz; i++){
  382. let arr = Object.keys(obj[i]);
  383. for(let x = 0; x < arr.length; x++){
  384. if(!keys.includes(arr[x])){
  385. keys.push(arr[x]);
  386. }
  387. }
  388. }
  389. obj = ia.UANodeSet.UAObject; //base
  390. sz = obj.length;
  391. console.log(sz);
  392. for(let i = 0; i < sz; i++){
  393. let arr = Object.keys(obj[i]);
  394. for(let x = 0; x < arr.length; x++){
  395. if(!keys.includes(arr[x])){
  396. keys.push(arr[x]);
  397. }
  398. }
  399. }
  400. obj = mach.UANodeSet.UAObject; //base
  401. sz = obj.length;
  402. console.log(sz);
  403. for(let i = 0; i < sz; i++){
  404. let arr = Object.keys(obj[i]);
  405. for(let x = 0; x < arr.length; x++){
  406. if(!keys.includes(arr[x])){
  407. keys.push(arr[x]);
  408. }
  409. }
  410. }
  411. obj = mt.UANodeSet.UAObject; //base
  412. sz = obj.length;
  413. console.log(sz);
  414. for(let i = 0; i < sz; i++){
  415. let arr = Object.keys(obj[i]);
  416. for(let x = 0; x < arr.length; x++){
  417. if(!keys.includes(arr[x])){
  418. keys.push(arr[x]);
  419. }
  420. }
  421. }
  422. console.log(keys);
  423. }
  424. listObj();
  425. function listVar(){
  426. var keys = [];
  427. console.log("Variables:");
  428. let obj = jsn.UANodeSet.UAVariable; //base
  429. var sz = obj.length;
  430. console.log(sz);
  431. for(let i = 0; i < sz; i++){
  432. let arr = Object.keys(obj[i]);
  433. for(let x = 0; x < arr.length; x++){
  434. if(!keys.includes(arr[x])){
  435. keys.push(arr[x]);
  436. }
  437. }
  438. }
  439. obj = di.UANodeSet.UAVariable; //base
  440. sz = obj.length;
  441. console.log(sz);
  442. for(let i = 0; i < sz; i++){
  443. let arr = Object.keys(obj[i]);
  444. for(let x = 0; x < arr.length; x++){
  445. if(!keys.includes(arr[x])){
  446. keys.push(arr[x]);
  447. }
  448. }
  449. }
  450. obj = ia.UANodeSet.UAVariable; //base
  451. sz = obj.length;
  452. console.log(sz);
  453. for(let i = 0; i < sz; i++){
  454. let arr = Object.keys(obj[i]);
  455. for(let x = 0; x < arr.length; x++){
  456. if(!keys.includes(arr[x])){
  457. keys.push(arr[x]);
  458. }
  459. }
  460. }
  461. obj = mach.UANodeSet.UAVariable; //base
  462. sz = obj.length;
  463. console.log(sz);
  464. for(let i = 0; i < sz; i++){
  465. let arr = Object.keys(obj[i]);
  466. for(let x = 0; x < arr.length; x++){
  467. if(!keys.includes(arr[x])){
  468. keys.push(arr[x]);
  469. }
  470. }
  471. }
  472. obj = mt.UANodeSet.UAVariable; //base
  473. sz = obj.length;
  474. console.log(sz);
  475. for(let i = 0; i < sz; i++){
  476. let arr = Object.keys(obj[i]);
  477. for(let x = 0; x < arr.length; x++){
  478. if(!keys.includes(arr[x])){
  479. keys.push(arr[x]);
  480. }
  481. }
  482. }
  483. console.log(keys);
  484. }
  485. listVar();
  486. function listVarTypes(){
  487. var keys = [];
  488. console.log("VariableTypes:");
  489. let obj = jsn.UANodeSet.UAVariableType; //base
  490. var sz = obj.length;
  491. console.log(sz);
  492. for(let i = 0; i < sz; i++){
  493. let arr = Object.keys(obj[i]);
  494. for(let x = 0; x < arr.length; x++){
  495. if(!keys.includes(arr[x])){
  496. keys.push(arr[x]);
  497. }
  498. }
  499. }
  500. obj = di.UANodeSet.UAVariableType; //base
  501. sz = obj.length;
  502. console.log(sz);
  503. for(let i = 0; i < sz; i++){
  504. let arr = Object.keys(obj[i]);
  505. for(let x = 0; x < arr.length; x++){
  506. if(!keys.includes(arr[x])){
  507. keys.push(arr[x]);
  508. }
  509. }
  510. }
  511. obj = ia.UANodeSet.UAVariableType; //base
  512. sz = obj.length;
  513. console.log(sz);
  514. for(let i = 0; i < sz; i++){
  515. let arr = Object.keys(obj[i]);
  516. for(let x = 0; x < arr.length; x++){
  517. if(!keys.includes(arr[x])){
  518. keys.push(arr[x]);
  519. }
  520. }
  521. }
  522. obj = mach.UANodeSet.UAVariableType; //base
  523. if(obj !== undefined){
  524. if(Array.isArray(obj)){
  525. sz = obj.length;
  526. console.log(sz);
  527. for(let i = 0; i < sz; i++){
  528. let arr = Object.keys(obj[i]);
  529. for(let x = 0; x < arr.length; x++){
  530. if(!keys.includes(arr[x])){
  531. keys.push(arr[x]);
  532. }
  533. }
  534. }}else{
  535. let arr = Object.keys(obj);
  536. for(let x = 0; x < arr.length; x++){
  537. if(!keys.includes(arr[x])){
  538. keys.push(arr[x]);
  539. }
  540. }
  541. }
  542. }
  543. obj = mt.UANodeSet.UAVariableType; //base
  544. sz = obj.length;
  545. console.log(sz);
  546. for(let i = 0; i < sz; i++){
  547. let arr = Object.keys(obj[i]);
  548. for(let x = 0; x < arr.length; x++){
  549. if(!keys.includes(arr[x])){
  550. keys.push(arr[x]);
  551. }
  552. }
  553. }
  554. console.log(keys);
  555. }
  556. listVarTypes();
  557. function listMethod(){
  558. var keys = [];
  559. console.log("Methods:");
  560. let obj = jsn.UANodeSet.UAMethod; //base
  561. var sz = obj.length;
  562. console.log(sz);
  563. for(let i = 0; i < sz; i++){
  564. let arr = Object.keys(obj[i]);
  565. for(let x = 0; x < arr.length; x++){
  566. if(!keys.includes(arr[x])){
  567. keys.push(arr[x]);
  568. }
  569. }
  570. }
  571. obj = di.UANodeSet.UAMethod; //base
  572. sz = obj.length;
  573. console.log(sz);
  574. for(let i = 0; i < sz; i++){
  575. let arr = Object.keys(obj[i]);
  576. for(let x = 0; x < arr.length; x++){
  577. if(!keys.includes(arr[x])){
  578. keys.push(arr[x]);
  579. }
  580. }
  581. }
  582. obj = ia.UANodeSet.UAMethod; //base
  583. sz = obj.length;
  584. console.log(sz);
  585. for(let i = 0; i < sz; i++){
  586. let arr = Object.keys(obj[i]);
  587. for(let x = 0; x < arr.length; x++){
  588. if(!keys.includes(arr[x])){
  589. keys.push(arr[x]);
  590. }
  591. }
  592. }
  593. obj = mach.UANodeSet.UAMethod; //base
  594. if(obj !== undefined){
  595. if(Array.isArray(obj)){
  596. sz = obj.length;
  597. console.log(sz);
  598. for(let i = 0; i < sz; i++){
  599. let arr = Object.keys(obj[i]);
  600. for(let x = 0; x < arr.length; x++){
  601. if(!keys.includes(arr[x])){
  602. keys.push(arr[x]);
  603. }
  604. }
  605. }}else{
  606. let arr = Object.keys(obj);
  607. for(let x = 0; x < arr.length; x++){
  608. if(!keys.includes(arr[x])){
  609. keys.push(arr[x]);
  610. }
  611. }
  612. }}
  613. obj = mt.UANodeSet.UAMethod; //base
  614. if(obj !== undefined){
  615. if(Array.isArray(obj)){
  616. sz = obj.length;
  617. console.log(sz);
  618. for(let i = 0; i < sz; i++){
  619. let arr = Object.keys(obj[i]);
  620. for(let x = 0; x < arr.length; x++){
  621. if(!keys.includes(arr[x])){
  622. keys.push(arr[x]);
  623. }
  624. }
  625. }}else{
  626. let arr = Object.keys(obj);
  627. for(let x = 0; x < arr.length; x++){
  628. if(!keys.includes(arr[x])){
  629. keys.push(arr[x]);
  630. }
  631. }
  632. }}
  633. console.log(keys);
  634. }
  635. listMethod();
  636. function listDataType(){
  637. var keys = [];
  638. console.log("DataType:");
  639. let obj = jsn.UANodeSet.UADataType; //base
  640. var sz = obj.length;
  641. console.log(sz);
  642. for(let i = 0; i < sz; i++){
  643. let arr = Object.keys(obj[i]);
  644. for(let x = 0; x < arr.length; x++){
  645. if(!keys.includes(arr[x])){
  646. keys.push(arr[x]);
  647. }
  648. }
  649. }
  650. obj = di.UANodeSet.UADataType; //base
  651. sz = obj.length;
  652. console.log(sz);
  653. for(let i = 0; i < sz; i++){
  654. let arr = Object.keys(obj[i]);
  655. for(let x = 0; x < arr.length; x++){
  656. if(!keys.includes(arr[x])){
  657. keys.push(arr[x]);
  658. }
  659. }
  660. }
  661. obj = ia.UANodeSet.UADataType; //base
  662. sz = obj.length;
  663. console.log(sz);
  664. for(let i = 0; i < sz; i++){
  665. let arr = Object.keys(obj[i]);
  666. for(let x = 0; x < arr.length; x++){
  667. if(!keys.includes(arr[x])){
  668. keys.push(arr[x]);
  669. }
  670. }
  671. }
  672. obj = mach.UANodeSet.UADataType; //base
  673. if(obj !== undefined){
  674. if(Array.isArray(obj)){
  675. sz = obj.length;
  676. console.log(sz);
  677. for(let i = 0; i < sz; i++){
  678. let arr = Object.keys(obj[i]);
  679. for(let x = 0; x < arr.length; x++){
  680. if(!keys.includes(arr[x])){
  681. keys.push(arr[x]);
  682. }
  683. }
  684. }}else{
  685. let arr = Object.keys(obj);
  686. for(let x = 0; x < arr.length; x++){
  687. if(!keys.includes(arr[x])){
  688. keys.push(arr[x]);
  689. }
  690. }
  691. }}
  692. obj = mt.UANodeSet.UADataType; //base
  693. sz = obj.length;
  694. console.log(sz);
  695. for(let i = 0; i < sz; i++){
  696. let arr = Object.keys(obj[i]);
  697. for(let x = 0; x < arr.length; x++){
  698. if(!keys.includes(arr[x])){
  699. keys.push(arr[x]);
  700. }
  701. }
  702. }
  703. console.log(keys);
  704. }
  705. listDataType();
  706. function listRefType(){
  707. var keys = [];
  708. console.log("ReferenceTypes:");
  709. let obj = jsn.UANodeSet.UAReferenceType; //base
  710. var sz = obj.length;
  711. console.log(sz);
  712. for(let i = 0; i < sz; i++){
  713. let arr = Object.keys(obj[i]);
  714. for(let x = 0; x < arr.length; x++){
  715. if(!keys.includes(arr[x])){
  716. keys.push(arr[x]);
  717. }
  718. }
  719. }
  720. obj = di.UANodeSet.UAReferenceType; //base
  721. sz = obj.length;
  722. console.log(sz);
  723. for(let i = 0; i < sz; i++){
  724. let arr = Object.keys(obj[i]);
  725. for(let x = 0; x < arr.length; x++){
  726. if(!keys.includes(arr[x])){
  727. keys.push(arr[x]);
  728. }
  729. }
  730. }
  731. obj = ia.UANodeSet.UAReferenceType; //base
  732. sz = obj.length;
  733. console.log(sz);
  734. for(let i = 0; i < sz; i++){
  735. let arr = Object.keys(obj[i]);
  736. for(let x = 0; x < arr.length; x++){
  737. if(!keys.includes(arr[x])){
  738. keys.push(arr[x]);
  739. }
  740. }
  741. }
  742. obj = mach.UANodeSet.UAReferenceType; //base
  743. if(obj !== undefined){
  744. if(Array.isArray(obj)){
  745. sz = obj.length;
  746. console.log(sz);
  747. for(let i = 0; i < sz; i++){
  748. let arr = Object.keys(obj[i]);
  749. for(let x = 0; x < arr.length; x++){
  750. if(!keys.includes(arr[x])){
  751. keys.push(arr[x]);
  752. }
  753. }
  754. }}else{
  755. let arr = Object.keys(obj);
  756. for(let x = 0; x < arr.length; x++){
  757. if(!keys.includes(arr[x])){
  758. keys.push(arr[x]);
  759. }
  760. }
  761. }}
  762. obj = mt.UANodeSet.UAReferenceType; //base
  763. if(obj !== undefined){
  764. if(Array.isArray(obj)){
  765. sz = obj.length;
  766. console.log(sz);
  767. for(let i = 0; i < sz; i++){
  768. let arr = Object.keys(obj[i]);
  769. for(let x = 0; x < arr.length; x++){
  770. if(!keys.includes(arr[x])){
  771. keys.push(arr[x]);
  772. }
  773. }
  774. }}else{
  775. let arr = Object.keys(obj);
  776. for(let x = 0; x < arr.length; x++){
  777. if(!keys.includes(arr[x])){
  778. keys.push(arr[x]);
  779. }
  780. }
  781. }}
  782. console.log(keys);
  783. }
  784. listRefType();
  785. */
  786. let arref = [];
  787. async function checkRefs(obj, nid){
  788. try{
  789. var idx = 0;
  790. if(nid.includes('ns=')){
  791. var ix = nid.indexOf(';');
  792. var ns = nid.substring(3,ix);
  793. idx = parseInt(ns);
  794. }
  795. if(obj['References']){
  796. let refs = obj['References'].Reference;
  797. if(Array.isArray(refs)){
  798. for(let i = 0; i < refs.length; i++){
  799. var entry = refs[i];
  800. var nid_t = "";
  801. if(nid.includes('i=')){
  802. nid_t = 'Numeric';
  803. }else if(nid.includes('s=')){
  804. nid_t = 'String';
  805. }
  806. var nst = 0;
  807. console.log(entry);
  808. var target = "";
  809. if(entry['$t']){
  810. target = entry['$t'];
  811. if(target.includes('ns=')){
  812. var ix = target.indexOf(';');
  813. var ns = target.substring(3,ix);
  814. nst = parseInt(ns);
  815. }
  816. }
  817. var command = "INSERT INTO ns0references(nodeidorigin, nodeidtype, nsindex, referencetype, isforward, target, ns_target) VALUES ('"+nid+"', '"+nid_t+"', '"+idx+"', '"+entry['ReferenceType']+"', '"+entry['IsForward']+"', '"+target+"', '"+nst+"');";
  818. console.log(command);
  819. var ret = pool.query(command);
  820. }
  821. }else{
  822. var entry = refs;
  823. var nid_t = "";
  824. if(nid.includes('i=')){
  825. nid_t = 'Numeric';
  826. }else if(nid.includes('s=')){
  827. nid_t = 'String';
  828. }
  829. var nst = 0;
  830. console.log(entry);
  831. var target = "";
  832. if(entry['$t']){
  833. target = entry['$t'];
  834. if(target.includes('ns=')){
  835. var ix = target.indexOf(';');
  836. var ns = target.substring(3,ix);
  837. nst = parseInt(ns);
  838. }
  839. }
  840. var command = "INSERT INTO ns0references(nodeidorigin, nodeidtype, nsindex, referencetype, isforward, target, ns_target) VALUES ('"+nid+"', '"+nid_t+"', '"+idx+"', '"+entry['ReferenceType']+"', '"+entry['IsForward']+"', '"+target+"', '"+nst+"');";
  841. console.log(command);
  842. var ret = pool.query(command);
  843. }
  844. }
  845. }catch(err){
  846. console.log(err);
  847. }
  848. }
  849. app.get('/obj', async function(req, res){
  850. try{
  851. var key = req.body;
  852. let obj = jsn.UANodeSet.UAObject; //base
  853. if(Array.isArray(obj)){
  854. var sz = obj.length;
  855. for(let i = 0; i < sz; i++){
  856. var entry = obj[i];
  857. var nid = entry['NodeId'];
  858. var idx = 0;
  859. if(nid.includes('ns=')){
  860. var ix = nid.indexOf(';');
  861. var ns = nid.substring(3,ix);
  862. idx = parseInt(ns);
  863. }
  864. checkRefs(entry, nid);
  865. var nid_t = "";
  866. if(nid.includes('i=')){
  867. nid_t = 'Numeric';
  868. }else if(nid.includes('s=')){
  869. nid_t = 'String';
  870. }
  871. var eventnot = 0;
  872. if(entry['EventNotifier']){
  873. eventnot = parseInt(entry['EventNotifier']);
  874. }
  875. var command = "INSERT INTO ns0objects(nodeid, nodeidtype, nsindex, name, displayname, browsename, typedefinition, description, eventnotifier, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', 'TBD','"+entry['Description']+"', '"+eventnot+"', '"+entry['Documentation']+"');";
  876. console.log(command);
  877. var ret = pool.query(command);
  878. }
  879. }else{
  880. var entry = obj;
  881. var nid = entry['NodeId'];
  882. var idx = 0;
  883. if(nid.includes('ns=')){
  884. var ix = nid.indexOf(';');
  885. var ns = nid.substring(3,ix);
  886. idx = parseInt(ns);
  887. }
  888. checkRefs(entry, nid);
  889. var nid_t = "";
  890. if(nid.includes('i=')){
  891. nid_t = 'Numeric';
  892. }else if(nid.includes('s=')){
  893. nid_t = 'String';
  894. }
  895. var eventnot = 0;
  896. if(entry['EventNotifier']){
  897. eventnot = parseInt(entry['EventNotifier']);
  898. }
  899. var command = "INSERT INTO ns0objects(nodeid, nodeidtype, nsindex, name, displayname, browsename, typedefinition, description, eventnotifier, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', 'TBD','"+entry['Description']+"', '"+eventnot+"', '"+entry['Documentation']+"');";
  900. console.log(command);
  901. var ret = pool.query(command);
  902. }
  903. res.json({result:'OK',success:true});
  904. }catch(err){
  905. console.log(err);
  906. res.json({result:"NOK"});
  907. }
  908. })
  909. app.get('/objtypes', async function(req, res){
  910. try{
  911. var key = req.body;
  912. let obj = jsn.UANodeSet.UAObjectType; //base
  913. if(Array.isArray(obj)){
  914. var sz = obj.length;
  915. console.log(sz);
  916. for(let i = 0; i < sz; i++){
  917. var entry = obj[i];
  918. var nid = entry['NodeId'];
  919. var idx = 0;
  920. if(nid.includes('ns=')){
  921. var ix = nid.indexOf(';');
  922. var ns = nid.substring(3,ix);
  923. idx = parseInt(ns);
  924. }
  925. checkRefs(entry, nid);
  926. var nid_t = "";
  927. if(nid.includes('i=')){
  928. nid_t = 'Numeric';
  929. }else if(nid.includes('s=')){
  930. nid_t = 'String';
  931. }
  932. var isabstr = "TBD";
  933. if(entry['IsAbstract']){
  934. isabstr = entry['IsAbstract'];
  935. }
  936. var command = "INSERT INTO ns0objecttypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, isabstract, description, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','"+isabstr+"', '"+entry['Description']+"', '"+entry['Documentation']+"');";
  937. var ret = pool.query(command);
  938. }
  939. res.json({result:'OK',success:true});
  940. }else{
  941. var entry = obj;
  942. var nid = entry['NodeId'];
  943. var idx = 0;
  944. if(nid.includes('ns=')){
  945. var ix = nid.indexOf(';');
  946. var ns = nid.substring(3,ix);
  947. idx = parseInt(ns);
  948. }
  949. checkRefs(entry, nid);
  950. var nid_t = "";
  951. if(nid.includes('i=')){
  952. nid_t = 'Numeric';
  953. }else if(nid.includes('s=')){
  954. nid_t = 'String';
  955. }
  956. var isabstr = "TBD";
  957. if(entry['IsAbstract']){
  958. isabstr = entry['IsAbstract'];
  959. }
  960. var command = "INSERT INTO ns0objecttypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, isabstract, description, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','"+isabstr+"', '"+entry['Description']+"', '"+entry['Documentation']+"');";
  961. var ret = pool.query(command);
  962. res.json({result:'OK',success:true});
  963. }
  964. }catch(err){
  965. console.log(err);
  966. res.json({result:"NOK"});
  967. }
  968. })
  969. app.get('/var', async function(req, res){
  970. try{
  971. var key = req.body;
  972. let obj = jsn.UANodeSet.UAVariable; //base
  973. if(Array.isArray(obj)){
  974. var sz = obj.length;
  975. for(let i = 0; i < sz; i++){
  976. var entry = obj[i];
  977. var nid = entry['NodeId'];
  978. var idx = 0;
  979. if(nid.includes('ns=')){
  980. var ix = nid.indexOf(';');
  981. var ns = nid.substring(3,ix);
  982. idx = parseInt(ns);
  983. }
  984. checkRefs(entry, nid);
  985. var nid_t = "";
  986. if(nid.includes('i=')){
  987. nid_t = 'Numeric';
  988. }else if(nid.includes('s=')){
  989. nid_t = 'String';
  990. }
  991. var valrank = 0;
  992. if(entry['ValueRank']){
  993. valrank = entry['ValueRank'];
  994. }
  995. var arrdim = 0;
  996. if(entry['ArrayDimensions']){
  997. arrdim = entry['ArrayDimensions'];
  998. }
  999. var acclev = 0;
  1000. if(entry['AccessLevel']){
  1001. acclev = entry['AccessLevel'];
  1002. }
  1003. var minsamp = 0;
  1004. if(entry['MinimumSamplingInterval']){
  1005. minsamp = entry['MinimumSamplingInterval'];
  1006. }
  1007. var command = "INSERT INTO ns0variables(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, accesslevel, minsamplinginterval, releasestatus) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+acclev+"', '"+minsamp+"', '"+entry['ReleaseStatus']+"');";
  1008. console.log(command);
  1009. var ret = pool.query(command);
  1010. }
  1011. res.json({result:'OK',success:true});
  1012. }else{
  1013. var entry = obj;
  1014. var nid = entry['NodeId'];
  1015. var idx = 0;
  1016. if(nid.includes('ns=')){
  1017. var ix = nid.indexOf(';');
  1018. var ns = nid.substring(3,ix);
  1019. idx = parseInt(ns);
  1020. }
  1021. checkRefs(entry, nid);
  1022. var nid_t = "";
  1023. if(nid.includes('i=')){
  1024. nid_t = 'Numeric';
  1025. }else if(nid.includes('s=')){
  1026. nid_t = 'String';
  1027. }
  1028. var valrank = 0;
  1029. if(entry['ValueRank']){
  1030. valrank = entry['ValueRank'];
  1031. }
  1032. var arrdim = 0;
  1033. if(entry['ArrayDimensions']){
  1034. arrdim = entry['ArrayDimensions'];
  1035. }
  1036. var acclev = 0;
  1037. if(entry['AccessLevel']){
  1038. acclev = entry['AccessLevel'];
  1039. }
  1040. var minsamp = 0;
  1041. if(entry['MinimumSamplingInterval']){
  1042. minsamp = entry['MinimumSamplingInterval'];
  1043. }
  1044. var command = "INSERT INTO ns0variables(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, accesslevel, minsamplinginterval, releasestatus) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+acclev+"', '"+minsamp+"', '"+entry['ReleaseStatus']+"');";
  1045. console.log(command);
  1046. var ret = pool.query(command);
  1047. res.json({result:'OK',success:true});
  1048. }
  1049. }catch(err){
  1050. console.log(err);
  1051. res.json({result:"NOK"});
  1052. }
  1053. })
  1054. app.get('/vartypes', async function(req, res){
  1055. try{
  1056. var key = req.body;
  1057. let obj = jsn.UANodeSet.UAVariableType; //base
  1058. if(Array.isArray(obj)){
  1059. var sz = obj.length;
  1060. for(let i = 0; i < sz; i++){
  1061. console.log(obj[i]);
  1062. var entry = obj[i];
  1063. var nid = entry['NodeId'];
  1064. var idx = 0;
  1065. if(nid.includes('ns=')){
  1066. var ix = nid.indexOf(';');
  1067. var ns = nid.substring(3,ix);
  1068. idx = parseInt(ns);
  1069. }
  1070. checkRefs(entry, nid);
  1071. var nid_t = "";
  1072. if(nid.includes('i=')){
  1073. nid_t = 'Numeric';
  1074. }else if(nid.includes('s=')){
  1075. nid_t = 'String';
  1076. }
  1077. var valrank = 0;
  1078. if(entry['ValueRank']){
  1079. valrank = entry['ValueRank'];
  1080. }
  1081. var arrdim = 0;
  1082. if(entry['ArrayDimensions']){
  1083. console.log('Here');
  1084. console.log(entry['ArrayDimensions']);
  1085. arrdim = entry['ArrayDimensions'];
  1086. }
  1087. var isabstr = "TBD";
  1088. if(entry['IsAbstract']){
  1089. isabstr = entry['IsAbstract'];
  1090. }
  1091. var command = "INSERT INTO ns0variabletypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, isabstract, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+isabstr+"', '"+entry['Documentation']+"');";
  1092. console.log(command);
  1093. var ret = pool.query(command);
  1094. }
  1095. }else{
  1096. var entry = obj;
  1097. var nid = entry['NodeId'];
  1098. var idx = 0;
  1099. if(nid.includes('ns=')){
  1100. var ix = nid.indexOf(';');
  1101. var ns = nid.substring(3,ix);
  1102. idx = parseInt(ns);
  1103. }
  1104. checkRefs(entry, nid);
  1105. var nid_t = "";
  1106. if(nid.includes('i=')){
  1107. nid_t = 'Numeric';
  1108. }else if(nid.includes('s=')){
  1109. nid_t = 'String';
  1110. }
  1111. var valrank = 0;
  1112. if(entry['ValueRank']){
  1113. valrank = entry['ValueRank'];
  1114. }
  1115. var arrdim = 0;
  1116. if(entry['ArrayDimensions']){
  1117. console.log('Here');
  1118. console.log(entry['ArrayDimensions']);
  1119. arrdim = entry['ArrayDimensions'];
  1120. }
  1121. var isabstr = "TBD";
  1122. if(entry['IsAbstract']){
  1123. isabstr = entry['IsAbstract'];
  1124. }
  1125. var command = "INSERT INTO ns0variabletypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, datatype, valuerank, arraydimensions, isabstract, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','#', '"+entry['Description']+"', '"+entry['DataType']+"', '"+valrank+"', '"+arrdim+"', '"+isabstr+"', '"+entry['Documentation']+"');";
  1126. console.log(command);
  1127. var ret = pool.query(command);
  1128. }
  1129. res.json({result:'OK',success:true});
  1130. }catch(err){
  1131. console.log(err);
  1132. res.json({result:"NOK"});
  1133. }
  1134. })
  1135. app.get('/methods', async function(req, res){
  1136. try{
  1137. var key = req.body;
  1138. let obj = jsn.UANodeSet.UAMethod; //base
  1139. if(Array.isArray(obj)){
  1140. var sz = obj.length;
  1141. for(let i = 0; i < sz; i++){
  1142. var entry = obj[i];
  1143. var nid = entry['NodeId'];
  1144. var idx = 0;
  1145. if(nid.includes('ns=')){
  1146. var ix = nid.indexOf(';');
  1147. var ns = nid.substring(3,ix);
  1148. idx = parseInt(ns);
  1149. }
  1150. checkRefs(entry, nid);
  1151. var nid_t = "";
  1152. if(nid.includes('i=')){
  1153. nid_t = 'Numeric';
  1154. }else if(nid.includes('s=')){
  1155. nid_t = 'String';
  1156. }
  1157. var command = "INSERT INTO ns0methods(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, methoddeclarationid) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['MethodDeclarationId']+"');";
  1158. console.log(command);
  1159. var ret = pool.query(command);
  1160. }
  1161. }else{
  1162. var entry = obj;
  1163. var nid = entry['NodeId'];
  1164. var idx = 0;
  1165. if(nid.includes('ns=')){
  1166. var ix = nid.indexOf(';');
  1167. var ns = nid.substring(3,ix);
  1168. idx = parseInt(ns);
  1169. }
  1170. checkRefs(entry, nid);
  1171. var nid_t = "";
  1172. if(nid.includes('i=')){
  1173. nid_t = 'Numeric';
  1174. }else if(nid.includes('s=')){
  1175. nid_t = 'String';
  1176. }
  1177. var command = "INSERT INTO ns0methods(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, methoddeclarationid) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['MethodDeclarationId']+"');";
  1178. console.log(command);
  1179. var ret = pool.query(command);
  1180. }
  1181. res.json({result:'OK',success:true});
  1182. }catch(err){
  1183. console.log(err);
  1184. res.json({result:"NOK"});
  1185. }
  1186. })
  1187. app.get('/datatypes', async function(req, res){
  1188. try{
  1189. var key = req.body;
  1190. let obj = jsn.UANodeSet.UADataType; //base
  1191. if(Array.isArray(obj)){
  1192. var sz = obj.length;
  1193. for(let i = 0; i < sz; i++){
  1194. var entry = obj[i];
  1195. var nid = entry['NodeId'];
  1196. var idx = 0;
  1197. if(nid.includes('ns=')){
  1198. var ix = nid.indexOf(';');
  1199. var ns = nid.substring(3,ix);
  1200. idx = parseInt(ns);
  1201. }
  1202. checkRefs(entry, nid);
  1203. var nid_t = "";
  1204. if(nid.includes('i=')){
  1205. nid_t = 'Numeric';
  1206. }else if(nid.includes('s=')){
  1207. nid_t = 'String';
  1208. }
  1209. var command = "INSERT INTO ns0datatypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, isabstract, definition, releasestatus, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Definition']+"', '"+entry['ReleaseStatus']+"', '"+entry['Documentation']+"');";
  1210. console.log(command);
  1211. var ret = pool.query(command);
  1212. }
  1213. }else{
  1214. var entry = obj;
  1215. var nid = entry['NodeId'];
  1216. var idx = 0;
  1217. if(nid.includes('ns=')){
  1218. var ix = nid.indexOf(';');
  1219. var ns = nid.substring(3,ix);
  1220. idx = parseInt(ns);
  1221. }
  1222. checkRefs(entry, nid);
  1223. var nid_t = "";
  1224. if(nid.includes('i=')){
  1225. nid_t = 'Numeric';
  1226. }else if(nid.includes('s=')){
  1227. nid_t = 'String';
  1228. }
  1229. var command = "INSERT INTO ns0datatypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, description, isabstract, definition, releasestatus, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Definition']+"', '"+entry['ReleaseStatus']+"', '"+entry['Documentation']+"');";
  1230. console.log(command);
  1231. var ret = pool.query(command);
  1232. }
  1233. res.json({result:'OK',success:true});
  1234. }catch(err){
  1235. console.log(err);
  1236. res.json({result:"NOK"});
  1237. }
  1238. })
  1239. app.get('/reftypes', async function(req, res){
  1240. try{
  1241. var key = req.body;
  1242. var len = nsray.length;
  1243. for(let m = 1; m < nsray.length; m++){
  1244. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"referencetypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, inversename VARCHAR(300), symmetric VARCHAR(10) DEFAULT 'TBD', nodeclass VARCHAR(50) DEFAULT 'ReferenceType', nsindex INT DEFAULT NULL, nsurl VARCHAR(120) DEFAULT 'http://opcfoundation.org/UA/', displayname VARCHAR(300) NOT NULL, browsename VARCHAR(300) NOT NULL, description VARCHAR(300), isabstract VARCHAR(10) DEFAULT 'TBD', parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse INT DEFAULT NULL, documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1245. var ret = await pool.query(command);
  1246. let obj = nsray[m].UANodeSet.UAReferenceType; //base
  1247. if(nsray[m].UANodeSet.UAReferenceType){
  1248. if(Array.isArray(obj)){
  1249. var sz = obj.length;
  1250. for(let i = 0; i < sz; i++){
  1251. var entry = obj[i];
  1252. var nid = entry['NodeId'];
  1253. var idx = m;
  1254. if(nid.includes('ns=')){
  1255. var ix = nid.indexOf(';');
  1256. var ns = nid.substring(3,ix);
  1257. idx = parseInt(ns);
  1258. }
  1259. checkRefs(entry, nid);
  1260. var nid_t = "";
  1261. if(nid.includes('i=')){
  1262. nid_t = 'Numeric';
  1263. }else if(nid.includes('s=')){
  1264. nid_t = 'String';
  1265. }
  1266. command = "INSERT INTO ns"+m+"referencetypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, description, isabstract, symmetric, inversename, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+nsray[m].UANodeSet.Models.Model.ModelUri+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Symmetric']+"', '"+entry['InverseName']+"', '"+entry['Documentation']+"');";
  1267. console.log(command);
  1268. ret = pool.query(command);
  1269. }
  1270. }else{
  1271. var entry = obj;
  1272. var nid = entry['NodeId'];
  1273. var idx = m;
  1274. if(nid.includes('ns=')){
  1275. var ix = nid.indexOf(';');
  1276. var ns = nid.substring(3,ix);
  1277. idx = parseInt(ns);
  1278. }
  1279. checkRefs(entry, nid);
  1280. var nid_t = "";
  1281. if(nid.includes('i=')){
  1282. nid_t = 'Numeric';
  1283. }else if(nid.includes('s=')){
  1284. nid_t = 'String';
  1285. }
  1286. command = "INSERT INTO ns"+m+"referencetypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, description, isabstract, symmetric, inversename, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+nsray[m].UANodeSet.Models.Model.ModelUri+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '#', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Symmetric']+"', '"+entry['InverseName']+"', '"+entry['Documentation']+"');";
  1287. console.log(command);
  1288. ret = pool.query(command);
  1289. }
  1290. }
  1291. }
  1292. res.json({result:'OK',success:true});
  1293. }catch(err){
  1294. console.log(err);
  1295. res.json({result:"NOK"});
  1296. }
  1297. })
  1298. app.get('/namesp', async function(req, res){
  1299. try{
  1300. var key = req.body;
  1301. var sz = nsray.length;
  1302. //-------ns0--------------
  1303. var command = "CREATE TABLE IF NOT EXISTS ns0depends(id INT AUTO_INCREMENT, nsindex INT DEFAULT NULL, nsurl VARCHAR(120), publicationdate VARCHAR(120), version VARCHAR(100), PRIMARY KEY(id));";
  1304. var ret = await pool.query(command);
  1305. command = "INSERT INTO ns0depends(nsindex, nsurl, publicationdate, version) VALUES ('0','http://opcfoundation.org/UA/','"+jsn.UANodeSet.Models.Model['PublicationDate']+"','"+jsn.UANodeSet.Models.Model['Version']+"');";
  1306. ret = pool.query(command);
  1307. //----------------ns0--------------
  1308. for(let i = 1; i < sz; i++){
  1309. var entry0 = nsray[i].UANodeSet.NamespaceUris.Uri;
  1310. command = "CREATE TABLE IF NOT EXISTS ns"+i+"depends(id INT AUTO_INCREMENT, nsindex INT DEFAULT NULL, nsurl VARCHAR(120), publicationdate VARCHAR(120), version VARCHAR(100), PRIMARY KEY(id));";
  1311. ret = await pool.query(command);
  1312. command = "INSERT INTO ns"+i+"depends(nsindex, nsurl, publicationdate, version) VALUES ('0','http://opcfoundation.org/UA/','"+jsn.UANodeSet.Models.Model['PublicationDate']+"','"+jsn.UANodeSet.Models.Model['Version']+"');";
  1313. ret = pool.query(command);
  1314. if(Array.isArray(entry0)){
  1315. var szy = entry0.length;
  1316. for(let y = 0; y < szy; y++){
  1317. var ns = entry0[y];
  1318. command = "INSERT INTO ns"+i+"depends(nsindex, nsurl) VALUES ('"+(y+1)+"','"+ns+"');";
  1319. ret = pool.query(command);
  1320. }
  1321. }else{
  1322. var ns = entry0;
  1323. command = "INSERT INTO ns"+i+"depends(nsindex, nsurl) VALUES ('1','"+entry0+"');";
  1324. ret = pool.query(command);
  1325. }
  1326. var entry = nsray[i].UANodeSet.Models.Model.RequiredModel;
  1327. command = "UPDATE ns"+i+"depends SET publicationdate = '"+nsray[i].UANodeSet.Models.Model['PublicationDate']+"' WHERE nsurl = '"+nsray[i].UANodeSet.Models.Model['ModelUri']+"';";
  1328. ret = pool.query(command);
  1329. command = "UPDATE ns"+i+"depends SET version = '"+nsray[i].UANodeSet.Models.Model['Version']+"' WHERE nsurl = '"+nsray[i].UANodeSet.Models.Model['ModelUri']+"';";
  1330. ret = pool.query(command);
  1331. if(Array.isArray(entry)){
  1332. var szy = entry.length;
  1333. for(let y = 0; y < szy; y++){
  1334. var ns0 = entry[y];
  1335. command = "UPDATE ns"+i+"depends SET publicationdate = '"+ns0['PublicationDate']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1336. ret = pool.query(command);
  1337. command = "UPDATE ns"+i+"depends SET version = '"+ns0['Version']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1338. ret = pool.query(command);
  1339. }
  1340. }else{
  1341. var ns0 = entry;
  1342. command = "UPDATE ns"+i+"depends SET publicationdate = '"+ns0['PublicationDate']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1343. ret = pool.query(command);
  1344. command = "UPDATE ns"+i+"depends SET version = '"+ns0['Version']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1345. ret = pool.query(command);
  1346. }
  1347. }
  1348. res.json({result:'OK',success:true});
  1349. }catch(err){
  1350. console.log(err);
  1351. res.json({result:"NOK"});
  1352. }
  1353. })
  1354. app.get('/allrefs', async function(req, res){
  1355. try{
  1356. console.log(arref);
  1357. res.json({result:'OK',success:true});
  1358. }catch(err){
  1359. console.log("NOK");
  1360. res.json({result:"NOK"});
  1361. }
  1362. })
  1363. /*
  1364. app.post('/key', async function(req, res){
  1365. try{
  1366. var key = req.body;
  1367. console.log(key);
  1368. var ret = await gen_query("SELECT name FROM mitarbeiter WHERE key_id='"+key['key_id']+"';");
  1369. res.json({result:ret[0].name,success:true});
  1370. }catch(err){
  1371. console.log("NOK");
  1372. res.json({result:"NOK"});
  1373. }
  1374. })
  1375. */
  1376. app.get('/requirejson/:ident/:name',(req, res) =>{
  1377. try{
  1378. var namejs = req.params["name"];
  1379. var shorty = req.params["ident"];
  1380. const id = "./"+namejs+".json";
  1381. const fl = require(id);
  1382. for(let i = 0; i < ns_array.length; i++){
  1383. if(ns_array[i][1] === shorty){
  1384. return res.json({result:"Array already includes element."})
  1385. }
  1386. }
  1387. ns_array.push([fl, shorty, fl.UANodeSet.Models.Model.ModelUri]);
  1388. res.json({result:"OK"});
  1389. }catch(err){
  1390. console.log("NOK");
  1391. res.json({result:"NOK", error: "Json file may not be available. Call list json files."});
  1392. }
  1393. })
  1394. app.get('/shownsarray',(req, res) =>{
  1395. try{ let str = '';
  1396. for(let i = 0; i < ns_array.length; i++){
  1397. str += '('+i+': '+ns_array[i][1]+')';
  1398. }
  1399. res.json({result:str});
  1400. console.log(ns_array);
  1401. }catch(err){
  1402. console.log("NOK");
  1403. res.json({result:"NOK", error: "Json file may not be available. Call list json files."});
  1404. }
  1405. })
  1406. app.get('/getredis',(req, res) =>{
  1407. try{
  1408. redis_get();
  1409. res.json({result:"OK"});
  1410. }catch(err){
  1411. console.log("NOK");
  1412. res.json({result:"NOK"});
  1413. }
  1414. })
  1415. app.get('/get_root',(req, res) =>{
  1416. try{
  1417. let rt = jsn.UANodeSet.UAObject.find( record => record.NodeId === "i=84");
  1418. let resj = {
  1419. id: rt.NodeId,
  1420. parent: "#",
  1421. text: rt.DisplayName};
  1422. res.json(resj);
  1423. }catch(err){
  1424. console.log("NOK");
  1425. res.json({result:"NOK"});
  1426. }
  1427. })
  1428. app.get('/get_children/base/:id',(req, res) =>{
  1429. var nid = req.params["id"];
  1430. try{
  1431. if(Array.isArray(jsn.UANodeSet.UAObject)){
  1432. for (let i = 0; i < jsn.UANodeSet.UAObject.length;i++){
  1433. if(Array.isArray(jsn.UANodeSet.UAObject[i].References.Reference)){
  1434. for (let x = 0; x < jsn.UANodeSet.UAObject[i].References.Reference.length;x++){
  1435. if(jsn.UANodeSet.UAObject[i].References.Reference[x].$t === nid){
  1436. console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject[i].References.Reference[x]) +jsn.UANodeSet.UAObject[i].References.Reference[x].ReferenceType);
  1437. }
  1438. }
  1439. }else{
  1440. if(jsn.UANodeSet.UAObject[i].References.Reference.$t === nid){
  1441. console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject[i].References.Reference) +jsn.UANodeSet.UAObject[i].References.Reference.ReferenceType);
  1442. }
  1443. }
  1444. }
  1445. }else{
  1446. if(Array.isArray(jsn.UANodeSet.UAObject.References.Reference)){
  1447. for (let x = 0; x < jsn.UANodeSet.UAObject.References.Reference.length;x++){
  1448. if(jsn.UANodeSet.UAObject[i].References.Reference[x].$t === nid){
  1449. console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject.References.Reference[x]) +jsn.UANodeSet.UAObject.References.Reference[x].ReferenceType);
  1450. }
  1451. }
  1452. }else{
  1453. if(jsn.UANodeSet.UAObject.References.Reference.$t === nid){
  1454. console.log(jsn.UANodeSet.UAObject.BrowseName + inverse(jsn.UANodeSet.UAObject.References.Reference) +jsn.UANodeSet.UAObject.References.Reference.ReferenceType);
  1455. }
  1456. }
  1457. }
  1458. console.log('');
  1459. res.json({result:"OK"});
  1460. }catch(err){
  1461. console.log("NOK");
  1462. res.json({result:"NOK"});
  1463. }
  1464. })
  1465. app.get('/get_children/all/:ns/:id',(req, res) =>{
  1466. var ret_obj = [];
  1467. var ns = req.params["ns"];
  1468. var id = req.params["id"];
  1469. var nid = 'ns='+ns+';'+'i='+id;
  1470. console.log(nid);
  1471. get_Children(di, nid, ret_obj);
  1472. get_Children(ia, nid, ret_obj);
  1473. get_Children(mach, nid, ret_obj);
  1474. get_Children(mt, nid, ret_obj);
  1475. res.json(ret_obj);
  1476. })
  1477. app.get('/getNode/all/:ns/:id',(req, res) =>{
  1478. var ret_obj = [];
  1479. var ns = req.params["ns"];
  1480. var id = req.params["id"];
  1481. var nid = 'ns='+ns+';'+'i='+id;
  1482. console.log(nid);
  1483. get_Children(di, nid, ret_obj);
  1484. get_Children(ia, nid, ret_obj);
  1485. get_Children(mach, nid, ret_obj);
  1486. get_Children(mt, nid, ret_obj);
  1487. let node = {
  1488. id:nid,
  1489. text: "home",
  1490. children:ret_obj
  1491. }
  1492. res.json(node);
  1493. })
  1494. app.get('/flushall',(req, res) =>{
  1495. redis_flush();
  1496. res.json({result:"OK"});
  1497. })
  1498. app.get('/p2json/:nodeset/:ident',(req, res) =>{
  1499. var name = req.params["nodeset"];
  1500. var shorty = req.params["ident"];
  1501. p2json(name, shorty);
  1502. res.json({result:"OK"});
  1503. })
  1504. app.get('/list_projects', (req, res) => { //reacts to requests -> /list_projects
  1505. const output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
  1506. var out = output.split("\n");
  1507. if(out[out.length-1] === ""){
  1508. out.splice(-1,1);
  1509. }
  1510. console.log("Response: ", out);
  1511. res.json({result:out});
  1512. })
  1513. app.get('/list_nodesets', (req, res) => { //reacts to requests -> /list_nodesets
  1514. const output = execSync("cd .. && cd nodesets && ls", { encoding: 'utf-8' });
  1515. var out = output.split("\n");
  1516. var result = [];
  1517. for(let i = 0; i < out.length; i++){
  1518. if(out[i].includes(".xml")){
  1519. result.push(out[i]);
  1520. }
  1521. }
  1522. console.log("Response: ", result);
  1523. res.json({result:result});
  1524. })
  1525. app.get('/new_project', (req, res) => { //reacts to requests -> /new_project?name=myproject
  1526. const name = req.query.name; //project name
  1527. const output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
  1528. var out = output.split("\n");
  1529. var result = "";
  1530. var err = "Error - Project already exists.";
  1531. for(let i = 0; i < out.length; i++){
  1532. if(out[i] === name){
  1533. return res.json({result:err});
  1534. }
  1535. }
  1536. const dir = execSync("cd .. && cd Projects && mkdir "+name, { encoding: 'utf-8' });
  1537. var cp = execSync("sudo cp /home/pi/ModelingTool/nodesets/Opc.Ua.NodeSet2.xml /home/pi/ModelingTool/Projects/"+name+"/Opc.Ua.NodeSet2.xml", { encoding: 'utf-8' });
  1538. cp = execSync("sudo cp /home/pi/ModelingTool/nodesets/Opc.Ua.NodeSet2.json /home/pi/ModelingTool/Projects/"+name+"/Opc.Ua.NodeSet2.json", { encoding: 'utf-8' });
  1539. const cur_dir = execSync("cd .. && cd Projects && cd "+name+" && ls", { encoding: 'utf-8' });
  1540. console.log("New Project was created.");
  1541. res.json({result:cur_dir});
  1542. })
  1543. app.get('/save_project', (req, res) => { //reacts to requests -> /save_project?name=myproject
  1544. const name = req.query.name; //project name
  1545. const output = execSync("sudo cp /var/www/html/root.json /home/pi/ModelingTool/Projects/"+name+"/"+name+".json", { encoding: 'utf-8' });
  1546. console.log("Project "+name+" was saved.");
  1547. res.json({result:"Project saved"});
  1548. })
  1549. app.get('/load_json', (req, res) => { //reacts to requests -> /load_json?name=myproject
  1550. const name = req.query.name; //project name
  1551. var output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
  1552. var out = output.split("\n");
  1553. var result = "";
  1554. var err = "Error - Project or file not available.";
  1555. for(let i = 0; i < out.length; i++){
  1556. if(out[i] === name){
  1557. var output1 = execSync("cd .. && cd Projects && cd "+name+" && ls", { encoding: 'utf-8' });
  1558. var out1 = output1.split("\n");
  1559. var chk = name+".json"
  1560. for(let y = 0; y < out1.length; y++){
  1561. if(out1[y] === chk){
  1562. result = execSync("sudo cp /home/pi/ModelingTool/Projects/"+name+"/"+name+".json /var/www/html/root.json", { encoding: 'utf-8' });
  1563. console.log("Project has been loaded.");
  1564. return res.json({result:"Project loaded"});
  1565. }
  1566. }
  1567. }
  1568. }
  1569. res.json({result:err});
  1570. })
  1571. app.get('/root', (req, res) => { //reacts to requests -> /root
  1572. console.log("Return root.");
  1573. res.json([{id:"i=84",text:"Root",children:[{id:"i=85",text:"Objects",children:true},{id:"i=86",text:"Types", icon : "/variable_node.svg", children:true},{id:"i=87",text:"View",children:false}]}]);
  1574. })
  1575. function isChildRef(obj){
  1576. if('IsForward' in obj && obj.IsForward === 'false'){
  1577. return false;
  1578. }
  1579. if('IsForward' in obj && obj.IsForward === 'true'){
  1580. switch (obj.ReferenceType) {
  1581. case 'Organizes': return true;
  1582. case 'HasComponent': return true;
  1583. case 'HasProperty': return true;
  1584. case 'HasAddIn': return true;
  1585. case 'HasSubtype': return true;
  1586. default: return false;
  1587. }
  1588. }
  1589. switch (obj.ReferenceType) {
  1590. case 'Organizes': return true;
  1591. case 'HasComponent': return true;
  1592. case 'HasProperty': return true;
  1593. case 'HasAddIn': return true;
  1594. case 'HasSubtype': return true;
  1595. default: return false;
  1596. }
  1597. return false;
  1598. }
  1599. function checkDouble(item, obj){
  1600. for(let i = 0; i < obj.length; i++){
  1601. if(item.id === obj[i].id){
  1602. return true;
  1603. }
  1604. }
  1605. return false;
  1606. }
  1607. app.get('/lazy', (req, res) => {
  1608. //console.log(req);
  1609. var ret_obj = [];
  1610. let node = {};
  1611. if(req.query.id == "#"){
  1612. //res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object"},children:true}]);
  1613. res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object"},children:[{id:"i=85",text:"Objects",data:{nodeclass:"Objects"},children:true},{id:"i=86",text:"Types", data:{nodeclass:"Objects"},children:true},{id:"i=87",text:"View",data:{nodeclass:"Objects"},children:true}]}]);
  1614. }
  1615. var nid = req.query.id;
  1616. node = searchNode(nid);
  1617. if(node.data.references != null){
  1618. console.log("Here:"+node.data.references);
  1619. if(Array.isArray(node.data.references.Reference)){
  1620. console.log("And:"+node.data.references.Reference);
  1621. for(let x = 0; x < node.data.references.Reference.length; x++ ){
  1622. if(isChildRef(node.data.references.Reference[x])){
  1623. var cnode = searchNode(node.data.references.Reference[x].$t);
  1624. if(!checkDouble(cnode,ret_obj)){
  1625. ret_obj.push(cnode);
  1626. }
  1627. }
  1628. }
  1629. }else{
  1630. console.log("But:"+node.data.references);
  1631. if(isChildRef(node.data.references)){
  1632. var cnode = searchNode(node.data.references.$t);
  1633. if(!checkDouble(cnode,ret_obj)){
  1634. ret_obj.push(cnode);
  1635. }
  1636. }
  1637. }
  1638. }
  1639. getAllChildren(nid, ret_obj);
  1640. console.log(ret_obj);
  1641. res.json(ret_obj);
  1642. });
  1643. app.get('/index/:ns1/:ns2', (req, res) => {
  1644. var n1 = req.params["ns1"];
  1645. var n2 = req.params["ns2"];
  1646. var num = getIndexObj(ns_array[n1][0],ns_array[n2][0]);
  1647. console.log(getNode(ns_array[3][0],2,15048));
  1648. res.send("Index of "+ns_array[n2][1]+' in '+ns_array[n1][1]+' is '+num);
  1649. });
  1650. app.get('/test/:id', (req, res) => { //test
  1651. var n1 = parseInt(req.params["id"]);
  1652. console.log(ns_array[n1][1],);
  1653. var ret = searchNode("i=85");
  1654. console.log(ret);
  1655. res.send("All good");
  1656. //res.json([{id:"i=84",text:"Root",children:[{id:"i=85",text:"Objects",children:true},{id:"i=86",text:"Types", children:true},{id:"i=87",text:"View",children:false}]}]);
  1657. })
  1658. app.get('/require/all', (req, res) => { //test
  1659. ns_array.push([jsn, "base", jsn.UANodeSet.Models.Model.ModelUri]);
  1660. ns_array.push([di, "di", di.UANodeSet.Models.Model.ModelUri]);
  1661. ns_array.push([ia, "ia", ia.UANodeSet.Models.Model.ModelUri]);
  1662. ns_array.push([mach, "mach", mach.UANodeSet.Models.Model.ModelUri]);
  1663. ns_array.push([mt, "mt", mt.UANodeSet.Models.Model.ModelUri]);
  1664. res.json({result:"OK"});
  1665. })
  1666. app.listen(port, () => {
  1667. console.log("Server listening at http://localhost:", port);
  1668. })