// Licensed Materials - Property of IBM // // IBM Cognos Products: pps // // (C) Copyright IBM Corp. 2005, 2017 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. //This JavascriptFile wraps the admin tool command syntax used for administrative requests var ADM_GET = 100; var ADM_SET = 101; var ADM_RESET_BELOW = 114; var ADM_GETOBJECTCHILDREN = 126; var ADM_COM_errorMessage = "Communication failure"; var ADM_COM_ERROR_NODE = "error"; var ADM_RETURN_TYPE_ATTTREE = 0; function AdminCommandRec(command,returnFunc,returnType) { this.command = command; this.returnFunc = returnFunc; this.returnType = returnType; } //This class provides a communication API to the ppes server function AdminCommands() { var xmlCom = new xmlCommunicator(this); var attStreamer = new AttributeTreeStreamer(); var resultXML = null; var commandQueue= new Array(); var commandInProgress = false; var commandQueueLength = 0; var commandInterval = null; //Public Methods this.GetObjProperties = function(objName, returnFunc) { var commandAttTree = new AttributeTree(); commandAttTree.addInt("type",ADM_GET); commandAttTree.addString("object",objName); if (returnFunc) //Non blocking sendAsyncCommand(commandAttTree, returnFunc, ADM_RETURN_TYPE_ATTTREE); else { //Blocking return sendRequest(commandAttTree, true); } } this.GetObjChildren = function(objName, sortType, returnFunc, isSearch) { var commandAttTree = new AttributeTree(); commandAttTree.addInt("type",ADM_GETOBJECTCHILDREN); commandAttTree.addInt("sortType", sortType); commandAttTree.addString("object",objName); if (isSearch) commandAttTree.addString("isSearch", "true"); if (returnFunc) //Non blocking sendAsyncCommand(commandAttTree, returnFunc, ADM_RETURN_TYPE_ATTTREE); else { //Blocking return sendRequest(commandAttTree, true); } } this.SetObjProperties = function(objName, objectClass, attTree, returnFunc) { var commandAttTree = new AttributeTree(); commandAttTree.addInt("type",ADM_SET); commandAttTree.addString("object",objName); commandAttTree.addString("objectClass",objectClass); var props = attTree.getRoot(); props.name = "value"; commandAttTree.insertNode("value",props); if (returnFunc) //Non blocking sendAsyncCommand(commandAttTree, returnFunc, ADM_RETURN_TYPE_ATTTREE); else { //Blocking return sendRequest(commandAttTree, true); } } this.resetDescendants = function(objName, returnFunc) { var commandAttTree = new AttributeTree(); commandAttTree.addInt("type",ADM_RESET_BELOW); commandAttTree.addString("object",objName); if (returnFunc) //Non blocking sendAsyncCommand(commandAttTree, returnFunc, ADM_RETURN_TYPE_ATTTREE); else { //Blocking return sendRequest(commandAttTree, true); } } //Private Methods function sendAsyncCommand(command, returnFunc, returnType) { //Put this command at the start of the command Queue; var commandInfo = new AdminCommandRec(command, returnFunc, returnType); for (var i = commandQueueLength - 1; i >= 0; i--) { commandQueue[i + 1] = commandQueue[i]; } commandQueue[0] = commandInfo; commandQueueLength++; //If no command is in progress, send one if (!commandInProgress) sendNextCommand(); } function requestCompleted() { //The request completed, so we handle the response var result; var success = getXMLResponse(); if (commandQueue[commandQueueLength - 1].returnType == ADM_RETURN_TYPE_ATTTREE) { if (success) { result = attStreamer.getAttributeTreeFromXML(resultXML); } else { if (resultXML) result = generateErrorAttTree(resultXML); else result = generateErrorAttTree(ADM_COM_errorMessage); } } //Debug only; var debugDump = document.getElementById("attResponseDump"); if (debugDump) { debugDump.value += "\n**************************\n"; if (success) debugDump.value += result; else debugDump.value += "Unable to produce an attribute tree"; } commandQueue[commandQueueLength - 1].returnFunc(result); commandQueueLength--; sendNextCommand(); } this.requestCompleted = requestCompleted; function sendNextCommand() { if (commandQueueLength > 0) { if (send(commandQueue[commandQueueLength - 1].command,false)) commandInProgress = true; else { //Bad command, decriment the array commandQueueLength--; commandInProgress = false; sendNextCommand(); } } else { commandInProgress = false; } return commandInProgress; } function generateErrorAttTree(errorMessage) { var attTree = new AttributeTree(); attTree.addString(ADM_COM_ERROR_NODE,errorMessage); return attTree; } function getXMLResponse() { resultXML = null; if (xmlCom.requestSuceeded()) { //Debug only var debugDump = document.getElementById("xmlResponseDump"); if (debugDump) { debugDump.value += "\n**************************\n"; debugDump.value += xmlCom.GetTextResponse(); } if (!xmlCom.GetXMLResponse()) { resultXML = xmlCom.GetTextResponse(); return false; } else { resultXML = xmlCom.GetXMLResponse(); return true; } } else { return false; } } function getCamPassportCookie() { var allCookies = document.cookie; var start = allCookies.indexOf("cam_passport="); if (start != -1) { var end = allCookies.indexOf(";", start); if (end == -1) end = allCookies.length; return unescape(allCookies.substring(start + "cam_passport=".length, end)); } return ""; } function send(attTree, blocking) { if (document.getElementById("attRequestDump")) { document.getElementById("attRequestDump").value += "\n**************************\n"; document.getElementById("attRequestDump").value += attTree; } resultXML = null; var xmlCommand = attStreamer.getXMLFromAttributeTree(attTree); var xmlText = ""; if (xmlCommand.xml) { xmlText = xmlCommand.xml; } else { xmlText = (new XMLSerializer()).serializeToString(xmlCommand); } var cmdString = "\n" + xmlText; if (document.getElementById("xmlRequestDump")) { document.getElementById("xmlRequestDump").value += "\n**************************\n"; document.getElementById("xmlRequestDump").value += cmdString; } var data = new dataCollection(); data.addItem("b_action","powerPlayService"); data.addItem("ATXR",cmdString); data.addItem("ADMPP", getCamPassportCookie()); // protect from CSRF var status = xmlCom.sendRequest(data.getDataArray(), blocking); if (blocking) { return getXMLResponse(); } else { return (status == xmlCom.STATUS_ASYNC_SENT); } } function sendRequest(attTree, blocking) { var result; var success = send(attTree, blocking); if (blocking) { if (success) { result = attStreamer.getAttributeTreeFromXML(resultXML); } else { if (resultXML) result = generateErrorAttTree(resultXML); else result = generateErrorAttTree(ADM_COM_errorMessage); } //Debug only; var debugDump = document.getElementById("attResponseDump"); if (debugDump) { debugDump.value += "\n**************************\n"; if (success) debugDump.value += result; else debugDump.value += "Unable to produce an attribute tree"; } debugDump = document.getElementById("xmlResponseDump"); if (debugDump) { debugDump.value += "\n**************************\n"; debugDump.value += xmlCom.GetTextResponse(); } return result; } else { return success; } } }