'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * */ define(['./VisQuerySelectionBuilder'], function (VisQuerySelectionBuilder) { // noinspection JSAnnotator /** * INTENT: VisQueryDataItemBuilder is used to construct a dataItem in the form needed by the query. * building the dataItem involves a number of 'on the fly' steps such as: * inserting the appropriate initial selection based on the current drill state, * deciding if a filter should be a dataItem selection * ensuring that selections are performed in a predictable order (initial selection (root members or drill members), keep/remove, topN, sort) */ var QueryDataItemBuilder = function () { function QueryDataItemBuilder(_ref) { var internalVisualization = _ref.internalVisualization, layerToQuerySlotsMap = _ref.layerToQuerySlotsMap, applyServerSort = _ref.applyServerSort; _classCallCheck(this, QueryDataItemBuilder); this.internalVisualization = internalVisualization; this.visQuerySelectionBuilder = new VisQuerySelectionBuilder({ internalVisualization: internalVisualization, layerToQuerySlotsMap: layerToQuerySlotsMap, applyServerSort: applyServerSort }); } QueryDataItemBuilder.prototype._isExistingDrillSelection = function _isExistingDrillSelection(dataItem) { var drillSelection = dataItem.getDrillDownValue() || dataItem.getDrillUpValue(); return !!drillSelection; }; /* * @private * @return {Array} An array of Data Item objects assigned to a single slot. **/ QueryDataItemBuilder.prototype.build = function build(dataItem, slot, outputEdgeFilterExceptions) { //todo: before here is oldDataItemAPI.toQueryJSON() var oDataItemJSON = { id: dataItem.getId(), itemId: dataItem.getColumnId() }; if (!dataItem.getBinning() && this._isExistingDrillSelection(dataItem) && dataItem.getMetadataColumn().isNamedSet()) { oDataItemJSON.itemId = dataItem.getMetadataColumn().getReferencedHierarchyId(); } if (dataItem.getType() === 'fact') { //MappedDataItemAPI#getType // If the final slot type is ordinal, it means we are querying the data item // in a ordinal form, which in this case we want to respect the aggregation type // except 'none' oDataItemJSON.aggregate = dataItem.getAggregation(); } var finalSelection = this.visQuerySelectionBuilder.build(dataItem, slot, outputEdgeFilterExceptions); if (finalSelection.length) { oDataItemJSON.selection = finalSelection; } var binningSpec = this._buildAutoBinningSpec(dataItem); //binned dataItem type will be attribute, so if it has aggregate we need to remove it. // binningDefinition is part of toQueryJSON (need for copy/paste), but dss query has different format if (binningSpec) { //remove old selection, since it may have top/bottom if (!finalSelection.length) { delete oDataItemJSON.selection; } delete oDataItemJSON.aggregate; oDataItemJSON.binning = binningSpec; } return oDataItemJSON; }; QueryDataItemBuilder.prototype._buildAutoBinningSpec = function _buildAutoBinningSpec(dataItem) { var MAX_DECIMAL_PLACES_DEFAULT = 2; var binning = dataItem.getBinning(); if (binning) { var binningQuerySpec = { auto: { numberOfBins: binning.bins, maxDecPlaces: MAX_DECIMAL_PLACES_DEFAULT } }; var format = dataItem.getFormat(); if (format && Number.isInteger(format.maximumFractionDigits)) { binningQuerySpec.auto.maxDecPlaces = format.maximumFractionDigits; } return binningQuerySpec; } return null; }; return QueryDataItemBuilder; }(); return QueryDataItemBuilder; }); //# sourceMappingURL=QueryDataItemBuilder.js.map