services.js 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707
  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 = [jsn, di, ia, mach, mt];
  29. /*nsray.push(jsn);
  30. nsray.push(di);
  31. nsray.push(ia);
  32. nsray.push(mach);
  33. nsray.push(mt);
  34. */
  35. let type_ar = ['datatypes', 'objecttypes', 'referencetypes', 'variabletypes'];
  36. let classes_ar = ['datatypes', 'objecttypes', 'referencetypes', 'variabletypes', 'objects', 'variables', 'methods'];
  37. let child_refs = ['Organizes','HasComponent','HasProperty','HasAddIn','HasSubtype'];
  38. let hier_refs = ['i=34','i=44','i=45','i=35', 'i=47', 'i=46' ]; //HasChild, Aggregates, HasSubtype, Organizes, HasComponent, HasProperty
  39. /*
  40. async function gen_query(sql, params){
  41. const connection = await mysql.createConnection(conf);
  42. const [results, ] = await connection.execute(sql, params);
  43. //console.log(results);
  44. return results;
  45. }*/
  46. async function translateNid(nid, m){ //Uni -> local
  47. try{
  48. let obj = {
  49. idx: 0,
  50. ns: 0,
  51. ident: '0',
  52. combi: '',
  53. p1: '',
  54. p2:''
  55. }
  56. /*
  57. let obj = {
  58. ident_all:"",
  59. ident:"",
  60. ns_local: 0,
  61. combi_local: "",
  62. ns_old: 0,
  63. combi_old: "",
  64. ns_new: 0,
  65. combi_new: ""
  66. }*/
  67. if(nid.includes('ns=')){
  68. const nodeid = nid.split(";");
  69. obj.p1 = nodeid[0];
  70. obj.p2 = nodeid[1];
  71. const n1 = nodeid[0].split("=");
  72. obj.ns = parseInt(n1[1]);
  73. const n2 = nodeid[1].split("=");
  74. obj.ident = n2[1];
  75. var command = "SELECT nsurl FROM ns"+m+"depends WHERE nsindex='"+obj.ns+"';";
  76. var ret = await pool.query(command);
  77. command = "SELECT nsindex FROM namespaces WHERE nsurl='"+ret[0][0].nsurl+"';";
  78. ret = await pool.query(command);
  79. obj.idx = parseInt(ret[0][0].nsindex);
  80. obj.combi = "ns=1;"+nodeid[1];
  81. }else{
  82. const n1 = nid.split("=");
  83. obj.ident = n1[1];
  84. obj.combi = nid;
  85. obj.p2 = nid;
  86. }
  87. return obj;
  88. }catch(err){
  89. console.log(err);
  90. }
  91. }
  92. async function newNid(nid, i){ //Uni -> whatever is needed, global in i
  93. try{
  94. let obj = {
  95. ident_all:"",
  96. ident:"",
  97. ns: i,
  98. ns_local: 0,
  99. combi_local: "",
  100. ns_uni: 0,
  101. combi_uni: nid
  102. }
  103. if(nid.includes('ns=')){
  104. const nodeid = nid.split(";");
  105. obj.ident_all = nodeid[1];
  106. const n1 = nodeid[0].split("=");
  107. const n2 = nodeid[1].split("=");
  108. obj.ident = n2[1];
  109. obj.ns_uni = parseInt(n1[1]);
  110. var command = "SELECT nsurl FROM namespaces WHERE nsindex='"+n1[1]+"';";
  111. var ret = await pool.query(command);
  112. const ul = parseInt(ret[0][0].nsurl);
  113. command = "SELECT nsindex FROM ns"+i+"depends WHERE nsurl='"+ul+"';";
  114. ret = await pool.query(command);
  115. if(ret[0].length > 0){
  116. obj.ns_local = parseInt(ret[0][0].nsindex);
  117. obj.combi_local = "ns="+obj.ns_local+";"+obj.ident_all;
  118. }
  119. }else{
  120. const n1 = nid.split("=");
  121. obj.ident = n1[1];
  122. obj.ident_all = nid;
  123. obj.combi_local = nid;
  124. obj.combi_uni = nid;
  125. }
  126. return obj;
  127. }catch(err){
  128. console.log(err);
  129. }
  130. }
  131. async function getUniNid(nid, m){ //local -> Uni
  132. try{
  133. let obj = {
  134. ident_all:"",
  135. ident:"",
  136. ns: parseInt(m),
  137. ns_local: 0,
  138. combi_local: nid,
  139. ns_uni: 0,
  140. combi_uni: ""
  141. }
  142. if(nid.includes('ns=')){
  143. const nodeid = nid.split(";");
  144. obj.ident_all = nodeid[1];
  145. const n1 = nodeid[0].split("=");
  146. obj.ns_local = parseInt(n1[1]);
  147. const n2 = nodeid[1].split("=");
  148. obj.ident = n2[1];
  149. var command = "SELECT nsurl FROM ns"+m+"depends WHERE nsindex='"+obj.ns_local+"';";
  150. var ret = await pool.query(command);
  151. command = "SELECT nsindex FROM namespaces WHERE nsurl='"+ret[0][0].nsurl+"';";
  152. ret = await pool.query(command);
  153. obj.ns_uni = parseInt(ret[0][0].nsindex);
  154. obj.combi_uni = "ns="+obj.ns_uni+";"+obj.ident_all;
  155. }else{
  156. const n1 = nid.split("=");
  157. obj.ident = n1[1];
  158. obj.ident_all = nid;
  159. obj.combi_uni = nid;
  160. }
  161. return obj;
  162. }catch(err){
  163. console.log(err);
  164. }
  165. }
  166. async function getLocalNid(nid, m){ // Uni -> local
  167. try{
  168. let obj = {
  169. ident_all:"",
  170. ident:"",
  171. ns: 0,
  172. ns_local: 1,
  173. combi_local: "",
  174. ns_uni: m,
  175. combi_uni: ""
  176. }
  177. if(nid.includes('ns=')){
  178. const nodeid = nid.split(";");
  179. obj.ident_all = nodeid[1];
  180. const n1 = nodeid[0].split("=");
  181. obj.ns = obj.ns_uni;
  182. const n2 = nodeid[1].split("=");
  183. obj.ident = n2[1];
  184. obj.combi_local = "ns=1;"+obj.ident_all;
  185. obj.combi_uni = "ns="+m+";"+obj.ident_all;
  186. }else{
  187. const n1 = nid.split("=");
  188. obj.ident = n1[1];
  189. obj.ident_all = nid;
  190. obj.combi_local = nid;
  191. obj.combi_uni = nid;
  192. }
  193. return obj;
  194. }catch(err){
  195. console.log(err);
  196. }
  197. }
  198. function database_connection() {
  199. pool = mysql.createPool(conf);
  200. pool.getConnection(function(err, connection) {
  201. if(err) {
  202. logger.error('[ERROR] Connecting to database "' + err.toString() + '"');
  203. setTimeout(function() { database_connection(); }, 2500);
  204. }
  205. else
  206. {
  207. pool.query('SET NAMES utf8');
  208. pool.query('SET CHARACTER SET utf8');
  209. logger.trace('[INFO] Connected to database and set utf8!');
  210. }
  211. })};
  212. database_connection();
  213. function inverse(dev){
  214. if("IsForward" in dev){
  215. if(dev.IsForward === "false"){
  216. return true;
  217. }else{
  218. return false;
  219. }
  220. }else{
  221. return false;
  222. }
  223. }
  224. function forward(dev){
  225. var b = true;
  226. if("IsForward" in dev){
  227. if(dev.IsForward === "false"){
  228. b = false;
  229. }
  230. }else{
  231. b = true;
  232. }
  233. return b;
  234. }
  235. function sortNS(files){
  236. let nsets = [];
  237. for(let x = 0; x<files.length; x++){
  238. if("RequiredModel" in files[x].UANodeSet.Models.Model){
  239. if(Array.isArray(files[x].UANodeSet.Models.Model.RequiredModel)){
  240. var len = files[x].UANodeSet.Models.Model.RequiredModel.length;
  241. for(let y = 0; y < len; y++){
  242. files[x].UANodeSet.Models.Model.RequiredModel[y]
  243. }
  244. }else{
  245. }
  246. }else{
  247. nsets.push(files[x].UANodeSet.Models.Model.ModelUri);
  248. }
  249. }
  250. }
  251. function get_Children(jsnob, nid, ret_obj){
  252. const entities = ['UAObjectType','UAObject','UAVariableType','UAVariable', 'UADataType', 'UAReferenceType', 'UAMethod'];
  253. const set = jsnob.UANodeSet;
  254. for(let y = 0; y< entities.length; y++){
  255. if(entities[y] in set){
  256. try{
  257. const entry = set[entities[y]];
  258. if(Array.isArray(entry)){
  259. for (let i = 0; i < entry.length;i++){
  260. if(Object.keys(entry[i].References).length === 0){
  261. }else{
  262. if(Array.isArray(entry[i].References.Reference)){
  263. for (let x = 0; x < entry[i].References.Reference.length;x++){
  264. if(entry[i].References.Reference[x].$t === nid){
  265. if(inverse(entry[i].References.Reference[x])){
  266. let zobj= overwriteNode(entry[i], nid, entities[y], getIndexArray(jsnob));
  267. if(!checkDouble(zobj,ret_obj)){
  268. ret_obj.push(zobj);
  269. }
  270. }
  271. }
  272. }
  273. }else{
  274. if(entry[i].References.Reference.$t === nid){
  275. if(inverse(entry[i].References.Reference)){
  276. let zobj= overwriteNode(entry[i], nid, entities[y], getIndexArray(jsnob));
  277. if(!checkDouble(zobj,ret_obj)){
  278. ret_obj.push(zobj);
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. }else{
  286. if(Object.keys(entry.References).length === 0){
  287. }else{
  288. if(Array.isArray(entry.References.Reference)){
  289. for (let x = 0; x < entry.References.Reference.length;x++){
  290. if(entry.References.Reference[x].$t === nid){
  291. if(inverse(entry.References.Reference[x])){
  292. let zobj= overwriteNode(entry, nid, entities[y], getIndexArray(jsnob));
  293. if(!checkDouble(zobj,ret_obj)){
  294. ret_obj.push(zobj);
  295. }
  296. }
  297. }
  298. }
  299. }else{
  300. if(entry.References.Reference.$t === nid){
  301. if(inverse(entry.References.Reference)){
  302. let zobj= overwriteNode(entry, nid, entities[i], getIndexArray(jsnob));
  303. if(!checkDouble(zobj,ret_obj)){
  304. ret_obj.push(zobj);
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. }catch(err){
  312. console.log(err);
  313. }
  314. }
  315. }
  316. }
  317. function getAllChildren(nid, ret_obj){
  318. for(let ix = 0; ix < ns_array.length; ix++){
  319. get_Children(ns_array[ix][0], nid, ret_obj);
  320. }
  321. }
  322. function getIndexObj(jsnob, ns){
  323. var uri = ns.UANodeSet.Models.Model.ModelUri;
  324. if(uri == "http://opcfoundation.org/UA/"){
  325. return 0;
  326. }
  327. console.log(uri);
  328. let uris = {};
  329. if(jsnob.UANodeSet.NamespaceUris != undefined){
  330. uris = jsnob.UANodeSet.NamespaceUris.Uri;
  331. console.log(uris);
  332. }else{
  333. return 0;
  334. }
  335. for(let i = 0; i < uris.length; i++){
  336. console.log(uris[i]);
  337. if(uris[i] == uri){
  338. return i+1;
  339. }
  340. }
  341. return undefined;
  342. }
  343. function getIndexName(jsnob, name){
  344. if(name == "http://opcfoundation.org/UA/"){
  345. return 0;
  346. }
  347. let uris = {};
  348. if(jsnob.UANodeSet.NamespaceUris != undefined){
  349. uris = jsnob.UANodeSet.NamespaceUris.Uri;
  350. }else{
  351. return 0;
  352. }
  353. for(let i = 0; i < uris.length; i++){
  354. if(uris[i] == name){
  355. return i+1;
  356. }
  357. }
  358. return undefined;
  359. }
  360. function getIndexArray(tobj){
  361. for(let i = 0; i < ns_array.length;i++){
  362. console.log(ns_array[i][1]);
  363. if(tobj.UANodeSet.Models.Model.ModelUri === ns_array[i][0].UANodeSet.Models.Model.ModelUri){
  364. return i;
  365. }
  366. }
  367. return undefined;
  368. }
  369. function getNode(jsnob, ns, id){
  370. let uris = {};
  371. var ns_uri = '';
  372. if(jsnob.UANodeSet.NamespaceUris){
  373. uris = jsnob.UANodeSet.NamespaceUris.Uri;
  374. ns_uri = uris[ns-1];
  375. }
  376. for(let i = 0; i < ns_array.length; i++){
  377. if(ns_array[i][0].UANodeSet.Models.Model.ModelUri == ns_uri){
  378. return i;
  379. }
  380. }
  381. return -1;
  382. }
  383. function overwriteNode(nobj, nid, nc, ns){
  384. var nclass = "";
  385. switch(nc){
  386. case "UAObjectType":
  387. case "UAObject":
  388. case "UAVariableType":
  389. case "UADataType":
  390. case "UAReferenceType": nclass = "Object"; break;
  391. case "UAVariable": nclass = "Variable"; break;
  392. case "UAMethod": nclass = "Method"; break;
  393. default: nclass = "Object";
  394. }
  395. const node = {
  396. id:nobj.NodeId,
  397. text:nobj.DisplayName,
  398. children: true,
  399. data:{
  400. browsename: nobj.BrowseName,
  401. namespace: ns,
  402. elementclass: nc,
  403. nodeclass: nclass,
  404. parentNode: nid,
  405. parentid: "ParentNodeId" in nobj ? nobj.ParentNodeId : null,
  406. description: "Description" in nobj ? nobj.Description : null,
  407. notifier: "EventNotifier" in nobj ? nobj.EventNotifier : null, //Object
  408. isabstract: "IsAbstract" in nobj ? nobj.IsAbstract : null, //ObjectType
  409. datatype: "DataType" in nobj ? nobj.DataType : null, //Variable
  410. value: "Value" in nobj ? nobj.Value : null, //Variable
  411. arraydimensions: "ArrayDimensions" in nobj ? nobj.ArrayDimensions : null, //Variable
  412. references: "References" in nobj ? nobj.References : null
  413. }
  414. }
  415. return node;
  416. }
  417. function searchNode(id){
  418. const entities = ['UAObjectType','UAObject','UAVariableType','UAVariable', 'UADataType', 'UAReferenceType', 'UAMethod']; //7
  419. var nid = "";
  420. var jsnob = {};
  421. if(id.includes("ns=")){
  422. var ns = id.substring(id.length - 4);
  423. const ns1 = ns.split(";");
  424. var nsidx = parseInt(ns1[0]);
  425. jsnob = ns_array[nsidx][0];
  426. }else{
  427. nid = id;
  428. jsnob = ns_array[0][0];
  429. }
  430. const set = jsnob.UANodeSet;
  431. for(let i = 0; i< entities.length; i++){
  432. if(entities[i] in set){
  433. console.log(set.Models.Model.ModelUri+" has a "+entities[i]);
  434. if(Array.isArray(set[entities[i]])){
  435. for(let x = 0; x < set[entities[i]].length;x++){
  436. if(set[entities[i]][x].NodeId === nid){
  437. let nobj = set[entities[i]][x];
  438. const node = overwriteNode(nobj, null, entities[i], getIndexArray(jsnob));
  439. return node;
  440. }
  441. }
  442. }
  443. }
  444. }
  445. return null;
  446. }
  447. function p2json(name, shorty){
  448. try{
  449. const nn = name+".xml";
  450. var nnn = shorty+".json";
  451. fs.readFile( nn, function(err, data){
  452. //fs.readFile( "Opc.Ua.NodeSet2.xml", function(err, data){
  453. let jsn = parser.toJson(data);
  454. fs.writeFileSync(nnn, jsn);
  455. });
  456. }catch(err){
  457. console.log('not work');}
  458. }
  459. /*
  460. function listObjType(){
  461. var keys = [];
  462. console.log("ObjectTypes:");
  463. let obj = jsn.UANodeSet.UAObjectType; //base
  464. var sz = obj.length;
  465. console.log(sz);
  466. for(let i = 0; i < sz; i++){
  467. let arr = Object.keys(obj[i]);
  468. for(let x = 0; x < arr.length; x++){
  469. if(!keys.includes(arr[x])){
  470. keys.push(arr[x]);
  471. }
  472. }
  473. }
  474. obj = di.UANodeSet.UAObjectType; //base
  475. sz = obj.length;
  476. console.log(sz);
  477. for(let i = 0; i < sz; i++){
  478. let arr = Object.keys(obj[i]);
  479. for(let x = 0; x < arr.length; x++){
  480. if(!keys.includes(arr[x])){
  481. keys.push(arr[x]);
  482. }
  483. }
  484. }
  485. obj = ia.UANodeSet.UAObjectType; //base
  486. sz = obj.length;
  487. console.log(sz);
  488. for(let i = 0; i < sz; i++){
  489. let arr = Object.keys(obj[i]);
  490. for(let x = 0; x < arr.length; x++){
  491. if(!keys.includes(arr[x])){
  492. keys.push(arr[x]);
  493. }
  494. }
  495. }
  496. obj = mach.UANodeSet.UAObjectType; //base
  497. sz = obj.length;
  498. console.log(sz);
  499. for(let i = 0; i < sz; i++){
  500. let arr = Object.keys(obj[i]);
  501. for(let x = 0; x < arr.length; x++){
  502. if(!keys.includes(arr[x])){
  503. keys.push(arr[x]);
  504. }
  505. }
  506. }
  507. obj = mt.UANodeSet.UAObjectType; //base
  508. sz = obj.length;
  509. console.log(sz);
  510. for(let i = 0; i < sz; i++){
  511. let arr = Object.keys(obj[i]);
  512. for(let x = 0; x < arr.length; x++){
  513. if(!keys.includes(arr[x])){
  514. keys.push(arr[x]);
  515. }
  516. }
  517. }
  518. console.log(keys);
  519. }
  520. listObjType();
  521. function listObj(){
  522. var keys = [];
  523. console.log("Objects:");
  524. let obj = jsn.UANodeSet.UAObject; //base
  525. var 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. }
  535. obj = di.UANodeSet.UAObject; //base
  536. sz = obj.length;
  537. console.log(sz);
  538. for(let i = 0; i < sz; i++){
  539. let arr = Object.keys(obj[i]);
  540. for(let x = 0; x < arr.length; x++){
  541. if(!keys.includes(arr[x])){
  542. keys.push(arr[x]);
  543. }
  544. }
  545. }
  546. obj = ia.UANodeSet.UAObject; //base
  547. sz = obj.length;
  548. console.log(sz);
  549. for(let i = 0; i < sz; i++){
  550. let arr = Object.keys(obj[i]);
  551. for(let x = 0; x < arr.length; x++){
  552. if(!keys.includes(arr[x])){
  553. keys.push(arr[x]);
  554. }
  555. }
  556. }
  557. obj = mach.UANodeSet.UAObject; //base
  558. sz = obj.length;
  559. console.log(sz);
  560. for(let i = 0; i < sz; i++){
  561. let arr = Object.keys(obj[i]);
  562. for(let x = 0; x < arr.length; x++){
  563. if(!keys.includes(arr[x])){
  564. keys.push(arr[x]);
  565. }
  566. }
  567. }
  568. obj = mt.UANodeSet.UAObject; //base
  569. sz = obj.length;
  570. console.log(sz);
  571. for(let i = 0; i < sz; i++){
  572. let arr = Object.keys(obj[i]);
  573. for(let x = 0; x < arr.length; x++){
  574. if(!keys.includes(arr[x])){
  575. keys.push(arr[x]);
  576. }
  577. }
  578. }
  579. console.log(keys);
  580. }
  581. listObj();
  582. function listVar(){
  583. var keys = [];
  584. console.log("Variables:");
  585. let obj = jsn.UANodeSet.UAVariable; //base
  586. var sz = obj.length;
  587. console.log(sz);
  588. for(let i = 0; i < sz; i++){
  589. let arr = Object.keys(obj[i]);
  590. for(let x = 0; x < arr.length; x++){
  591. if(!keys.includes(arr[x])){
  592. keys.push(arr[x]);
  593. }
  594. }
  595. }
  596. obj = di.UANodeSet.UAVariable; //base
  597. sz = obj.length;
  598. console.log(sz);
  599. for(let i = 0; i < sz; i++){
  600. let arr = Object.keys(obj[i]);
  601. for(let x = 0; x < arr.length; x++){
  602. if(!keys.includes(arr[x])){
  603. keys.push(arr[x]);
  604. }
  605. }
  606. }
  607. obj = ia.UANodeSet.UAVariable; //base
  608. sz = obj.length;
  609. console.log(sz);
  610. for(let i = 0; i < sz; i++){
  611. let arr = Object.keys(obj[i]);
  612. for(let x = 0; x < arr.length; x++){
  613. if(!keys.includes(arr[x])){
  614. keys.push(arr[x]);
  615. }
  616. }
  617. }
  618. obj = mach.UANodeSet.UAVariable; //base
  619. sz = obj.length;
  620. console.log(sz);
  621. for(let i = 0; i < sz; i++){
  622. let arr = Object.keys(obj[i]);
  623. for(let x = 0; x < arr.length; x++){
  624. if(!keys.includes(arr[x])){
  625. keys.push(arr[x]);
  626. }
  627. }
  628. }
  629. obj = mt.UANodeSet.UAVariable; //base
  630. sz = obj.length;
  631. console.log(sz);
  632. for(let i = 0; i < sz; i++){
  633. let arr = Object.keys(obj[i]);
  634. for(let x = 0; x < arr.length; x++){
  635. if(!keys.includes(arr[x])){
  636. keys.push(arr[x]);
  637. }
  638. }
  639. }
  640. console.log(keys);
  641. }
  642. listVar();
  643. function listVarTypes(){
  644. var keys = [];
  645. console.log("VariableTypes:");
  646. let obj = jsn.UANodeSet.UAVariableType; //base
  647. var sz = obj.length;
  648. console.log(sz);
  649. for(let i = 0; i < sz; i++){
  650. let arr = Object.keys(obj[i]);
  651. for(let x = 0; x < arr.length; x++){
  652. if(!keys.includes(arr[x])){
  653. keys.push(arr[x]);
  654. }
  655. }
  656. }
  657. obj = di.UANodeSet.UAVariableType; //base
  658. sz = obj.length;
  659. console.log(sz);
  660. for(let i = 0; i < sz; i++){
  661. let arr = Object.keys(obj[i]);
  662. for(let x = 0; x < arr.length; x++){
  663. if(!keys.includes(arr[x])){
  664. keys.push(arr[x]);
  665. }
  666. }
  667. }
  668. obj = ia.UANodeSet.UAVariableType; //base
  669. sz = obj.length;
  670. console.log(sz);
  671. for(let i = 0; i < sz; i++){
  672. let arr = Object.keys(obj[i]);
  673. for(let x = 0; x < arr.length; x++){
  674. if(!keys.includes(arr[x])){
  675. keys.push(arr[x]);
  676. }
  677. }
  678. }
  679. obj = mach.UANodeSet.UAVariableType; //base
  680. if(obj !== undefined){
  681. if(Array.isArray(obj)){
  682. sz = obj.length;
  683. console.log(sz);
  684. for(let i = 0; i < sz; i++){
  685. let arr = Object.keys(obj[i]);
  686. for(let x = 0; x < arr.length; x++){
  687. if(!keys.includes(arr[x])){
  688. keys.push(arr[x]);
  689. }
  690. }
  691. }}else{
  692. let arr = Object.keys(obj);
  693. for(let x = 0; x < arr.length; x++){
  694. if(!keys.includes(arr[x])){
  695. keys.push(arr[x]);
  696. }
  697. }
  698. }
  699. }
  700. obj = mt.UANodeSet.UAVariableType; //base
  701. sz = obj.length;
  702. console.log(sz);
  703. for(let i = 0; i < sz; i++){
  704. let arr = Object.keys(obj[i]);
  705. for(let x = 0; x < arr.length; x++){
  706. if(!keys.includes(arr[x])){
  707. keys.push(arr[x]);
  708. }
  709. }
  710. }
  711. console.log(keys);
  712. }
  713. listVarTypes();
  714. function listMethod(){
  715. var keys = [];
  716. console.log("Methods:");
  717. let obj = jsn.UANodeSet.UAMethod; //base
  718. var sz = obj.length;
  719. console.log(sz);
  720. for(let i = 0; i < sz; i++){
  721. let arr = Object.keys(obj[i]);
  722. for(let x = 0; x < arr.length; x++){
  723. if(!keys.includes(arr[x])){
  724. keys.push(arr[x]);
  725. }
  726. }
  727. }
  728. obj = di.UANodeSet.UAMethod; //base
  729. sz = obj.length;
  730. console.log(sz);
  731. for(let i = 0; i < sz; i++){
  732. let arr = Object.keys(obj[i]);
  733. for(let x = 0; x < arr.length; x++){
  734. if(!keys.includes(arr[x])){
  735. keys.push(arr[x]);
  736. }
  737. }
  738. }
  739. obj = ia.UANodeSet.UAMethod; //base
  740. sz = obj.length;
  741. console.log(sz);
  742. for(let i = 0; i < sz; i++){
  743. let arr = Object.keys(obj[i]);
  744. for(let x = 0; x < arr.length; x++){
  745. if(!keys.includes(arr[x])){
  746. keys.push(arr[x]);
  747. }
  748. }
  749. }
  750. obj = mach.UANodeSet.UAMethod; //base
  751. if(obj !== undefined){
  752. if(Array.isArray(obj)){
  753. sz = obj.length;
  754. console.log(sz);
  755. for(let i = 0; i < sz; i++){
  756. let arr = Object.keys(obj[i]);
  757. for(let x = 0; x < arr.length; x++){
  758. if(!keys.includes(arr[x])){
  759. keys.push(arr[x]);
  760. }
  761. }
  762. }}else{
  763. let arr = Object.keys(obj);
  764. for(let x = 0; x < arr.length; x++){
  765. if(!keys.includes(arr[x])){
  766. keys.push(arr[x]);
  767. }
  768. }
  769. }}
  770. obj = mt.UANodeSet.UAMethod; //base
  771. if(obj !== undefined){
  772. if(Array.isArray(obj)){
  773. sz = obj.length;
  774. console.log(sz);
  775. for(let i = 0; i < sz; i++){
  776. let arr = Object.keys(obj[i]);
  777. for(let x = 0; x < arr.length; x++){
  778. if(!keys.includes(arr[x])){
  779. keys.push(arr[x]);
  780. }
  781. }
  782. }}else{
  783. let arr = Object.keys(obj);
  784. for(let x = 0; x < arr.length; x++){
  785. if(!keys.includes(arr[x])){
  786. keys.push(arr[x]);
  787. }
  788. }
  789. }}
  790. console.log(keys);
  791. }
  792. listMethod();
  793. function listDataType(){
  794. var keys = [];
  795. console.log("DataType:");
  796. let obj = jsn.UANodeSet.UADataType; //base
  797. var sz = obj.length;
  798. console.log(sz);
  799. for(let i = 0; i < sz; i++){
  800. let arr = Object.keys(obj[i]);
  801. for(let x = 0; x < arr.length; x++){
  802. if(!keys.includes(arr[x])){
  803. keys.push(arr[x]);
  804. }
  805. }
  806. }
  807. obj = di.UANodeSet.UADataType; //base
  808. sz = obj.length;
  809. console.log(sz);
  810. for(let i = 0; i < sz; i++){
  811. let arr = Object.keys(obj[i]);
  812. for(let x = 0; x < arr.length; x++){
  813. if(!keys.includes(arr[x])){
  814. keys.push(arr[x]);
  815. }
  816. }
  817. }
  818. obj = ia.UANodeSet.UADataType; //base
  819. sz = obj.length;
  820. console.log(sz);
  821. for(let i = 0; i < sz; i++){
  822. let arr = Object.keys(obj[i]);
  823. for(let x = 0; x < arr.length; x++){
  824. if(!keys.includes(arr[x])){
  825. keys.push(arr[x]);
  826. }
  827. }
  828. }
  829. obj = mach.UANodeSet.UADataType; //base
  830. if(obj !== undefined){
  831. if(Array.isArray(obj)){
  832. sz = obj.length;
  833. console.log(sz);
  834. for(let i = 0; i < sz; i++){
  835. let arr = Object.keys(obj[i]);
  836. for(let x = 0; x < arr.length; x++){
  837. if(!keys.includes(arr[x])){
  838. keys.push(arr[x]);
  839. }
  840. }
  841. }}else{
  842. let arr = Object.keys(obj);
  843. for(let x = 0; x < arr.length; x++){
  844. if(!keys.includes(arr[x])){
  845. keys.push(arr[x]);
  846. }
  847. }
  848. }}
  849. obj = mt.UANodeSet.UADataType; //base
  850. sz = obj.length;
  851. console.log(sz);
  852. for(let i = 0; i < sz; i++){
  853. let arr = Object.keys(obj[i]);
  854. for(let x = 0; x < arr.length; x++){
  855. if(!keys.includes(arr[x])){
  856. keys.push(arr[x]);
  857. }
  858. }
  859. }
  860. console.log(keys);
  861. }
  862. listDataType();
  863. function listRefType(){
  864. var keys = [];
  865. console.log("ReferenceTypes:");
  866. let obj = jsn.UANodeSet.UAReferenceType; //base
  867. var sz = obj.length;
  868. console.log(sz);
  869. for(let i = 0; i < sz; i++){
  870. let arr = Object.keys(obj[i]);
  871. for(let x = 0; x < arr.length; x++){
  872. if(!keys.includes(arr[x])){
  873. keys.push(arr[x]);
  874. }
  875. }
  876. }
  877. obj = di.UANodeSet.UAReferenceType; //base
  878. sz = obj.length;
  879. console.log(sz);
  880. for(let i = 0; i < sz; i++){
  881. let arr = Object.keys(obj[i]);
  882. for(let x = 0; x < arr.length; x++){
  883. if(!keys.includes(arr[x])){
  884. keys.push(arr[x]);
  885. }
  886. }
  887. }
  888. obj = ia.UANodeSet.UAReferenceType; //base
  889. sz = obj.length;
  890. console.log(sz);
  891. for(let i = 0; i < sz; i++){
  892. let arr = Object.keys(obj[i]);
  893. for(let x = 0; x < arr.length; x++){
  894. if(!keys.includes(arr[x])){
  895. keys.push(arr[x]);
  896. }
  897. }
  898. }
  899. obj = mach.UANodeSet.UAReferenceType; //base
  900. if(obj !== undefined){
  901. if(Array.isArray(obj)){
  902. sz = obj.length;
  903. console.log(sz);
  904. for(let i = 0; i < sz; i++){
  905. let arr = Object.keys(obj[i]);
  906. for(let x = 0; x < arr.length; x++){
  907. if(!keys.includes(arr[x])){
  908. keys.push(arr[x]);
  909. }
  910. }
  911. }}else{
  912. let arr = Object.keys(obj);
  913. for(let x = 0; x < arr.length; x++){
  914. if(!keys.includes(arr[x])){
  915. keys.push(arr[x]);
  916. }
  917. }
  918. }}
  919. obj = mt.UANodeSet.UAReferenceType; //base
  920. if(obj !== undefined){
  921. if(Array.isArray(obj)){
  922. sz = obj.length;
  923. console.log(sz);
  924. for(let i = 0; i < sz; i++){
  925. let arr = Object.keys(obj[i]);
  926. for(let x = 0; x < arr.length; x++){
  927. if(!keys.includes(arr[x])){
  928. keys.push(arr[x]);
  929. }
  930. }
  931. }}else{
  932. let arr = Object.keys(obj);
  933. for(let x = 0; x < arr.length; x++){
  934. if(!keys.includes(arr[x])){
  935. keys.push(arr[x]);
  936. }
  937. }
  938. }}
  939. console.log(keys);
  940. }
  941. listRefType();
  942. */
  943. let arref = [];
  944. /*
  945. async function getThisNodeAttribute(ix, nid, classname, attr){
  946. try{
  947. var res = "";
  948. //0/i=84/UAObject
  949. var nnid = await getLocalNid(nid);
  950. var command = "SELECT * FROM ns"+ix+""+classname+" WHERE nodeid='"+nnid.combi_local+"';";
  951. var ret = await pool.query(command);
  952. if(ret[0].length !== 0){
  953. res = ret[0][0][attr];
  954. return res;
  955. }
  956. return res;
  957. }catch(err){
  958. console.log(err);
  959. }
  960. }
  961. */
  962. async function getThisNode(ix, nid, classname){
  963. try{
  964. var res = "";
  965. var nnid = await getLocalNid(nid, ix);
  966. var command = "SELECT * FROM ns"+nnid.ns_uni+""+classname+" WHERE nodeid='"+nnid.combi_local+"';";
  967. var ret = await pool.query(command);
  968. var resp = ret[0][0];
  969. var flag_ch = true;
  970. /*var val1 = await getChildrenSql(ix, nid);
  971. if(val1.length == 0){
  972. flag_ch = false;
  973. }
  974. */
  975. if(ret[0].length !== 0){
  976. var l = await getUniNid(resp.nodeid, nnid.ns_uni);
  977. obj0 = {
  978. id: l.combi_uni,
  979. text: resp.name,
  980. type: ret[0][0].nodeclass,
  981. data: ret[0][0],
  982. children: flag_ch
  983. };
  984. obj0.data.nsindex = l.ns_uni;
  985. res = obj0;
  986. return res;
  987. }
  988. return res;
  989. }catch(err){
  990. console.log(err);
  991. }
  992. }
  993. async function getChildrenSql(ix, nid){ //Uni nodeid -> 4/ns=4;i=131
  994. try{
  995. let res = [];
  996. var obj = {};
  997. for(let i = ix; i < nsray.length; i++){
  998. obj = await newNid(nid, i);
  999. var command = "SELECT nodeidorigin FROM ns"+i+"references WHERE target='"+obj.combi_local+"' AND isforward='false';";
  1000. console.log(command);
  1001. var ret = await pool.query(command);
  1002. var iterator = ret[0].values();
  1003. for (const value of iterator) {
  1004. var bb = await getUniNid(value.nodeidorigin, i)
  1005. var nc = "";
  1006. for(let j = 0; j < classes_ar.length; j++){
  1007. if(bb.ns_uni !== 0){
  1008. command = "SELECT nodeclass FROM ns"+bb.ns_uni+""+classes_ar[j]+" WHERE nodeid='ns=1;"+bb.ident_all+"';";
  1009. ret = await pool.query(command);
  1010. if(ret[0].length !== 0){
  1011. nc = ret[0][0].nodeclass;
  1012. res.push([bb.combi_uni, bb.ns_uni, nc]);
  1013. }
  1014. }else{
  1015. command = "SELECT nodeclass FROM ns0"+classes_ar[j]+" WHERE nodeid='"+bb.ident_all+"';";
  1016. ret = await pool.query(command);
  1017. if(ret[0].length !== 0){
  1018. nc = ret[0][0].nodeclass;
  1019. res.push([bb.combi_uni, bb.ns_uni, nc]);
  1020. }
  1021. }
  1022. }
  1023. }
  1024. }
  1025. obj = await getLocalNid(nid, ix);
  1026. command = "SELECT target FROM ns"+ix+"references WHERE nodeidorigin='"+obj.combi_local+"' AND isforward='undefined';"; //Search all hierarchical references!
  1027. console.log(command);
  1028. ret = await pool.query(command);
  1029. var iterator = ret[0].values();
  1030. for (const value of iterator) {
  1031. var bb = await getUniNid(value.target, ix)
  1032. var nc = "";
  1033. for(let j = 0; j < classes_ar.length; j++){
  1034. if(bb.ns_uni !== 0){
  1035. command = "SELECT nodeclass FROM ns"+bb.ns_uni+""+classes_ar[j]+" WHERE nodeid='ns=1;"+bb.ident_all+"';";
  1036. console.log(command);
  1037. ret = await pool.query(command);
  1038. if(ret[0].length !== 0){
  1039. nc = ret[0][0].nodeclass;
  1040. res.push([bb.combi_uni, bb.ns_uni, nc]);
  1041. }
  1042. }else{
  1043. command = "SELECT nodeclass FROM ns0"+classes_ar[j]+" WHERE nodeid='"+bb.ident_all+"';";
  1044. console.log(command);
  1045. ret = await pool.query(command);
  1046. if(ret[0].length !== 0){
  1047. nc = ret[0][0].nodeclass;
  1048. res.push([bb.combi_uni, bb.ns_uni, nc]);
  1049. }
  1050. }
  1051. }
  1052. }
  1053. console.log(res);
  1054. return res;
  1055. }catch(err){
  1056. console.log(err);
  1057. }
  1058. }
  1059. async function checkRefs(obj, nsix, url){
  1060. try{
  1061. var nid = obj.NodeId;
  1062. var idx1 = 0;
  1063. if(nid.includes('ns=')){
  1064. var iy = nid.indexOf(';');
  1065. var ns = nid.substring(3,iy);
  1066. idx1 = parseInt(ns);
  1067. }
  1068. // 1 oder 0
  1069. // nsix = index bei den nodesets
  1070. var ret = {};
  1071. if(obj['References']){
  1072. let refs = obj.References.Reference;
  1073. if(Array.isArray(refs)){
  1074. for(let i = 0; i < refs.length; i++){
  1075. var elem = refs[i];
  1076. var nid_t = "";
  1077. if(nid.includes('i=')){
  1078. nid_t = 'Numeric';
  1079. }else if(nid.includes('s=')){
  1080. nid_t = 'String';
  1081. }
  1082. var nst = 0;
  1083. var target = "";
  1084. var t_new = "";
  1085. if(elem['$t']){
  1086. target = elem['$t'];
  1087. t_new = await translateNid(target, nsix);
  1088. nst = t_new.idx || 0;
  1089. }
  1090. var command = "INSERT INTO ns"+nsix+"references(nodeidorigin, nodeidtype, nsindex, nsurl, referencetype, isforward, target, ns_target) VALUES ('"+nid+"', '"+nid_t+"', '"+idx1+"', '"+url+"', '"+elem['ReferenceType']+"', '"+elem['IsForward']+"', '"+target+"', '"+nst+"');";
  1091. var ret = await pool.query(command);
  1092. }
  1093. }else{
  1094. var elem = refs;
  1095. var nid_t = "";
  1096. if(nid.includes('i=')){
  1097. nid_t = 'Numeric';
  1098. }else if(nid.includes('s=')){
  1099. nid_t = 'String';
  1100. }
  1101. var nst = 0;
  1102. var target = "";
  1103. var t_new = "";
  1104. if(elem['$t']){
  1105. target = elem['$t'];
  1106. t_new = await translateNid(target, nsix);
  1107. nst = t_new.idx || 0;
  1108. }
  1109. var command = "INSERT INTO ns"+nsix+"references(nodeidorigin, nodeidtype, nsindex, nsurl, referencetype, isforward, target, ns_target) VALUES ('"+nid+"', '"+nid_t+"', '"+idx1+"', '"+url+"', '"+elem['ReferenceType']+"', '"+elem['IsForward']+"', '"+target+"', '"+nst+"');";
  1110. var ret = await pool.query(command);
  1111. }
  1112. }
  1113. }catch(err){
  1114. console.log(err);
  1115. }
  1116. }
  1117. async function getTypeDef(nid, ix){
  1118. try{
  1119. let obj = await translateNid(nid, ix);
  1120. for(let z = 0; z < type_ar.length; z++){
  1121. var command = "SELECT name FROM ns"+obj.idx+""+type_ar[z]+" WHERE nodeid='"+obj.combi+"';";
  1122. var ret = await pool.query(command);
  1123. console.log(ret[0][0]);
  1124. if(ret[0].length === 0){
  1125. }else{
  1126. return ret[0][0].name;
  1127. }
  1128. }
  1129. return "?";
  1130. }catch(err){
  1131. console.log(err);
  1132. }
  1133. }
  1134. async function getDataType(nid, ix){
  1135. try{
  1136. var obj = await translateNid(nid, ix);
  1137. console.log(obj);
  1138. var command = "SELECT name FROM ns"+obj.idx+"datatypes WHERE nodeid='"+obj.combi+"';";
  1139. console.log(command);
  1140. var ret = await pool.query(command);
  1141. return ret[0][0].name;
  1142. }catch(err){
  1143. console.log(err);
  1144. }
  1145. }
  1146. async function getParentRef(entry, ix){
  1147. try{
  1148. let pnode = {
  1149. pnid: "",
  1150. pref: "",
  1151. pinv: "false"
  1152. }
  1153. if(entry['ParentNodeId']){
  1154. pnode.pnid = entry['ParentNodeId'];
  1155. }
  1156. if(entry['References']){
  1157. let refs = entry.References.Reference;
  1158. if(Array.isArray(refs)){
  1159. for(let d = 0; d < refs.length; d++){
  1160. var command = "SELECT DISTINCT target,referencetype FROM ns"+ix+"references WHERE nodeidorigin='"+entry['NodeId']+"' AND referencetype='"+refs[d]['ReferenceType']+"' AND isforward LIKE 'fal%';";
  1161. var ret = await pool.query(command);
  1162. if(ret[0].length === 0){
  1163. continue;
  1164. }else{
  1165. if(pnode.pnid === ret[0][0].target){
  1166. pnode.pref = ret[0][0].referencetype;
  1167. pnode.pinv = "false";
  1168. console.log(ret);
  1169. }else{
  1170. pnode.pnid = ret[0][0].target;
  1171. pnode.pref = ret[0][0].referencetype;
  1172. pnode.pinv = "true";
  1173. }
  1174. }
  1175. }
  1176. }else{
  1177. var command = "SELECT DISTINCT target,referencetype FROM ns"+ix+"references WHERE nodeidorigin='"+entry['NodeId']+"' AND referencetype='"+refs['ReferenceType']+"' AND isforward LIKE 'fal%';";
  1178. var ret = await pool.query(command);
  1179. if(ret[0].length === 0){
  1180. }else{
  1181. if(pnode.pnid === ret[0][0].target){
  1182. pnode.pref = ret[0][0].referencetype;
  1183. pnode.pinv = "false";
  1184. }else{
  1185. pnode.pnid = ret[0][0].target;
  1186. pnode.pref = ret[0][0].referencetype;
  1187. pnode.pinv = "true";
  1188. }
  1189. }
  1190. }
  1191. }
  1192. return pnode;
  1193. }catch(err){
  1194. console.log(err);
  1195. }
  1196. }
  1197. async function createNamespace(m){
  1198. try{
  1199. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"objects(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'Object', 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), eventnotifier INT DEFAULT NULL, typedefinition VARCHAR(300) NOT NULL, parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1200. var ret = await pool.query(command);
  1201. command = "CREATE TABLE IF NOT EXISTS ns"+m+"objecttypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'ObjectType', 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), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), comment VARCHAR(300), documentation VARCHAR(300), PRIMARY KEY(id));";
  1202. ret = await pool.query(command);
  1203. command = "CREATE TABLE IF NOT EXISTS ns"+m+"variables(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'Variable', 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), modellingrule VARCHAR(100) DEFAULT 'Optional', datatype VARCHAR(300) NOT NULL, typedefinition VARCHAR(300) NOT NULL, value VARCHAR(500) DEFAULT NULL, valuerank INT DEFAULT NULL, arraydimensions INT, accesslevel INT DEFAULT NULL, accesslevelex INT DEFAULT NULL, historizing VARCHAR(10), minsamplinginterval INT DEFAULT 500, releasestatus VARCHAR(300), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1204. ret = await pool.query(command);
  1205. command = "CREATE TABLE IF NOT EXISTS ns"+m+"variabletypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'VariableType', 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), datatype VARCHAR(300) NOT NULL, value VARCHAR(500) DEFAULT NULL, valuerank INT DEFAULT NULL, arraydimensions INT, isabstract VARCHAR(10), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1206. ret = await pool.query(command);
  1207. command = "CREATE TABLE IF NOT EXISTS ns"+m+"methods(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'Method', 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), modellingrule VARCHAR(100) DEFAULT 'Optional', executable INT DEFAULT 1, parentreference VARCHAR(300), parentid VARCHAR(300) DEFAULT '#', methoddeclarationid VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1208. ret = await pool.query(command);
  1209. command = "CREATE TABLE IF NOT EXISTS ns"+m+"datatypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'DataType', 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), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), definition VARCHAR(300), releasestatus VARCHAR(300), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1210. ret = await pool.query(command);
  1211. command = "CREATE TABLE IF NOT EXISTS ns"+m+"referencetypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, 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 VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1212. ret = await pool.query(command);
  1213. command = "CREATE TABLE IF NOT EXISTS ns"+m+"references(id INT AUTO_INCREMENT, nodeidorigin VARCHAR(300) NOT NULL, nodeidtype VARCHAR(100) NOT NULL, nsindex INT DEFAULT NULL, nsurl VARCHAR(120) DEFAULT 'http://opcfoundation.org/UA/', referencetype VARCHAR(100) NOT NULL, isforward VARCHAR(10) DEFAULT 'true', target VARCHAR(300), t_nidt VARCHAR(100), ns_target INT DEFAULT NULL, comment VARCHAR(300), PRIMARY KEY(id));";
  1214. ret = await pool.query(command);
  1215. }catch(err){
  1216. console.log(err);
  1217. }
  1218. }
  1219. async function createObj(m){
  1220. try{
  1221. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"objects(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'Object', 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), eventnotifier INT DEFAULT NULL, typedefinition VARCHAR(300) NOT NULL, parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1222. var ret = await pool.query(command);
  1223. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1224. let obj = nsray[m].UANodeSet.UAObject;
  1225. if(nsray[m].UANodeSet.UAObject){
  1226. if(Array.isArray(obj)){
  1227. var sz = obj.length;
  1228. for(let i = 0; i < sz; i++){
  1229. var entry = obj[i];
  1230. var nid = entry['NodeId'];
  1231. await checkRefs(entry, m, url);
  1232. var idx = 0;
  1233. if(nid.includes('ns=')){
  1234. var ix = nid.indexOf(';');
  1235. var ns = nid.substring(3,ix);
  1236. idx = parseInt(ns);
  1237. }
  1238. var nid_t = "";
  1239. if(nid.includes('i=')){
  1240. nid_t = 'Numeric';
  1241. }else if(nid.includes('s=')){
  1242. nid_t = 'String';
  1243. }
  1244. var eventnot = 0;
  1245. if(entry['EventNotifier']){
  1246. eventnot = parseInt(entry['EventNotifier']);
  1247. }
  1248. var tt = await getTypeDef(entry['NodeId'], m);
  1249. let pnode = await getParentRef(entry, m);
  1250. command = "INSERT INTO ns"+m+"objects(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, typedefinition, description, eventnotifier, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+tt+"','"+entry['Description']+"', '"+eventnot+"', '"+entry['Documentation']+"');";
  1251. ret = pool.query(command);
  1252. }
  1253. }else{
  1254. var entry = obj;
  1255. var nid = entry['NodeId'];
  1256. var idx = 0;
  1257. await checkRefs(entry, m, url);
  1258. if(nid.includes('ns=')){
  1259. var ix = nid.indexOf(';');
  1260. var ns = nid.substring(3,ix);
  1261. idx = parseInt(ns);
  1262. }
  1263. var nid_t = "";
  1264. if(nid.includes('i=')){
  1265. nid_t = 'Numeric';
  1266. }else if(nid.includes('s=')){
  1267. nid_t = 'String';
  1268. }
  1269. var eventnot = 0;
  1270. if(entry['EventNotifier']){
  1271. eventnot = parseInt(entry['EventNotifier']);
  1272. }
  1273. var tt = await getTypeDef(entry['NodeId'], m);
  1274. let pnode = await getParentRef(entry, m);
  1275. command = "INSERT INTO ns"+m+"objects(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, typedefinition, description, eventnotifier, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+tt+"','"+entry['Description']+"', '"+eventnot+"', '"+entry['Documentation']+"');";
  1276. ret = pool.query(command);
  1277. }
  1278. }
  1279. }catch(err){
  1280. console.log(err);
  1281. }
  1282. }
  1283. async function createObjTypes(m){
  1284. try{
  1285. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"objecttypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'ObjectType', 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), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), comment VARCHAR(300), documentation VARCHAR(300), PRIMARY KEY(id));";
  1286. var ret = await pool.query(command);
  1287. let obj = nsray[m].UANodeSet.UAObjectType;
  1288. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1289. if(nsray[m].UANodeSet.UAObjectType){
  1290. if(Array.isArray(obj)){
  1291. var sz = obj.length;
  1292. for(let i = 0; i < sz; i++){
  1293. var entry = obj[i];
  1294. var nid = entry['NodeId'];
  1295. var idx = 0;
  1296. if(nid.includes('ns=')){
  1297. var ix = nid.indexOf(';');
  1298. var ns = nid.substring(3,ix);
  1299. idx = parseInt(ns);
  1300. }
  1301. await checkRefs(entry, m, url);
  1302. var nid_t = "";
  1303. if(nid.includes('i=')){
  1304. nid_t = 'Numeric';
  1305. }else if(nid.includes('s=')){
  1306. nid_t = 'String';
  1307. }
  1308. var isabstr = "TBD";
  1309. if(entry['IsAbstract']){
  1310. isabstr = entry['IsAbstract'];
  1311. }
  1312. var pnid = "#";
  1313. let pnode = await getParentRef(entry, m);
  1314. command = "INSERT INTO ns"+m+"objecttypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, isabstract, description, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+isabstr+"', '"+entry['Description']+"', '"+entry['Documentation']+"');";
  1315. ret = pool.query(command);
  1316. }
  1317. }else{
  1318. var entry = obj;
  1319. var nid = entry['NodeId'];
  1320. var idx = 0;
  1321. if(nid.includes('ns=')){
  1322. var ix = nid.indexOf(';');
  1323. var ns = nid.substring(3,ix);
  1324. idx = parseInt(ns);
  1325. }
  1326. await checkRefs(entry, m, url);
  1327. var nid_t = "";
  1328. if(nid.includes('i=')){
  1329. nid_t = 'Numeric';
  1330. }else if(nid.includes('s=')){
  1331. nid_t = 'String';
  1332. }
  1333. var isabstr = "TBD";
  1334. if(entry['IsAbstract']){
  1335. isabstr = entry['IsAbstract'];
  1336. }
  1337. let pnode = await getParentRef(entry, m);
  1338. command = "INSERT INTO ns"+m+"objecttypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, isabstract, description, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+isabstr+"', '"+entry['Description']+"', '"+entry['Documentation']+"');";
  1339. ret = pool.query(command);
  1340. }
  1341. }
  1342. }catch(err){
  1343. console.log(err);
  1344. }
  1345. }
  1346. async function createVar(m){
  1347. try{
  1348. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"variables(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'Variable', 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), modellingrule VARCHAR(100) DEFAULT 'Optional', datatype VARCHAR(300) NOT NULL, typedefinition VARCHAR(300) NOT NULL, value VARCHAR(500) DEFAULT NULL, valuerank INT DEFAULT NULL, arraydimensions INT, accesslevel INT DEFAULT NULL, accesslevelex INT DEFAULT NULL, historizing VARCHAR(10), minsamplinginterval INT DEFAULT 500, releasestatus VARCHAR(300), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1349. var ret = await pool.query(command);
  1350. let obj = nsray[m].UANodeSet.UAVariable;
  1351. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1352. if(nsray[m].UANodeSet.UAVariable){
  1353. if(Array.isArray(obj)){
  1354. var sz = obj.length;
  1355. for(let i = 0; i < sz; i++){
  1356. var entry = obj[i];
  1357. var nid = entry['NodeId'];
  1358. var idx = 0;
  1359. if(nid.includes('ns=')){
  1360. var ix = nid.indexOf(';');
  1361. var ns = nid.substring(3,ix);
  1362. idx = parseInt(ns);
  1363. }
  1364. await checkRefs(entry, m, url);
  1365. var nid_t = "";
  1366. if(nid.includes('i=')){
  1367. nid_t = 'Numeric';
  1368. }else if(nid.includes('s=')){
  1369. nid_t = 'String';
  1370. }
  1371. var valrank = 0;
  1372. if(entry['ValueRank']){
  1373. valrank = entry['ValueRank'];
  1374. }
  1375. var arrdim = 0;
  1376. if(entry['ArrayDimensions']){
  1377. arrdim = entry['ArrayDimensions'];
  1378. }
  1379. var acclev = 0;
  1380. if(entry['AccessLevel']){
  1381. acclev = entry['AccessLevel'];
  1382. }
  1383. var minsamp = 0;
  1384. if(entry['MinimumSamplingInterval']){
  1385. minsamp = entry['MinimumSamplingInterval'];
  1386. }
  1387. var dt = entry['DataType'];
  1388. if(entry['DataType'] && dt.includes('=')){
  1389. dt = await getDataType(dt, m);
  1390. }
  1391. var tt = await getTypeDef(entry['NodeId'], m);
  1392. let pnode = await getParentRef(entry, m);
  1393. command = "INSERT INTO ns"+m+"variables(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, typedefinition, description, datatype, valuerank, arraydimensions, accesslevel, minsamplinginterval, releasestatus) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+tt+"', '"+entry['Description']+"', '"+dt+"', '"+valrank+"', '"+arrdim+"', '"+acclev+"', '"+minsamp+"', '"+entry['ReleaseStatus']+"');";
  1394. ret = await pool.query(command);
  1395. }
  1396. }else{
  1397. var entry = obj;
  1398. var nid = entry['NodeId'];
  1399. var idx = 0;
  1400. if(nid.includes('ns=')){
  1401. var ix = nid.indexOf(';');
  1402. var ns = nid.substring(3,ix);
  1403. idx = parseInt(ns);
  1404. }
  1405. await checkRefs(entry, m, url);
  1406. var nid_t = "";
  1407. if(nid.includes('i=')){
  1408. nid_t = 'Numeric';
  1409. }else if(nid.includes('s=')){
  1410. nid_t = 'String';
  1411. }
  1412. var valrank = 0;
  1413. if(entry['ValueRank']){
  1414. valrank = entry['ValueRank'];
  1415. }
  1416. var arrdim = 0;
  1417. if(entry['ArrayDimensions']){
  1418. arrdim = entry['ArrayDimensions'];
  1419. }
  1420. var acclev = 0;
  1421. if(entry['AccessLevel']){
  1422. acclev = entry['AccessLevel'];
  1423. }
  1424. var minsamp = 0;
  1425. if(entry['MinimumSamplingInterval']){
  1426. minsamp = entry['MinimumSamplingInterval'];
  1427. }
  1428. var dt = entry['DataType'];
  1429. if(entry['DataType'] && dt.includes('=')){
  1430. dt = await getDataType(nid, m);
  1431. }
  1432. var tt = await getTypeDef(entry['NodeId'], m);
  1433. let pnode = await getParentRef(entry, m);
  1434. command = "INSERT INTO ns"+m+"variables(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, typedefinition, parentid, description, datatype, valuerank, arraydimensions, accesslevel, minsamplinginterval, releasestatus) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+tt+"','#', '"+entry['Description']+"', '"+dt+"', '"+valrank+"', '"+arrdim+"', '"+acclev+"', '"+minsamp+"', '"+entry['ReleaseStatus']+"');";
  1435. ret = await pool.query(command);
  1436. }
  1437. }
  1438. }catch(err){
  1439. console.log(err);
  1440. }
  1441. }
  1442. async function createVarTypes(m){
  1443. try{
  1444. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"variabletypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'VariableType', 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), datatype VARCHAR(300) NOT NULL, value VARCHAR(500) DEFAULT NULL, valuerank INT DEFAULT NULL, arraydimensions INT, isabstract VARCHAR(10), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1445. var ret = await pool.query(command);
  1446. let obj = nsray[m].UANodeSet.UAVariableType;
  1447. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1448. if(nsray[m].UANodeSet.UAVariableType){
  1449. if(Array.isArray(obj)){
  1450. var sz = obj.length;
  1451. for(let i = 0; i < sz; i++){
  1452. console.log(obj[i]);
  1453. var entry = obj[i];
  1454. var nid = entry['NodeId'];
  1455. var idx = 0;
  1456. if(nid.includes('ns=')){
  1457. var ix = nid.indexOf(';');
  1458. var ns = nid.substring(3,ix);
  1459. idx = parseInt(ns);
  1460. }
  1461. await checkRefs(entry, m, url);
  1462. var nid_t = "";
  1463. if(nid.includes('i=')){
  1464. nid_t = 'Numeric';
  1465. }else if(nid.includes('s=')){
  1466. nid_t = 'String';
  1467. }
  1468. var valrank = 0;
  1469. if(entry['ValueRank']){
  1470. valrank = entry['ValueRank'];
  1471. }
  1472. var arrdim = 0;
  1473. if(entry['ArrayDimensions']){
  1474. console.log('Here');
  1475. console.log(entry['ArrayDimensions']);
  1476. arrdim = entry['ArrayDimensions'];
  1477. }
  1478. var isabstr = "TBD";
  1479. if(entry['IsAbstract']){
  1480. isabstr = entry['IsAbstract'];
  1481. }
  1482. var dt = entry['DataType'];
  1483. if(entry['DataType'] && dt.includes('=')){
  1484. dt = await getDataType(nid, m);
  1485. }
  1486. let pnode = await getParentRef(entry, m);
  1487. command = "INSERT INTO ns"+m+"variabletypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, description, datatype, valuerank, arraydimensions, isabstract, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+dt+"', '"+valrank+"', '"+arrdim+"', '"+isabstr+"', '"+entry['Documentation']+"');";
  1488. ret = pool.query(command);
  1489. }
  1490. }else{
  1491. var entry = obj;
  1492. var nid = entry['NodeId'];
  1493. var idx = 0;
  1494. if(nid.includes('ns=')){
  1495. var ix = nid.indexOf(';');
  1496. var ns = nid.substring(3,ix);
  1497. idx = parseInt(ns);
  1498. }
  1499. await checkRefs(entry, m, url);
  1500. var nid_t = "";
  1501. if(nid.includes('i=')){
  1502. nid_t = 'Numeric';
  1503. }else if(nid.includes('s=')){
  1504. nid_t = 'String';
  1505. }
  1506. var valrank = 0;
  1507. if(entry['ValueRank']){
  1508. valrank = entry['ValueRank'];
  1509. }
  1510. var arrdim = 0;
  1511. if(entry['ArrayDimensions']){
  1512. console.log('Here');
  1513. console.log(entry['ArrayDimensions']);
  1514. arrdim = entry['ArrayDimensions'];
  1515. }
  1516. var isabstr = "TBD";
  1517. if(entry['IsAbstract']){
  1518. isabstr = entry['IsAbstract'];
  1519. }
  1520. var dt = entry['DataType'];
  1521. if(entry['DataType'] && dt.includes('=')){
  1522. dt = await getDataType(nid, m);
  1523. }
  1524. let pnode = await getParentRef(entry, m);
  1525. command = "INSERT INTO ns"+m+"variabletypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, description, datatype, valuerank, arraydimensions, isabstract, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"','"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+dt+"', '"+valrank+"', '"+arrdim+"', '"+isabstr+"', '"+entry['Documentation']+"');";
  1526. ret = pool.query(command);
  1527. }
  1528. }
  1529. }catch(err){
  1530. console.log(err);
  1531. }
  1532. }
  1533. async function createMethods(m){
  1534. try{
  1535. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"methods(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'Method', 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), modellingrule VARCHAR(100) DEFAULT 'Optional', executable INT DEFAULT 1, parentreference VARCHAR(300), parentid VARCHAR(300) DEFAULT '#', methoddeclarationid VARCHAR(300), parentinverse VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1536. var ret = await pool.query(command);
  1537. let obj = nsray[m].UANodeSet.UAMethod;
  1538. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1539. if(nsray[m].UANodeSet.UAMethod){
  1540. if(Array.isArray(obj)){
  1541. var sz = obj.length;
  1542. for(let i = 0; i < sz; i++){
  1543. var entry = obj[i];
  1544. var nid = entry['NodeId'];
  1545. var idx = 0;
  1546. if(nid.includes('ns=')){
  1547. var ix = nid.indexOf(';');
  1548. var ns = nid.substring(3,ix);
  1549. idx = parseInt(ns);
  1550. }
  1551. await checkRefs(entry, m, url);
  1552. var nid_t = "";
  1553. if(nid.includes('i=')){
  1554. nid_t = 'Numeric';
  1555. }else if(nid.includes('s=')){
  1556. nid_t = 'String';
  1557. }
  1558. let pnode = await getParentRef(entry, m);
  1559. command = "INSERT INTO ns"+m+"methods(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, description, methoddeclarationid) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+entry['MethodDeclarationId']+"');";
  1560. ret = pool.query(command);
  1561. }
  1562. }else{
  1563. var entry = obj;
  1564. var nid = entry['NodeId'];
  1565. var idx = 0;
  1566. if(nid.includes('ns=')){
  1567. var ix = nid.indexOf(';');
  1568. var ns = nid.substring(3,ix);
  1569. idx = parseInt(ns);
  1570. }
  1571. await checkRefs(entry, m, url);
  1572. var nid_t = "";
  1573. if(nid.includes('i=')){
  1574. nid_t = 'Numeric';
  1575. }else if(nid.includes('s=')){
  1576. nid_t = 'String';
  1577. }
  1578. let pnode = await getParentRef(entry, m);
  1579. command = "INSERT INTO ns"+m+"methods(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, description, methoddeclarationid) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+entry['MethodDeclarationId']+"');";
  1580. ret = pool.query(command);
  1581. }
  1582. }
  1583. }catch(err){
  1584. console.log(err);
  1585. res.json({result:"NOK"});
  1586. }
  1587. }
  1588. async function createDataTypes(m){
  1589. try{
  1590. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"datatypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, nodeidtype VARCHAR(100) NOT NULL, name VARCHAR(300) NOT NULL, nodeclass VARCHAR(50) DEFAULT 'DataType', 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), parentid VARCHAR(300) DEFAULT '#', parentreference VARCHAR(300), parentinverse VARCHAR(10), definition VARCHAR(300), releasestatus VARCHAR(300), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1591. var ret = await pool.query(command);
  1592. let obj = nsray[m].UANodeSet.UADataType;
  1593. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1594. if(nsray[m].UANodeSet.UADataType){
  1595. if(Array.isArray(obj)){
  1596. var sz = obj.length;
  1597. for(let i = 0; i < sz; i++){
  1598. var entry = obj[i];
  1599. var nid = entry['NodeId'];
  1600. var idx = 0;
  1601. if(nid.includes('ns=')){
  1602. var ix = nid.indexOf(';');
  1603. var ns = nid.substring(3,ix);
  1604. idx = parseInt(ns);
  1605. }
  1606. await checkRefs(entry, m, url);
  1607. var nid_t = "";
  1608. if(nid.includes('i=')){
  1609. nid_t = 'Numeric';
  1610. }else if(nid.includes('s=')){
  1611. nid_t = 'String';
  1612. }
  1613. let pnode = await getParentRef(entry, m);
  1614. command = "INSERT INTO ns"+m+"datatypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, description, isabstract, definition, releasestatus, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Definition']+"', '"+entry['ReleaseStatus']+"', '"+entry['Documentation']+"');";
  1615. ret = pool.query(command);
  1616. }
  1617. }else{
  1618. var entry = obj;
  1619. var nid = entry['NodeId'];
  1620. var idx = 0;
  1621. if(nid.includes('ns=')){
  1622. var ix = nid.indexOf(';');
  1623. var ns = nid.substring(3,ix);
  1624. idx = parseInt(ns);
  1625. }
  1626. await checkRefs(entry, m, url);
  1627. var nid_t = "";
  1628. if(nid.includes('i=')){
  1629. nid_t = 'Numeric';
  1630. }else if(nid.includes('s=')){
  1631. nid_t = 'String';
  1632. }
  1633. let pnode = await getParentRef(entry, m);
  1634. command = "INSERT INTO ns"+m+"datatypes(nodeid, nodeidtype, nsindex, name, displayname, browsename, parentid, parentreference, parentinverse, description, isabstract, definition, releasestatus, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Definition']+"', '"+entry['ReleaseStatus']+"', '"+entry['Documentation']+"');";
  1635. ret = pool.query(command);
  1636. }
  1637. }
  1638. }catch(err){
  1639. console.log(err);
  1640. res.json({result:"NOK"});
  1641. }
  1642. }
  1643. async function createRefTypes(m){
  1644. try{
  1645. var command = "CREATE TABLE IF NOT EXISTS ns"+m+"referencetypes(id INT AUTO_INCREMENT, nodeid VARCHAR(300) NOT NULL UNIQUE, 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 VARCHAR(10), documentation VARCHAR(300), comment VARCHAR(300), PRIMARY KEY(id));";
  1646. var ret = await pool.query(command);
  1647. let obj = nsray[m].UANodeSet.UAReferenceType;
  1648. var url = nsray[m].UANodeSet.Models.Model.ModelUri;
  1649. if(nsray[m].UANodeSet.UAReferenceType){
  1650. if(Array.isArray(obj)){
  1651. var sz = obj.length;
  1652. for(let i = 0; i < sz; i++){
  1653. var entry = obj[i];
  1654. var nid = entry['NodeId'];
  1655. var idx = m;
  1656. if(nid.includes('ns=')){
  1657. var ix = nid.indexOf(';');
  1658. var ns = nid.substring(3,ix);
  1659. idx = parseInt(ns);
  1660. }
  1661. await checkRefs(entry, m, url);
  1662. var nid_t = "";
  1663. if(nid.includes('i=')){
  1664. nid_t = 'Numeric';
  1665. }else if(nid.includes('s=')){
  1666. nid_t = 'String';
  1667. }
  1668. let pnode = await getParentRef(entry, m);
  1669. command = "INSERT INTO ns"+m+"referencetypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, description, isabstract, symmetric, inversename, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Symmetric']+"', '"+entry['InverseName']+"', '"+entry['Documentation']+"');";
  1670. ret = pool.query(command);
  1671. }
  1672. }else{
  1673. var entry = obj;
  1674. var nid = entry['NodeId'];
  1675. var idx = m;
  1676. if(nid.includes('ns=')){
  1677. var ix = nid.indexOf(';');
  1678. var ns = nid.substring(3,ix);
  1679. idx = parseInt(ns);
  1680. }
  1681. await checkRefs(entry, m, url);
  1682. var nid_t = "";
  1683. if(nid.includes('i=')){
  1684. nid_t = 'Numeric';
  1685. }else if(nid.includes('s=')){
  1686. nid_t = 'String';
  1687. }
  1688. let pnode = await getParentRef(entry, m);
  1689. command = "INSERT INTO ns"+m+"referencetypes(nodeid, nodeidtype, nsindex, nsurl, name, displayname, browsename, parentid, parentreference, parentinverse, parentreference, parentinverse, description, isabstract, symmetric, inversename, documentation) VALUES ('"+entry['NodeId']+"', '"+nid_t+"', '"+idx+"', '"+url+"', '"+entry['DisplayName']+"', '"+entry['DisplayName']+"', '"+entry['BrowseName']+"', '"+pnode.pnid+"', '"+pnode.pref+"', '"+pnode.pinv+"', '"+entry['Description']+"', '"+entry['IsAbstract']+"', '"+entry['Symmetric']+"', '"+entry['InverseName']+"', '"+entry['Documentation']+"');";
  1690. ret = pool.query(command);
  1691. }
  1692. }
  1693. }catch(err){
  1694. console.log(err);
  1695. res.json({result:"NOK"});
  1696. }
  1697. }
  1698. app.get('/obj', async function(req, res){
  1699. try{
  1700. var key = req.body;
  1701. var len = nsray.length;
  1702. for(let m = 0; m < nsray.length; m++){
  1703. await createObj(m);
  1704. }
  1705. res.json({result:'OK',success:true});
  1706. }catch(err){
  1707. console.log(err);
  1708. res.json({result:"NOK"});
  1709. }
  1710. })
  1711. app.get('/obj/:id', async function(req, res){
  1712. try{
  1713. var key = req.body;
  1714. var m = parseInt(req.params["id"]);
  1715. await createObj(m);
  1716. res.json({result:'OK',success:true});
  1717. }catch(err){
  1718. console.log(err);
  1719. res.json({result:"NOK"});
  1720. }
  1721. })
  1722. app.get('/objtypes', async function(req, res){
  1723. try{
  1724. var key = req.body;
  1725. var len = nsray.length;
  1726. for(let m = 0; m < nsray.length; m++){
  1727. await createObjTypes(m);
  1728. }
  1729. res.json({result:'OK',success:true});
  1730. }catch(err){
  1731. console.log(err);
  1732. res.json({result:"NOK"});
  1733. }
  1734. })
  1735. app.get('/objtypes/:id', async function(req, res){
  1736. try{
  1737. var m = parseInt(req.params["id"]);
  1738. await createObjTypes(m);
  1739. res.json({result:'OK',success:true});
  1740. }catch(err){
  1741. console.log(err);
  1742. res.json({result:"NOK"});
  1743. }
  1744. })
  1745. app.get('/var', async function(req, res){
  1746. try{
  1747. var key = req.body;
  1748. var len = nsray.length;
  1749. for(let m = 0; m < nsray.length; m++){
  1750. await createVar(m);
  1751. }
  1752. res.json({result:'OK',success:true});
  1753. }catch(err){
  1754. console.log(err);
  1755. res.json({result:"NOK"});
  1756. }
  1757. })
  1758. app.get('/var/:id', async function(req, res){
  1759. try{
  1760. var m = parseInt(req.params["id"]);
  1761. await createVar(m);
  1762. res.json({result:'OK',success:true});
  1763. }catch(err){
  1764. console.log(err);
  1765. res.json({result:"NOK"});
  1766. }
  1767. })
  1768. app.get('/vartypes', async function(req, res){
  1769. try{
  1770. var key = req.body;
  1771. var len = nsray.length;
  1772. for(let m = 0; m < nsray.length; m++){
  1773. await createVarTypes(m);
  1774. }
  1775. res.json({result:'OK',success:true});
  1776. }catch(err){
  1777. console.log(err);
  1778. res.json({result:"NOK"});
  1779. }
  1780. })
  1781. app.get('/vartypes/:id', async function(req, res){
  1782. try{
  1783. var m = parseInt(req.params["id"]);
  1784. await createVarTypes(m);
  1785. res.json({result:'OK',success:true});
  1786. }catch(err){
  1787. console.log(err);
  1788. res.json({result:"NOK"});
  1789. }
  1790. })
  1791. app.get('/methods', async function(req, res){
  1792. try{
  1793. var key = req.body;
  1794. var len = nsray.length;
  1795. for(let m = 0; m < nsray.length; m++){
  1796. await createMethods(m);
  1797. }
  1798. res.json({result:'OK',success:true});
  1799. }catch(err){
  1800. console.log(err);
  1801. res.json({result:"NOK"});
  1802. }
  1803. })
  1804. app.get('/methods/:id', async function(req, res){
  1805. try{
  1806. var m = parseInt(req.params["id"]);
  1807. await createMethods(m);
  1808. res.json({result:'OK',success:true});
  1809. }catch(err){
  1810. console.log(err);
  1811. res.json({result:"NOK"});
  1812. }
  1813. })
  1814. app.get('/datatypes', async function(req, res){
  1815. try{
  1816. var key = req.body;
  1817. var len = nsray.length;
  1818. for(let m = 0; m < nsray.length; m++){
  1819. await createDataTypes(m);
  1820. }
  1821. res.json({result:'OK',success:true});
  1822. }catch(err){
  1823. console.log(err);
  1824. res.json({result:"NOK"});
  1825. }
  1826. })
  1827. app.get('/datatypes/:id', async function(req, res){
  1828. try{
  1829. var m = parseInt(req.params["id"]);
  1830. await createDataTypes(m);
  1831. res.json({result:'OK',success:true});
  1832. }catch(err){
  1833. console.log(err);
  1834. res.json({result:"NOK"});
  1835. }
  1836. })
  1837. app.get('/reftypes', async function(req, res){
  1838. try{
  1839. var key = req.body;
  1840. var len = nsray.length;
  1841. for(let m = 0; m < nsray.length; m++){
  1842. await createRefTypes(m);
  1843. }
  1844. res.json({result:'OK',success:true});
  1845. }catch(err){
  1846. console.log(err);
  1847. res.json({result:"NOK"});
  1848. }
  1849. })
  1850. app.get('/reftypes/:id', async function(req, res){
  1851. try{
  1852. var m = parseInt(req.params["id"]);
  1853. await createRefTypes(m);
  1854. res.json({result:'OK',success:true});
  1855. }catch(err){
  1856. console.log(err);
  1857. res.json({result:"NOK"});
  1858. }
  1859. })
  1860. app.get('/createnodes/:id', async function(req, res){
  1861. try{
  1862. var m = parseInt(req.params["id"]);
  1863. await createDataTypes(m);
  1864. await createObjTypes(m);
  1865. await createVarTypes(m);
  1866. await createRefTypes(m);
  1867. await createObj(m);
  1868. await createVar(m);
  1869. await createMethods(m);
  1870. res.json({result:'OK',success:true});
  1871. }catch(err){
  1872. console.log(err);
  1873. res.json({result:"NOK"});
  1874. }
  1875. })
  1876. app.get('/namesp', async function(req, res){
  1877. try{
  1878. var key = req.body;
  1879. var sz = nsray.length;
  1880. //-------ns0--------------
  1881. 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));";
  1882. var ret = await pool.query(command);
  1883. command = "INSERT INTO ns0depends(nsindex, nsurl, publicationdate, version) VALUES ('0','http://opcfoundation.org/UA/','"+jsn.UANodeSet.Models.Model['PublicationDate']+"','"+jsn.UANodeSet.Models.Model['Version']+"');";
  1884. ret = pool.query(command);
  1885. //----------------ns0--------------
  1886. for(let i = 1; i < sz; i++){
  1887. var entry0 = nsray[i].UANodeSet.NamespaceUris.Uri;
  1888. 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));";
  1889. ret = await pool.query(command);
  1890. 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']+"');";
  1891. ret = pool.query(command);
  1892. if(Array.isArray(entry0)){
  1893. var szy = entry0.length;
  1894. for(let y = 0; y < szy; y++){
  1895. var ns = entry0[y];
  1896. command = "INSERT INTO ns"+i+"depends(nsindex, nsurl) VALUES ('"+(y+1)+"','"+ns+"');";
  1897. ret = pool.query(command);
  1898. }
  1899. }else{
  1900. var ns = entry0;
  1901. command = "INSERT INTO ns"+i+"depends(nsindex, nsurl) VALUES ('1','"+entry0+"');";
  1902. ret = pool.query(command);
  1903. }
  1904. var entry = nsray[i].UANodeSet.Models.Model.RequiredModel;
  1905. command = "UPDATE ns"+i+"depends SET publicationdate = '"+nsray[i].UANodeSet.Models.Model['PublicationDate']+"' WHERE nsurl = '"+nsray[i].UANodeSet.Models.Model['ModelUri']+"';";
  1906. ret = pool.query(command);
  1907. command = "UPDATE ns"+i+"depends SET version = '"+nsray[i].UANodeSet.Models.Model['Version']+"' WHERE nsurl = '"+nsray[i].UANodeSet.Models.Model['ModelUri']+"';";
  1908. ret = pool.query(command);
  1909. if(Array.isArray(entry)){
  1910. var szy = entry.length;
  1911. for(let y = 0; y < szy; y++){
  1912. var ns0 = entry[y];
  1913. command = "UPDATE ns"+i+"depends SET publicationdate = '"+ns0['PublicationDate']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1914. ret = pool.query(command);
  1915. command = "UPDATE ns"+i+"depends SET version = '"+ns0['Version']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1916. ret = pool.query(command);
  1917. }
  1918. }else{
  1919. var ns0 = entry;
  1920. command = "UPDATE ns"+i+"depends SET publicationdate = '"+ns0['PublicationDate']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1921. ret = pool.query(command);
  1922. command = "UPDATE ns"+i+"depends SET version = '"+ns0['Version']+"' WHERE nsurl = '"+ns0['ModelUri']+"';";
  1923. ret = pool.query(command);
  1924. }
  1925. }
  1926. res.json({result:'OK',success:true});
  1927. }catch(err){
  1928. console.log(err);
  1929. res.json({result:"NOK"});
  1930. }
  1931. })
  1932. app.get('/allrefs', async function(req, res){
  1933. try{
  1934. console.log(arref);
  1935. res.json({result:'OK',success:true});
  1936. }catch(err){
  1937. console.log("NOK");
  1938. res.json({result:"NOK"});
  1939. }
  1940. })
  1941. app.get('/init', async function(req, res){
  1942. try{
  1943. var len = nsray.length;
  1944. for(let m = 0; m < nsray.length; m++){
  1945. await createNamespace(m);
  1946. }
  1947. res.json({result:'OK',success:true});
  1948. }catch(err){
  1949. console.log("NOK");
  1950. res.json({result:"NOK"});
  1951. }
  1952. })
  1953. app.get('/init/:ns', async function(req, res){
  1954. try{
  1955. var n = req.params["ns"];
  1956. await createNamespace(n);
  1957. res.json({result:'OK',success:true});
  1958. }catch(err){
  1959. console.log("NOK");
  1960. res.json({result:"NOK"});
  1961. }
  1962. })
  1963. /*
  1964. app.post('/key', async function(req, res){
  1965. try{
  1966. var key = req.body;
  1967. console.log(key);
  1968. var ret = await gen_query("SELECT name FROM mitarbeiter WHERE key_id='"+key['key_id']+"';");
  1969. res.json({result:ret[0].name,success:true});
  1970. }catch(err){
  1971. console.log("NOK");
  1972. res.json({result:"NOK"});
  1973. }
  1974. })
  1975. */
  1976. /*
  1977. app.get('/look/:ix/:id/:eclass/:attr', async function(req, res){
  1978. try{
  1979. var ix = req.params["ix"];
  1980. var id = req.params["id"];
  1981. var cls = req.params["eclass"];
  1982. var attr = req.params["attr"];
  1983. var class_name = "";
  1984. switch(cls){
  1985. case "ObjectType": class_name="objecttypes"; break;
  1986. case "Object": class_name="objects"; break;
  1987. case "VariableType": class_name="variabletypes"; break;
  1988. case "DataType": class_name="datatypes"; break;
  1989. case "ReferenceType": class_name="referencetypes"; break;
  1990. case "Variable": class_name="variables"; break;
  1991. case "Method": class_name="methods"; break;
  1992. default: class_name="objects";
  1993. }
  1994. var ret = await getThisNodeAttribute(ix, id, class_name, attr);
  1995. res.json({result:ret,success:true});
  1996. }catch(err){
  1997. console.log(err);
  1998. res.json({result:"NOK"});
  1999. }
  2000. })
  2001. */
  2002. app.get('/find/:ix/:id/:eclass', async function(req, res){
  2003. try{
  2004. var ix = req.params["ix"];
  2005. var id = req.params["id"];
  2006. var cls = req.params["eclass"];
  2007. var class_name = "";
  2008. switch(cls){
  2009. case "ObjectType": class_name="objecttypes"; break;
  2010. case "Object": class_name="objects"; break;
  2011. case "VariableType": class_name="variabletypes"; break;
  2012. case "DataType": class_name="datatypes"; break;
  2013. case "ReferenceType": class_name="referencetypes"; break;
  2014. case "Variable": class_name="variables"; break;
  2015. case "Method": class_name="methods"; break;
  2016. default: class_name="objects";
  2017. }
  2018. var ret = await getThisNode(ix, id, class_name);
  2019. res.json(ret);
  2020. }catch(err){
  2021. console.log(err);
  2022. res.json({result:"NOK"});
  2023. }
  2024. })
  2025. app.get('/children/sql/:ix/:id', async function(req, res){
  2026. try{
  2027. var ix = req.params["ix"];
  2028. var id = req.params["id"];
  2029. var ret = await getChildrenSql(ix, id);
  2030. res.json({num:ret.length, result:ret, success: true});
  2031. }catch(err){
  2032. console.log(err);
  2033. res.json({result:"NOK"});
  2034. }
  2035. })
  2036. app.get('/typedef', async function(req, res){
  2037. try{
  2038. var ret = await getTypeDef("ns=1;i=103", 4);
  2039. res.json({result:ret,success:true});
  2040. }catch(err){
  2041. console.log(err);
  2042. res.json({result:"NOK"});
  2043. }
  2044. })
  2045. app.get('/parent', async function(req, res){
  2046. try{
  2047. var ret = await getParentRef("ns=1;i=118", 4);
  2048. res.json({result:ret,success:true});
  2049. }catch(err){
  2050. console.log(err);
  2051. res.json({result:"NOK"});
  2052. }
  2053. })
  2054. app.get('/delete', async function(req, res){
  2055. try{
  2056. for(let i = 1; i < 5; i++){
  2057. var command = "DROP TABLE ns"+i+"objects;";
  2058. var ret = await pool.query(command);
  2059. var command = "DROP TABLE ns"+i+"objecttypes;";
  2060. var ret = await pool.query(command);
  2061. var command = "DROP TABLE ns"+i+"variables;";
  2062. var ret = await pool.query(command);
  2063. var command = "DROP TABLE ns"+i+"variabletypes;";
  2064. var ret = await pool.query(command);
  2065. var command = "DROP TABLE ns"+i+"datatypes;";
  2066. var ret = await pool.query(command);
  2067. var command = "DROP TABLE ns"+i+"referencetypes;";
  2068. var ret = await pool.query(command);
  2069. var command = "DROP TABLE ns"+i+"references;";
  2070. var ret = await pool.query(command);
  2071. var command = "DROP TABLE ns"+i+"methods;";
  2072. var ret = await pool.query(command);
  2073. }
  2074. res.json({result:"OK",success:true});
  2075. }catch(err){
  2076. console.log(err);
  2077. res.json({result:"NOK"});
  2078. }
  2079. })
  2080. app.get('/delete/:id', async function(req, res){
  2081. try{
  2082. var i = req.params["id"];
  2083. var command = "DROP TABLE ns"+i+"objects;";
  2084. var ret = await pool.query(command);
  2085. var command = "DROP TABLE ns"+i+"objecttypes;";
  2086. var ret = await pool.query(command);
  2087. var command = "DROP TABLE ns"+i+"variables;";
  2088. var ret = await pool.query(command);
  2089. var command = "DROP TABLE ns"+i+"variabletypes;";
  2090. var ret = await pool.query(command);
  2091. var command = "DROP TABLE ns"+i+"datatypes;";
  2092. var ret = await pool.query(command);
  2093. var command = "DROP TABLE ns"+i+"referencetypes;";
  2094. var ret = await pool.query(command);
  2095. var command = "DROP TABLE ns"+i+"references;";
  2096. var ret = await pool.query(command);
  2097. var command = "DROP TABLE ns"+i+"methods;";
  2098. var ret = await pool.query(command);
  2099. res.json({result:"OK",success:true});
  2100. }catch(err){
  2101. console.log(err);
  2102. res.json({result:"NOK"});
  2103. }
  2104. })
  2105. app.get('/requirejson/:ident/:name',(req, res) =>{
  2106. try{
  2107. var namejs = req.params["name"];
  2108. var shorty = req.params["ident"];
  2109. const id = "./"+namejs+".json";
  2110. const fl = require(id);
  2111. for(let i = 0; i < ns_array.length; i++){
  2112. if(ns_array[i][1] === shorty){
  2113. return res.json({result:"Array already includes element."})
  2114. }
  2115. }
  2116. ns_array.push([fl, shorty, fl.UANodeSet.Models.Model.ModelUri]);
  2117. res.json({result:"OK"});
  2118. }catch(err){
  2119. console.log("NOK");
  2120. res.json({result:"NOK", error: "Json file may not be available. Call list json files."});
  2121. }
  2122. })
  2123. app.get('/shownsarray',(req, res) =>{
  2124. try{ let str = '';
  2125. for(let i = 0; i < ns_array.length; i++){
  2126. str += '('+i+': '+ns_array[i][1]+')';
  2127. }
  2128. res.json({result:str});
  2129. console.log(ns_array);
  2130. }catch(err){
  2131. console.log("NOK");
  2132. res.json({result:"NOK", error: "Json file may not be available. Call list json files."});
  2133. }
  2134. })
  2135. app.get('/getredis',(req, res) =>{
  2136. try{
  2137. redis_get();
  2138. res.json({result:"OK"});
  2139. }catch(err){
  2140. console.log("NOK");
  2141. res.json({result:"NOK"});
  2142. }
  2143. })
  2144. app.get('/get_root',(req, res) =>{
  2145. try{
  2146. let rt = jsn.UANodeSet.UAObject.find( record => record.NodeId === "i=84");
  2147. let resj = {
  2148. id: rt.NodeId,
  2149. parent: "#",
  2150. text: rt.DisplayName};
  2151. res.json(resj);
  2152. }catch(err){
  2153. console.log("NOK");
  2154. res.json({result:"NOK"});
  2155. }
  2156. })
  2157. app.get('/get_children/base/:id',(req, res) =>{
  2158. var nid = req.params["id"];
  2159. try{
  2160. if(Array.isArray(jsn.UANodeSet.UAObject)){
  2161. for (let i = 0; i < jsn.UANodeSet.UAObject.length;i++){
  2162. if(Array.isArray(jsn.UANodeSet.UAObject[i].References.Reference)){
  2163. for (let x = 0; x < jsn.UANodeSet.UAObject[i].References.Reference.length;x++){
  2164. if(jsn.UANodeSet.UAObject[i].References.Reference[x].$t === nid){
  2165. console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject[i].References.Reference[x]) +jsn.UANodeSet.UAObject[i].References.Reference[x].ReferenceType);
  2166. }
  2167. }
  2168. }else{
  2169. if(jsn.UANodeSet.UAObject[i].References.Reference.$t === nid){
  2170. console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject[i].References.Reference) +jsn.UANodeSet.UAObject[i].References.Reference.ReferenceType);
  2171. }
  2172. }
  2173. }
  2174. }else{
  2175. if(Array.isArray(jsn.UANodeSet.UAObject.References.Reference)){
  2176. for (let x = 0; x < jsn.UANodeSet.UAObject.References.Reference.length;x++){
  2177. if(jsn.UANodeSet.UAObject[i].References.Reference[x].$t === nid){
  2178. console.log(jsn.UANodeSet.UAObject[i].BrowseName + inverse(jsn.UANodeSet.UAObject.References.Reference[x]) +jsn.UANodeSet.UAObject.References.Reference[x].ReferenceType);
  2179. }
  2180. }
  2181. }else{
  2182. if(jsn.UANodeSet.UAObject.References.Reference.$t === nid){
  2183. console.log(jsn.UANodeSet.UAObject.BrowseName + inverse(jsn.UANodeSet.UAObject.References.Reference) +jsn.UANodeSet.UAObject.References.Reference.ReferenceType);
  2184. }
  2185. }
  2186. }
  2187. console.log('');
  2188. res.json({result:"OK"});
  2189. }catch(err){
  2190. console.log("NOK");
  2191. res.json({result:"NOK"});
  2192. }
  2193. })
  2194. app.get('/get_children/all/:ns/:id',(req, res) =>{
  2195. var ret_obj = [];
  2196. var ns = req.params["ns"];
  2197. var id = req.params["id"];
  2198. var nid = 'ns='+ns+';'+'i='+id;
  2199. console.log(nid);
  2200. get_Children(di, nid, ret_obj);
  2201. get_Children(ia, nid, ret_obj);
  2202. get_Children(mach, nid, ret_obj);
  2203. get_Children(mt, nid, ret_obj);
  2204. res.json(ret_obj);
  2205. })
  2206. app.get('/getNode/all/:ns/:id',(req, res) =>{
  2207. var ret_obj = [];
  2208. var ns = req.params["ns"];
  2209. var id = req.params["id"];
  2210. var nid = 'ns='+ns+';'+'i='+id;
  2211. console.log(nid);
  2212. get_Children(di, nid, ret_obj);
  2213. get_Children(ia, nid, ret_obj);
  2214. get_Children(mach, nid, ret_obj);
  2215. get_Children(mt, nid, ret_obj);
  2216. let node = {
  2217. id:nid,
  2218. text: "home",
  2219. children:ret_obj
  2220. }
  2221. res.json(node);
  2222. })
  2223. app.get('/flushall',(req, res) =>{
  2224. redis_flush();
  2225. res.json({result:"OK"});
  2226. })
  2227. app.get('/p2json/:nodeset/:ident',(req, res) =>{
  2228. var name = req.params["nodeset"];
  2229. var shorty = req.params["ident"];
  2230. p2json(name, shorty);
  2231. res.json({result:"OK"});
  2232. })
  2233. app.get('/list_projects', (req, res) => { //reacts to requests -> /list_projects
  2234. const output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
  2235. var out = output.split("\n");
  2236. if(out[out.length-1] === ""){
  2237. out.splice(-1,1);
  2238. }
  2239. console.log("Response: ", out);
  2240. res.json({result:out});
  2241. })
  2242. app.get('/list_nodesets', (req, res) => { //reacts to requests -> /list_nodesets
  2243. const output = execSync("cd .. && cd nodesets && ls", { encoding: 'utf-8' });
  2244. var out = output.split("\n");
  2245. var result = [];
  2246. for(let i = 0; i < out.length; i++){
  2247. if(out[i].includes(".xml")){
  2248. result.push(out[i]);
  2249. }
  2250. }
  2251. console.log("Response: ", result);
  2252. res.json({result:result});
  2253. })
  2254. app.get('/new_project', (req, res) => { //reacts to requests -> /new_project?name=myproject
  2255. const name = req.query.name; //project name
  2256. const output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
  2257. var out = output.split("\n");
  2258. var result = "";
  2259. var err = "Error - Project already exists.";
  2260. for(let i = 0; i < out.length; i++){
  2261. if(out[i] === name){
  2262. return res.json({result:err});
  2263. }
  2264. }
  2265. const dir = execSync("cd .. && cd Projects && mkdir "+name, { encoding: 'utf-8' });
  2266. 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' });
  2267. cp = execSync("sudo cp /home/pi/ModelingTool/nodesets/Opc.Ua.NodeSet2.json /home/pi/ModelingTool/Projects/"+name+"/Opc.Ua.NodeSet2.json", { encoding: 'utf-8' });
  2268. const cur_dir = execSync("cd .. && cd Projects && cd "+name+" && ls", { encoding: 'utf-8' });
  2269. console.log("New Project was created.");
  2270. res.json({result:cur_dir});
  2271. })
  2272. app.get('/save_project', (req, res) => { //reacts to requests -> /save_project?name=myproject
  2273. const name = req.query.name; //project name
  2274. const output = execSync("sudo cp /var/www/html/root.json /home/pi/ModelingTool/Projects/"+name+"/"+name+".json", { encoding: 'utf-8' });
  2275. console.log("Project "+name+" was saved.");
  2276. res.json({result:"Project saved"});
  2277. })
  2278. app.get('/load_json', (req, res) => { //reacts to requests -> /load_json?name=myproject
  2279. const name = req.query.name; //project name
  2280. var output = execSync("cd .. && cd Projects && ls", { encoding: 'utf-8' });
  2281. var out = output.split("\n");
  2282. var result = "";
  2283. var err = "Error - Project or file not available.";
  2284. for(let i = 0; i < out.length; i++){
  2285. if(out[i] === name){
  2286. var output1 = execSync("cd .. && cd Projects && cd "+name+" && ls", { encoding: 'utf-8' });
  2287. var out1 = output1.split("\n");
  2288. var chk = name+".json"
  2289. for(let y = 0; y < out1.length; y++){
  2290. if(out1[y] === chk){
  2291. result = execSync("sudo cp /home/pi/ModelingTool/Projects/"+name+"/"+name+".json /var/www/html/root.json", { encoding: 'utf-8' });
  2292. console.log("Project has been loaded.");
  2293. return res.json({result:"Project loaded"});
  2294. }
  2295. }
  2296. }
  2297. }
  2298. res.json({result:err});
  2299. })
  2300. app.get('/root', (req, res) => { //reacts to requests -> /root
  2301. console.log("Return root.");
  2302. 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}]}]);
  2303. })
  2304. function isChildRef(obj){
  2305. if('IsForward' in obj && obj.IsForward === 'false'){
  2306. return false;
  2307. }
  2308. if('IsForward' in obj && obj.IsForward === 'true'){
  2309. switch (obj.ReferenceType) {
  2310. case 'Organizes': return true;
  2311. case 'HasComponent': return true;
  2312. case 'HasProperty': return true;
  2313. case 'HasAddIn': return true;
  2314. case 'HasSubtype': return true;
  2315. default: return false;
  2316. }
  2317. }
  2318. switch (obj.ReferenceType) {
  2319. case 'Organizes': return true;
  2320. case 'HasComponent': return true;
  2321. case 'HasProperty': return true;
  2322. case 'HasAddIn': return true;
  2323. case 'HasSubtype': return true;
  2324. default: return false;
  2325. }
  2326. return false;
  2327. }
  2328. function checkDouble(item, obj){
  2329. for(let i = 0; i < obj.length; i++){
  2330. if(item.id === obj[i].id){
  2331. return true;
  2332. }
  2333. }
  2334. return false;
  2335. }
  2336. /*
  2337. app.get('/lazy', (req, res) => {
  2338. //console.log(req);
  2339. var ret_obj = [];
  2340. let node = {};
  2341. if(req.query.id == "#"){
  2342. //res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object"},children:true}]);
  2343. res.json([{id:"i=84",text:"Root",data:{nodeclass:"Object", idx:0},children:[{id:"i=85",text:"Objects",data:{nodeclass:"Object", idx:0},children:true},{id:"i=86",text:"Types", data:{nodeclass:"Object", idx:0},children:true},{id:"i=87",text:"View",data:{nodeclass:"Object", idx:0},children:true}]}]);
  2344. }
  2345. var nid = req.query.id;
  2346. node = searchNode(nid);
  2347. console.log(node);
  2348. if(node.data.references != null){
  2349. console.log("Here:"+node.data.references);
  2350. if(Array.isArray(node.data.references.Reference)){
  2351. console.log("And:"+node.data.references.Reference);
  2352. for(let x = 0; x < node.data.references.Reference.length; x++ ){
  2353. if(isChildRef(node.data.references.Reference[x])){
  2354. var cnode = searchNode(node.data.references.Reference[x].$t);
  2355. if(!checkDouble(cnode,ret_obj)){
  2356. ret_obj.push(cnode);
  2357. }
  2358. }
  2359. }
  2360. }else{
  2361. console.log("But:"+node.data.references);
  2362. if(isChildRef(node.data.references)){
  2363. var cnode = searchNode(node.data.references.$t);
  2364. if(!checkDouble(cnode,ret_obj)){
  2365. ret_obj.push(cnode);
  2366. }
  2367. }
  2368. }
  2369. }
  2370. getAllChildren(nid, ret_obj);
  2371. console.log(ret_obj);
  2372. res.json(ret_obj);
  2373. });
  2374. */
  2375. app.get('/lazy', async function(req, res) {
  2376. var ret_obj = [];
  2377. let node = {};
  2378. if(req.query.id == "#"){
  2379. res.json([{id:"i=84",text:"Root", type:"Object", data:{nodeclass:"Object", nsindex:0},children:[{id:"i=85",text:"Objects",type:"Object",data:{nodeclass:"Object", nsindex:0},children:true},{id:"i=86",text:"Types", type:"Object",data:{nodeclass:"Object", nsindex:0},children:true},{id:"i=87",text:"View",type:"Object",data:{nodeclass:"Object", nsindex:0},children:true}]}]);
  2380. return 0;
  2381. }
  2382. var nid = req.query.id;
  2383. var idx = req.query.nsindex;
  2384. var classn = req.query.nodeclass;
  2385. var class_name = "";
  2386. switch(classn){
  2387. case "ObjectType": class_name="objecttypes"; break;
  2388. case "Object": class_name="objects"; break;
  2389. case "VariableType": class_name="variabletypes"; break;
  2390. case "DataType": class_name="datatypes"; break;
  2391. case "ReferenceType": class_name="referencetypes"; break;
  2392. case "Variable": class_name="variables"; break;
  2393. case "Method": class_name="methods"; break;
  2394. default: class_name="objects";
  2395. }
  2396. var obj = await getThisNode(idx, nid, class_name);
  2397. //console.log(obj);
  2398. var ch = await getChildrenSql(idx, obj.id);
  2399. //console.log(ch);
  2400. var child_arr = [];
  2401. for(let j = 0; j < ch.length; j++){
  2402. classn = ch[j][2];
  2403. switch(classn){
  2404. case "ObjectType": class_name="objecttypes"; break;
  2405. case "Object": class_name="objects"; break;
  2406. case "VariableType": class_name="variabletypes"; break;
  2407. case "DataType": class_name="datatypes"; break;
  2408. case "ReferenceType": class_name="referencetypes"; break;
  2409. case "Variable": class_name="variables"; break;
  2410. case "Method": class_name="methods"; break;
  2411. default: class_name="objects";
  2412. }
  2413. console.log(ch[j][1]+","+ch[j][0]+","+class_name);
  2414. var ch0 = await getThisNode(ch[j][1],ch[j][0],class_name);
  2415. console.log(ch0);
  2416. child_arr.push(ch0);
  2417. }
  2418. //console.log(ch);
  2419. res.json([{id:obj.id, text:obj.text, type:obj.data.nodeclass, data:obj.data, children:child_arr}]);
  2420. return 0;
  2421. node = searchNode(nid);
  2422. //console.log(node);
  2423. if(node.data.references != null){
  2424. //console.log("Here:"+node.data.references);
  2425. if(Array.isArray(node.data.references.Reference)){
  2426. //console.log("And:"+node.data.references.Reference);
  2427. for(let x = 0; x < node.data.references.Reference.length; x++ ){
  2428. if(isChildRef(node.data.references.Reference[x])){
  2429. var cnode = searchNode(node.data.references.Reference[x].$t);
  2430. if(!checkDouble(cnode,ret_obj)){
  2431. ret_obj.push(cnode);
  2432. }
  2433. }
  2434. }
  2435. }else{
  2436. //console.log("But:"+node.data.references);
  2437. if(isChildRef(node.data.references)){
  2438. var cnode = searchNode(node.data.references.$t);
  2439. if(!checkDouble(cnode,ret_obj)){
  2440. ret_obj.push(cnode);
  2441. }
  2442. }
  2443. }
  2444. }
  2445. getAllChildren(nid, ret_obj);
  2446. //console.log(ret_obj);
  2447. res.json(ret_obj);
  2448. });
  2449. app.get('/index/:ns1/:ns2', (req, res) => {
  2450. var n1 = req.params["ns1"];
  2451. var n2 = req.params["ns2"];
  2452. var num = getIndexObj(ns_array[n1][0],ns_array[n2][0]);
  2453. console.log(getNode(ns_array[3][0],2,15048));
  2454. res.send("Index of "+ns_array[n2][1]+' in '+ns_array[n1][1]+' is '+num);
  2455. });
  2456. app.get('/test/:id', (req, res) => { //test
  2457. var n1 = parseInt(req.params["id"]);
  2458. console.log(ns_array[n1][1],);
  2459. var ret = searchNode("i=85");
  2460. console.log(ret);
  2461. res.send("All good");
  2462. //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}]}]);
  2463. })
  2464. app.get('/require/all', (req, res) => { //test
  2465. ns_array.push([jsn, "base", jsn.UANodeSet.Models.Model.ModelUri]);
  2466. ns_array.push([di, "di", di.UANodeSet.Models.Model.ModelUri]);
  2467. ns_array.push([ia, "ia", ia.UANodeSet.Models.Model.ModelUri]);
  2468. ns_array.push([mach, "mach", mach.UANodeSet.Models.Model.ModelUri]);
  2469. ns_array.push([mt, "mt", mt.UANodeSet.Models.Model.ModelUri]);
  2470. res.json({result:"OK"});
  2471. })
  2472. app.listen(port, () => {
  2473. console.log("Server listening at http://localhost:", port);
  2474. })