Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //var paramName;
- //var paramValue;
- //var headerName;
- //var headerValue;
- //var contentType;
- ////var globalAdjList = new Map();
- //var mapPackageMos = new Map();
- //var globalTypeMap = new Map();
- //var globalCosts = new Map();
- //var globalVisited = [];
- //var gbv = [];
- //var gbv2 = [];
- //var gbvCondition = [];
- //var globalVisited2 = [];
- //var globalVisited3 = [];
- //var globalFlag = -1;
- //var globalBfsTravers;
- // Implementation of GET call
- var globalAdjList = new Map();
- var parentChild = new Map();
- var visited = [];
- var visited2 = [];
- var level = [];
- function dfs(rootNode){
- var res = [];
- var stack = [];
- var display = "";
- stack.push(rootNode);
- visited[rootNode] = true;
- level[rootNode] = 0;
- while(stack.length > 0){
- var head = stack.pop();
- var currentLevel = level[head];
- display += head;
- display += "->";
- //add in the final result
- var row = [];
- for(var i = 0 ; i < level[head]; i++){
- row.push("*");
- }
- row.push(head);
- res.push(row);
- if(globalAdjList.get(head) == null || globalAdjList.get(head) == undefined)
- continue;
- for(var child of globalAdjList.get(head)){
- // if(visited[child] == false){
- // level[child] = currentLevel + 1;
- // visited[child] = true;
- // stack.push(child);
- // }
- var parentChild = head + child;
- if(visited2[parentChild] == false){
- visited2[parentChild] = true;
- level[child] = currentLevel + 1;
- stack.push(child);
- }
- }
- }
- return res;
- }
- function handleGet() {
- // Retrieve data here a nd return results in JSON/other format
- var OBJECT = $.request.parameters.get("OBJECT");
- var STARTDATE = $.request.parameters.get("STARTDATE");
- var ENDDATE = $.request.parameters.get("ENDDATE");
- var LEVEL = $.request.parameters.get("LEVEL");
- if (OBJECT === null) {
- $.response.status = $.net.http.OK;
- return {
- "myResult" : "500 - Invalid entry"
- };
- }
- var result;
- var conn = null;
- var pstmt = null;
- // 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+"'))";
- var sql = "select * from \"_SYS_BIC\".\"USAG.PROD.FactSheets.DataModelingV2.PackagePage.common/CA_TEST_GRAPH\"";
- try {
- conn = $.db.getConnection();
- pstmt = conn.prepareStatement(sql);
- var grs = pstmt.executeQuery();
- result = {
- "data" : [],
- 'result' : true,
- 'message' : 'Search term success',
- 'rootNode': -1,
- 'length' : -1,
- 'display' : -1,
- 'sizeDisplay' : -1
- };
- var counter = 0;
- var sum = 0 ;
- while (grs.next()) {
- var parentName = grs.getNString(2);
- var childName = grs.getNString(1);
- var parentChild = parentName + childName;
- visited2[parentChild] = false;
- if(globalAdjList.get(parentName) == null || globalAdjList.get(parentName) == undefined){
- globalAdjList.set(parentName, []);
- globalAdjList.get(parentName).push(childName);
- }else{
- globalAdjList.get(parentName).push(childName);
- }
- visited[parentName] = false;
- visited[childName] = false;
- visited2[{parentName, childName}] = false;
- result.data.push({
- PARENT_NAME : parentName,
- CHILD_NAME : childName,
- });
- }
- var rootNode = OBJECT;
- var keys = globalAdjList.keys();
- for(var t of keys){
- visited[t] = false;
- }
- result.rootNode = OBJECT;
- // result.length = Array.from( globalAdjList.values() );
- rootNode = "1";
- result.display = dfs(rootNode);
- grs.close();
- } catch (error) {
- $.trace.error("Search term error: " + error.toString());
- $.trace.error("TEMP__:About to query:" + sql);
- result = {
- "result" : false,
- "message" : "Search term error: " + error.toString()
- };
- } finally {
- if (pstmt !== null) {
- pstmt.close();
- }
- if (conn !== null) {
- conn.close();
- }
- }
- return result;
- }
- // Implementation of POST call
- function handlePost() {
- var bodyStr = $.request.body ? $.request.body.asString() : undefined;
- if (bodyStr === undefined) {
- $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
- return {
- "myResult" : "Missing BODY"
- };
- }
- // Extract body insert data to DB and return results in JSON/other format
- $.response.status = $.net.http.CREATED;
- return {
- "myResult" : "POST success"
- };
- }
- // Check Content type headers and parameters
- function validateInput() {
- var i;
- var j;
- // Check content-type is application/json
- contentType = $.request.contentType;
- if (contentType === null
- || contentType.startsWith("application/json") === false) {
- $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
- $.response.setBody("Wrong content type request use application/json");
- return false;
- }
- // Extract parameters and process them
- for (i = 0; i < $.request.parameters.length; ++i) {
- paramName = $.request.parameters[i].name;
- paramValue = $.request.parameters[i].value;
- // Add logic
- }
- // Extract headers and process them
- for (j = 0; j < $.request.headers.length; ++j) {
- headerName = $.request.headers[j].name;
- headerValue = $.request.headers[j].value;
- // Add logic
- }
- return true;
- }
- // Request process
- function processRequest() {
- //if (validateInput()) {
- try {
- switch ($.request.method) {
- // Handle your GET calls here
- case $.net.http.GET:
- $.response.setBody(JSON.stringify(handleGet()));
- handleGet();
- // return handleGet();
- // $.response.setBody(JSON.stringify(bfs("UICORE")));
- break;
- // Handle your POST calls here
- case $.net.http.POST:
- $.response.setBody(JSON.stringify(handleGet()));
- break;
- // Handle your other methods: PUT, DELETE
- default:
- $.response.status = $.net.http.METHOD_NOT_ALLOWED;
- $.response.setBody("Wrong request method");
- break;
- }
- $.response.contentType = "application/json";
- } catch (e) {
- $.response.setBody("Failed to execute action: " + e.toString());
- }
- //}
- }
- // Call request processing
- processRequest();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement