Advertisement
Guest User

Untitled

a guest
May 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. //var paramName;
  2. //var paramValue;
  3. //var headerName;
  4. //var headerValue;
  5. //var contentType;
  6. ////var globalAdjList = new Map();
  7. //var mapPackageMos = new Map();
  8. //var globalTypeMap = new Map();
  9. //var globalCosts = new Map();
  10. //var globalVisited = [];
  11. //var gbv = [];
  12. //var gbv2 = [];
  13. //var gbvCondition = [];
  14. //var globalVisited2 = [];
  15. //var globalVisited3 = [];
  16. //var globalFlag = -1;
  17. //var globalBfsTravers;
  18. // Implementation of GET call
  19.  
  20. var globalAdjList = new Map();
  21. var parentChild = new Map();
  22. var visited = [];
  23. var visited2 = [];
  24. var level = [];
  25.  
  26. function dfs(rootNode){
  27. var res = [];
  28. var stack = [];
  29. var display = "";
  30.  
  31. stack.push(rootNode);
  32. visited[rootNode] = true;
  33. level[rootNode] = 0;
  34.  
  35. while(stack.length > 0){
  36. var head = stack.pop();
  37. var currentLevel = level[head];
  38.  
  39. display += head;
  40. display += "->";
  41. //add in the final result
  42. var row = [];
  43. for(var i = 0 ; i < level[head]; i++){
  44. row.push("*");
  45. }
  46. row.push(head);
  47. res.push(row);
  48.  
  49. if(globalAdjList.get(head) == null || globalAdjList.get(head) == undefined)
  50. continue;
  51.  
  52. for(var child of globalAdjList.get(head)){
  53. // if(visited[child] == false){
  54. // level[child] = currentLevel + 1;
  55. // visited[child] = true;
  56. // stack.push(child);
  57. // }
  58. var parentChild = head + child;
  59. if(visited2[parentChild] == false){
  60. visited2[parentChild] = true;
  61. level[child] = currentLevel + 1;
  62. stack.push(child);
  63. }
  64. }
  65. }
  66. return res;
  67.  
  68. }
  69.  
  70. function handleGet() {
  71.  
  72. // Retrieve data here a nd return results in JSON/other format
  73. var OBJECT = $.request.parameters.get("OBJECT");
  74. var STARTDATE = $.request.parameters.get("STARTDATE");
  75. var ENDDATE = $.request.parameters.get("ENDDATE");
  76. var LEVEL = $.request.parameters.get("LEVEL");
  77.  
  78.  
  79. if (OBJECT === null) {
  80. $.response.status = $.net.http.OK;
  81. return {
  82. "myResult" : "500 - Invalid entry"
  83. };
  84. }
  85.  
  86. var result;
  87. var conn = null;
  88. var pstmt = null;
  89.  
  90.  
  91.  
  92. // var sql = "select * from \"_SYS_BIC\".\"USAG.PROD.FactSheets.DataModelingV2.PackagePage.common/CA_USAG_PACKAGE_TREETABLE2\"('PLACEHOLDER' = ('$$IP_USAG_PACKAGE$$','"+OBJECT+"'), 'PLACEHOLDER' = ('$$IP_USAG_START_MONTH$$','"+STARTDATE+"'), 'PLACEHOLDER' = ('$$IP_USAG_END_MONTH$$','"+ENDDATE+"'), 'PLACEHOLDER' = ('$$IP_USAG_HIER_LEVEL$$','"+LEVEL+"'))";
  93. var sql = "select * from \"_SYS_BIC\".\"USAG.PROD.FactSheets.DataModelingV2.PackagePage.common/CA_TEST_GRAPH\"";
  94.  
  95.  
  96. try {
  97. conn = $.db.getConnection();
  98. pstmt = conn.prepareStatement(sql);
  99. var grs = pstmt.executeQuery();
  100.  
  101. result = {
  102. "data" : [],
  103. 'result' : true,
  104. 'message' : 'Search term success',
  105. 'rootNode': -1,
  106. 'length' : -1,
  107. 'display' : -1,
  108. 'sizeDisplay' : -1
  109. };
  110.  
  111. var counter = 0;
  112. var sum = 0 ;
  113.  
  114.  
  115.  
  116. while (grs.next()) {
  117.  
  118. var parentName = grs.getNString(2);
  119. var childName = grs.getNString(1);
  120. var parentChild = parentName + childName;
  121.  
  122. visited2[parentChild] = false;
  123.  
  124. if(globalAdjList.get(parentName) == null || globalAdjList.get(parentName) == undefined){
  125. globalAdjList.set(parentName, []);
  126. globalAdjList.get(parentName).push(childName);
  127. }else{
  128. globalAdjList.get(parentName).push(childName);
  129. }
  130. visited[parentName] = false;
  131. visited[childName] = false;
  132.  
  133. visited2[{parentName, childName}] = false;
  134.  
  135.  
  136.  
  137.  
  138.  
  139. result.data.push({
  140.  
  141. PARENT_NAME : parentName,
  142. CHILD_NAME : childName,
  143.  
  144. });
  145.  
  146. }
  147.  
  148. var rootNode = OBJECT;
  149. var keys = globalAdjList.keys();
  150. for(var t of keys){
  151. visited[t] = false;
  152. }
  153.  
  154. result.rootNode = OBJECT;
  155. // result.length = Array.from( globalAdjList.values() );
  156. rootNode = "1";
  157. result.display = dfs(rootNode);
  158.  
  159.  
  160.  
  161.  
  162. grs.close();
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. } catch (error) {
  170. $.trace.error("Search term error: " + error.toString());
  171. $.trace.error("TEMP__:About to query:" + sql);
  172. result = {
  173. "result" : false,
  174. "message" : "Search term error: " + error.toString()
  175. };
  176. } finally {
  177. if (pstmt !== null) {
  178. pstmt.close();
  179. }
  180. if (conn !== null) {
  181. conn.close();
  182. }
  183. }
  184.  
  185.  
  186. return result;
  187.  
  188. }
  189.  
  190. // Implementation of POST call
  191. function handlePost() {
  192. var bodyStr = $.request.body ? $.request.body.asString() : undefined;
  193. if (bodyStr === undefined) {
  194. $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
  195. return {
  196. "myResult" : "Missing BODY"
  197. };
  198. }
  199. // Extract body insert data to DB and return results in JSON/other format
  200. $.response.status = $.net.http.CREATED;
  201. return {
  202. "myResult" : "POST success"
  203. };
  204. }
  205. // Check Content type headers and parameters
  206. function validateInput() {
  207. var i;
  208. var j;
  209. // Check content-type is application/json
  210. contentType = $.request.contentType;
  211. if (contentType === null
  212. || contentType.startsWith("application/json") === false) {
  213. $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
  214. $.response.setBody("Wrong content type request use application/json");
  215. return false;
  216. }
  217. // Extract parameters and process them
  218. for (i = 0; i < $.request.parameters.length; ++i) {
  219. paramName = $.request.parameters[i].name;
  220. paramValue = $.request.parameters[i].value;
  221. // Add logic
  222. }
  223. // Extract headers and process them
  224. for (j = 0; j < $.request.headers.length; ++j) {
  225. headerName = $.request.headers[j].name;
  226. headerValue = $.request.headers[j].value;
  227. // Add logic
  228. }
  229. return true;
  230. }
  231. // Request process
  232. function processRequest() {
  233. //if (validateInput()) {
  234. try {
  235. switch ($.request.method) {
  236. // Handle your GET calls here
  237. case $.net.http.GET:
  238. $.response.setBody(JSON.stringify(handleGet()));
  239. handleGet();
  240. // return handleGet();
  241. // $.response.setBody(JSON.stringify(bfs("UICORE")));
  242. break;
  243. // Handle your POST calls here
  244. case $.net.http.POST:
  245. $.response.setBody(JSON.stringify(handleGet()));
  246. break;
  247. // Handle your other methods: PUT, DELETE
  248. default:
  249. $.response.status = $.net.http.METHOD_NOT_ALLOWED;
  250. $.response.setBody("Wrong request method");
  251. break;
  252. }
  253. $.response.contentType = "application/json";
  254. } catch (e) {
  255. $.response.setBody("Failed to execute action: " + e.toString());
  256. }
  257. //}
  258. }
  259. // Call request processing
  260. processRequest();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement