/******************************************************************************************************************************** * Licensed Materials - Property of IBM * * * * IBM Cognos Products: AGS * * * * (C) Copyright IBM Corp. 2005, 2015 * * * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * *********************************************************************************************************************************/ /* * Build a report specification by calling buildReportSpec.xts. This uses the XHTTP dispatcher * which utilises a callback to set the report spec into a config parameter. It should * be called using the command stack manager * Optional config parameters can be set that change the way specification is built. * Details are below(default settings shown in brackets). * * Inputs * inlineSpec_items - an array of data items (all current data items) * inlineSpec_groups - an array of group items (no grouping). Group items contain a 'ref' property * inlineSpec_sorts - an array of sort items (no sorting). Sort items contain 'ref' and 'order' properties * inlineSpec_forCount - true or false (false) * The following options are used when the hidden menu items to import agent spec from clipboard: * inlineSpec_promptPages - an element containing custom prompt pages. * inlineSpec_extraQueries - an array of extra query nodes. * * Outputs * inlineSpec - the signed report specification */ function getReportSpec() { var cf = getConfigFrame(); var groups = cf.cfgGet("inlineSpec_groups"); var sorts = cf.cfgGet("inlineSpec_sorts"); var promptPages = cf.cfgGet("inlineSpec_promptPages"); if (promptPages == undefined) { promptPages = null; } var extraQueries = cf.cfgGet("inlineSpec_extraQueries"); if (extraQueries == undefined) { extraQueries = null; } //count var forCount = cf.cfgGet("inlineSpec_forCount"); if (forCount==undefined) { forCount=false; } //items var items = cf.cfgGet("inlineSpec_items"); if (items == undefined) { items = null; } //start the request startReportSpecRequest(items,groups,sorts,forCount,promptPages,extraQueries); } /* * Build an XML structure ... containing the metadata needed * to build a report specification. The specification is built on the server by * the morphlet 'ags/buildReportSpec.xts'. The XHTTP dispatcher is used the run the * morphlet asynchronously. If no parameters are passed to this function, the current data items * will be used with no 'sort' and no 'group by' sections. * * items - custom list of items taken from the agent items tree. If null then all query items are used * groups(optional) - the group settings. If missing no sort elements will be created * sorts(optional) - the sort settings. If missing no group elements will be created * forCount(optional) - true when building the report spec for the count command. If missing default is false */ function startReportSpecRequest(items,groups,sorts,forCount,promptPages,extraQueries) { signedReportSpec=""; var msgFrame = getMessageIFrame(); var frameDoc = getFrameDocument(msgFrame); var diXML = ""; if (forCount==true) { diXML+="for_count"; } if (items==null) { items = getTreeValues(getDataItemsTree()); } //build the filter element diXML += buildFilter(); if (forCount != undefined && forCount==true) { diXML += buildFixedItemXML("_count","count ([_const] for report)"); diXML += buildFixedItemXML("_const","1"); } //these are jscript objects holding the details of report and agent tasks and their parameter assignments var reportTasks = getAgentItemsListener().getReportTaskAssignments(); // loop over all the items in the agent items tree for (var i = 0; items!= null && i < items.length; ++i) { diXML += buildItemXML(items[i],"", false,reportTasks); } // add the group by's if they have been defined if (groups != undefined && groups != null && groups.length > 0) { for (var i = 0; i < groups.length; ++i) { // get the group reference var group = groups[i]; diXML += ""; } } // add the sort by's if they have been defined if (sorts != undefined && sorts != null && sorts.length > 0) { for (var i = 0; i < sorts.length; ++i) { // get the sorts reference var sorts = sorts[i]; diXML += ""; } } diXML += ""; var holder = new Object(); holder['queryItems'] = diXML; // serialize the promptPages Element to a string; remove all the attributes to avoid report server death. if (promptPages != null) { var promptpage = promptPages.cloneNode(true); if (promptpage.attributes.length > 0){ promptpage.removeAttribute('xmlns'); } if (window.clipboardData) { holder['promptPages'] = promptpage.xml; } else { holder['promptPages'] = (new XMLSerializer( )).serializeToString(promptpage); } //alert(holder['promptPages']); } if (extraQueries != null && extraQueries.length > 0) { var extraQueriesString = ""; for (var i = 0; i < extraQueries.length; i++) { if (window.clipboardData) { //alert(extraQueries[i].xml); extraQueriesString = extraQueriesString + extraQueries[i].xml; } else { extraQueriesString = extraQueriesString + (new XMLSerializer( )).serializeToString(extraQueries[i]); } } holder['extraQueries'] = extraQueriesString; } holder['el'] = getExpressionLocale(); holder['model'] = cf.cfgGet("cmLastModel"); holder['m'] = "/ags/buildReportSpec.xts"; // force SOAPFault for passport expire instead of getting a logon page holder['forceSOAPFault'] = "false"; var dispatcher = new parent.cf.XHTTPDispatcher(processReportSpecResponse, holder); applicationActionManager.httpStart(); try{ dispatcher.dispatch(); }catch(ex){ applicationActionManager.httpStop(); } } function processReportSpecResponse(responseArray) { var signedReportSpec=""; applicationActionManager.httpStop(); // get the values returned var responseXML = responseArray[0]; var responseText = responseArray[1]; //Although it is unlikely but there is a chance this may fault when calling //the xts. var parsedResponse = parseResponse(responseXML,responseText); // decide what we're going to do if (parsedResponse.isLogonFault()) { doPassportExpire(responseXML,resendGetReportSpec,parsedResponse); applicationActionManager.httpStop(); return; } else if (parsedResponse.isSoapFault()) { // we have a fault which is a genuine fault fault doSOAPFault(responseXML,null,parsedResponse); } else { //get the reportSpec text signedReportSpec = parsedResponse.getTextValueForXPath("./*[local-name()='value']"); } if(document.documentMode > 10){ //workaround in IE11 as signedReportSpec is null //alert('in IE11 signedReportSpec ' +signedReportSpec); if(signedReportSpec==null){ signedReportSpec = responseText ; } //alert('now signedReportSpec ' +signedReportSpec); } cf.cfgSet("inlineSpec",signedReportSpec); clearReportSpecInputs(); setTimeout("getCommandStackManager().processCommandStack();", 100); } function resendGetReportSpec() { getCommandStackManager().getCommandStack().push("getReportSpec()"); } function buildFixedItemXML(name,dataItemStr) { var v_sDiXML=""; v_sDiXML += ""; v_sDiXML += dataItemStr; v_sDiXML += ""; return v_sDiXML; } /* * item - a tree node * sort - the sort order 0 or 1, optional * noAggregate - true to set no aggregates, optional */ function buildItemXML(item,sort,noAggregate,reportTasks) { var v_sDiXML=""; //create the item v_sDiXML += ""; v_sDiXML += buildDataItemXML(item,sort,noAggregate) v_sDiXML += createDrillThroughs(item.name, reportTasks); v_sDiXML += ""; return v_sDiXML; } function buildFilter() { //The AgentTask-condition holds an XML encoded blob of the summary and details //filter. We have a hidden input in the defineCondtion.xts that is always updated //when the summary and detail filter changes. var filters = ""; var msgFrame = getMessageIFrame(); var msgDoc = getFrameDocument(msgFrame); // get the task condition element var conditionElement = msgDoc.getElementById("AgentTask-condition"); var filters_string = cf.cfgGet("AgentTask-condition"); if(conditionElement != null && conditionElement.value != ""){ filters_string = conditionElement.value; } // if we have an element - get it's value if (filters_string != null && filters_string != "") { // condition element MIGHT be 2 elements if we have both summary and detail filters, so create a dummy root node. var filters_xml = new XMLParser(""+ filters_string +""); if (filters_xml != null && filters_xml.childNodes != null && filters_xml.childNodes.length > 0) { //shouldnt have any attributes.. they are probably xts ones which cause report server validation death filters_xml.attributes = new Array(); // handle the filters and combine as one string for (var i = 0; i < filters_xml.childNodes.length; i++) { filters_xml.childNodes[i].attributes = new Array(); filters = filters + filters_xml.childNodes[i].toString(); } } } // return the filters return filters; } function clearReportSpecInputs() { var cf = getConfigFrame(); cf.cfgSet("inlineSpec_items",undefined); cf.cfgSet("inlineSpec_groups",undefined); cf.cfgSet("inlineSpec_sorts",undefined); cf.cfgSet("inlineSpec_forCount",undefined); // do not clear the promptPages here //cf.cfgSet("inlineSpec_promptPages",undefined); //cf.cfgSet("inlineSpec_extraQueries",undefined); } function buildDataItemXML(node,sort,noAggregate) { var v_sDiXML=""; //create the referenced data item fragment v_sDiXML += " 0) { v_sDiXML += " sort=\"" + sort + "\""; } v_sDiXML += ">"; v_sDiXML += "" + encode(getObjProp(node,"ref")) + ""; v_sDiXML += ""; return v_sDiXML; } /* * write out a drill through for each promptable report and agent task * the drills go in the list column bodies in the layout section I have loosely associated each drill though with the columns for the topics they contain, if multiple tasks contain the same topic they will all be here but if there are multiple topics in the same task, then the first topic to come up will contain the drill */ function createDrillThroughs(topicName, reportTaskAssignments){ var drillThroughs = ""; var foundDrill = false; //only one drill through per topic... they all come out the same anyway //i.e. drill values are not specific to the target, but to the source for(i = 0; reportTaskAssignments && i < reportTaskAssignments.length; i++){ var reportTaskAssignment = reportTaskAssignments[i]; if(!reportTaskAssignment || !reportTaskAssignment.parameterAssignments || reportTaskAssignment.parameterAssignments.length < 1 || !reportTaskAssignment.reportPath || !reportTaskAssignment.containsTopic(topicName) || foundDrill){ continue; } foundDrill = true; drillThroughs += ""; if (reportTaskAssignment.parameterAssignments.length > 0) { drillThroughs +=""; } for(var j = 0; j < reportTaskAssignment.parameterAssignments.length; j++){ var pa = reportTaskAssignment.parameterAssignments[j]; if(!pa || pa.topic != topicName){ continue; } drillThroughs += ""; } if (reportTaskAssignment.parameterAssignments.length > 0) { drillThroughs +=""; } drillThroughs += ""; } return drillThroughs; }