123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- /********************************************************************************************************************************
- * 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 <items>...</item> 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 = "<items>";
-
- if (forCount==true) {
- diXML+="<type>for_count</type>";
- }
-
- if (items==null) {
- items = getTreeValues(getDataItemsTree());
- }
- //build the filter element
- diXML += buildFilter();
-
- if (forCount != undefined && forCount==true) {
- diXML += buildFixedItemXML("_count","<dataItem name=\"_count\"><expression>count ([_const] for report)</expression></dataItem>");
- diXML += buildFixedItemXML("_const","<dataItem name=\"_const\" rollupAggregate=\"total\" aggregate=\"calculated\"><expression>1</expression></dataItem>");
- }
-
- //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 += "<group ref=\"" + group.ref + "\"/>";
- }
- }
-
- // 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 += "<sort ref=\"" + sorts.ref + "\" order=\""+sorts.order+"\"/>";
- }
- }
-
- diXML += "</items>";
-
- 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 += "<item name=\"" + name + "\">";
- v_sDiXML += dataItemStr;
- v_sDiXML += "</item>";
-
- 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 += "<item name=\"" + encode(getObjPropName(item)) + "\"";
- v_sDiXML += " displayType=\""+item.displayType+"\">";
- v_sDiXML += buildDataItemXML(item,sort,noAggregate)
- v_sDiXML += createDrillThroughs(item.name, reportTasks);
- v_sDiXML += "</item>";
-
- 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("<filter>"+ filters_string +"</filter>");
- 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 += "<dataItem name=\"" + encode(getObjPropName(node)) + "\" label=\"" + encode(getObjPropName(node)) + "\"";
- //aggregate
- if (noAggregate!=undefined && (noAggregate==true || noAggregate=="true")) {
- v_sDiXML += " aggregate=\"none\" rollupAggregate=\"none\"";
- }
- else {
- var v_sAgg = "none";
- if (node.regularAggregate != undefined) {
- v_sAgg = encode(getObjProp(node, "regularAggregate"));
- }
- v_sDiXML += " aggregate=\"" + v_sAgg + "\"";
- }
-
- //sort
- if (sort != undefined && sort.length > 0) {
- v_sDiXML += " sort=\"" + sort + "\"";
- }
-
- v_sDiXML += ">";
- v_sDiXML += "<expression>" + encode(getObjProp(node,"ref")) + "</expression>";
- v_sDiXML += "</dataItem>";
-
- 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 += "<drill id=\""+ reportTaskAssignment.taskId +"\"";
- drillThroughs += " path=\""+encode(reportTaskAssignment.reportPath)+"\"";
- drillThroughs += " name=\""+encode(reportTaskAssignment.reportName)+"\">";
-
- if (reportTaskAssignment.parameterAssignments.length > 0) {
- drillThroughs +="<links>";
- }
-
- for(var j = 0; j < reportTaskAssignment.parameterAssignments.length; j++){
- var pa = reportTaskAssignment.parameterAssignments[j];
-
- if(!pa || pa.topic != topicName){
- continue;
- }
- drillThroughs += "<link name=\""+encode(pa.parameterName)+"\" topic=\""+encode(pa.topic)+"\"/>";
- }
- if (reportTaskAssignment.parameterAssignments.length > 0) {
- drillThroughs +="</links>";
- }
-
- drillThroughs += "</drill>";
- }
-
- return drillThroughs;
- }
|