123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'bi/commons/ui/core/Class', 'doT', 'text!bi/admin/common/templates/collectParameterValues.xml', 'bi/admin/common/utils/XMLUtils', 'bi/admin/globalparameters/helpers/SoapHelper', 'bi/admin/common/utils/parameters/ParameterValues', 'ba-react-admin/ba-react-admin.min', 'text!bi/admin/common/templates/queryForRoutingServerGroup.xml'], function (_, Class, doT, CollectParameterValuesTemplate, XMLUtilsPlaceholder, SoapHelper, ParameterValues, AdminReact, RoutingServerGroupQueryTemplate) {
- var CollectParameterValues = Class.extend({
- _cachedResponses: {},
- init: function init(options) {
- CollectParameterValues.inherited('init', this, arguments);
- _.extend(this, options);
- },
- get: function get() {
- if (this.parameter.source !== 'report') {
- return this._returnStaticValues();
- } else if (this._cachedResponses[this.parameter.report_id]) {
- return this._returnCachedResponse();
- } else {
- var routingServerGroupQuery = doT.template(RoutingServerGroupQueryTemplate)({
- 'cafContextId': this.glassContext.authInfo.cafContextId,
- 'objectPath': this.parameter.report_path ? SoapHelper.xml_encode(this.parameter.report_path) : 'storeID(\'' + this.parameter.report_id + '\')'
- });
- return this.glassContext.services.fetch.post('v1/reports', {
- 'headers': {
- 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/contentManagerService/201703/'
- },
- 'contentType': 'text/xml; charset=UTF-8',
- 'data': routingServerGroupQuery
- }).then(function (cmResponse) {
- var $routingServerGroupNode = $(cmResponse.data).selectNode('Envelope').selectNode('Body').selectNode('queryResponse').selectNode('result').selectNode('item').selectNode('routingServerGroup').selectNode('value');
- var collectParameterValuesRequest = doT.template(CollectParameterValuesTemplate)({
- 'cafContextId': this.glassContext.authInfo.cafContextId,
- 'objectPath': this.parameter.report_path ? SoapHelper.xml_encode(this.parameter.report_path) : 'storeID(\'' + this.parameter.report_id + '\')',
- 'parameterValues': this.parameterValues ? ParameterValues.toXML(this.parameterValues) : '<parameterValues xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="bus:parameterValue[]"/>',
- 'routingServerGroup': $routingServerGroupNode.text()
- });
- return this.glassContext.services.fetch.post('v1/reports', {
- 'headers': {
- 'SOAPAction': 'http://www.ibm.com/xmlns/prod/cognos/reportService/201703/.high'
- },
- 'contentType': 'text/xml; charset=UTF-8',
- 'data': collectParameterValuesRequest
- }).then(function (response) {
- return SoapHelper.processResponse({
- id: this.parameter.report_id,
- defaultName: ''
- }, response.data);
- }.bind(this));
- }.bind(this)).catch(function (response) {
- return {
- status: 'error',
- report_id: this.parameter.report_id,
- message: response.message,
- code: response.code
- };
- }.bind(this));
- }
- },
- _returnStaticValues: function _returnStaticValues() {
- return new Promise(function (resolve, reject) {
- var values = [];
- _.each(this.parameter.values, function (item) {
- values.push({
- label: item.display,
- value: item.use
- });
- });
- var response = {
- status: 'success',
- type: 'json',
- promptControls: [this.parameter.name],
- name: this.parameter.name,
- json: {
- name: this.parameter.name,
- control: {
- multiSelect: true,
- type: 'checkBoxGroup',
- module: AdminReact.CheckboxGroupControl,
- autoSubmit: false
- },
- values: values
- },
- xml: null
- };
- if (this.parameter.name === '_as_of_date') {
- response.json.control = {
- multiSelect: false,
- type: 'selectDate',
- module: AdminReact.DateTimeControl,
- autoSubmit: false
- };
- }
- resolve(response);
- }.bind(this));
- },
- _returnCachedResponse: function _returnCachedResponse() {
- return new Promise(function (resolve, reject) {
- var xmlDoc = $.parseXML(this._cachedResponses[this.parameter.report_id]);
- resolve(SoapHelper.processResponse(xmlDoc));
- }.bind(this));
- }
- });
- return CollectParameterValues;
- });
|