123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- // 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 = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\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;
- }
- }
- }
|