'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: BI Dashboard *| (C) Copyright IBM Corp. 2019, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['./QueryPostProcessor', './PostProcessMultiEdgeShowNulls', './QueryResultDataPoints.v2'], function (QueryPostprocessor, PostProcessMultiEdgeShowNulls, QueryResultDataPointsV2) { 'use strict'; /** * This post processor has two purposes: * 1) To make multi-edge, multi-measure data more compatible with row-based output * by collecting measures into a single data point. [ pt: [0, 1, 0, {v:msr1}, {v:msr2}, ... {v:msrN}]] * 2) To fill gaps in data where different measures have different numbers of missing values * By default, v2 responses simply skip cells that have no value. * Imagine Canada 17 and China 18 have no value for Cost, USA has value 22 * Canada has no value of UnitCost for product trees (7) but both US and Canada have a value for Quantity * V2 RESPONSE: EG: * [ pt: [ 16, 7, 0, { v:15 }]], Brazil cost = 15 * GAP....no cost for Canada, or China. * [ pt: [ 19, 7, 0, { v:21 }]], Colombia cost = 21 * : etc. * [ pt: [ 22, 7, 0, { v:122 } ]], USA cost = 122 * : * [ pt: [ 17, 7, 1, { v:1000 }]], Canada Quantity = 1000 * : * [ pt: [ 22, 7, 1, { v:2000 }]] USA Quantity = 2000 * * AFTER POST-PROCESSING: In the end, these rows appear like this. * [ pt: [ 16, 7, 0, { v:15}, { v:500 } ]], * [ pt: [ 17, 7, 0, { v:null }, { v:1000 } ]], //Canada Cost null, Quantity 1000 * [ pt: [ 18, 7, 0, { v:null }, { v:3200 }]], //China Cost null, Quantity 3200 * : * [ pt: [ 22, 7, 0, { v:122 }, { v:2000 }]] //USA Cost: 122, Quantity 2000 **/ return function (_QueryPostprocessor) { _inherits(PostProcessMultiEdgeMeasures, _QueryPostprocessor); /** * @Constructor * @param {Object} options */ function PostProcessMultiEdgeMeasures(_ref) { var queryResultData = _ref.queryResultData, queryDefinition = _ref.queryDefinition, suppressionEnabled = _ref.suppressionEnabled; _classCallCheck(this, PostProcessMultiEdgeMeasures); var _this = _possibleConstructorReturn(this, _QueryPostprocessor.call(this, { queryResultData: queryResultData })); _this.queryDefinition = queryDefinition; _this.data = _this._queryResultData.data; _this.dataItems = _this._queryResultData.dataItems; _this.suppressionEnabled = suppressionEnabled; return _this; } /** * Apply the users overrides * @return {QueryResultData} */ PostProcessMultiEdgeMeasures.prototype._processData = function _processData() { if (this._queryResultData.edges && this._queryResultData.edges.length > 1 && this._queryResultData.data && this._queryResultData.data.length > 0) { //This post processor is only for multi-edge. //in v2, regardless suppression is on or off, we will need to populate the null values; var dataPoints = this._buildQueryResultDataPoints(); if (dataPoints) { var showNullsProcessor = new PostProcessMultiEdgeShowNulls({ queryResultDataPoints: dataPoints, queryResultData: this._queryResultData }); this._queryResultData = showNullsProcessor._processData(); } } //For V1 or single edge V2, this postProcessor is a no-op. return this._queryResultData; }; //If there is more than 1 measure, process the measure edge, otherwise postprocessor is no-op. PostProcessMultiEdgeMeasures.prototype._buildQueryResultDataPoints = function _buildQueryResultDataPoints() { var measureEdgeIndex = this.queryDefinition && this.queryDefinition.getDataItemSetList().length && this.queryDefinition.getDataItemSetList().findIndex(function (dataItemSet) { return dataItemSet.isMeasureItemSet(); }); if (measureEdgeIndex !== -1) { //Both measures and calculations should be included in the measure count. var measureCount = 0; this.queryDefinition.getDataItemSetList().forEach(function (dataItemSet) { if (dataItemSet.isMeasureItemSet()) { measureCount += dataItemSet.getDataItemList().length + dataItemSet.getCalculationList().length; } }); return this._loadQueryResultDataPoints(measureCount, measureEdgeIndex); } return null; //No multiEdge data could be built (we had no measures) }; PostProcessMultiEdgeMeasures.prototype._loadQueryResultDataPoints = function _loadQueryResultDataPoints(measureCount, measureEdgeIndex) { var edgeCount = this._queryResultData.edges && this._queryResultData.edges.length; var queryResultDataPoints = new QueryResultDataPointsV2(edgeCount, measureCount, measureEdgeIndex, this.suppressionEnabled); queryResultDataPoints.loadPoints(this.data); return queryResultDataPoints; }; return PostProcessMultiEdgeMeasures; }(QueryPostprocessor); }); //# sourceMappingURL=PostProcessMultiEdgeMeasures.js.map