123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- '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. 2019, 2021
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../apiHelpers/SlotAPIHelper', '../../../lib/@waca/dashboard-common/dist/utils/ContentUtil', 'underscore'], function (SlotAPIHelper, ContentUtil, _) {
- return function () {
- function DataQueryUtils() {
- _classCallCheck(this, DataQueryUtils);
- }
- /**
- * @public
- * Convert exclude empty values filters to include all filters for non OLAP data sources since there might be joins defined in model,
- * and remove such filters for OLAP sources since OLAP doesn't have the concept of joins so these filters won't affect the query at all.
- * @param {filterSpec[]} filterSpecList
- * @example
- * Convert exclude all filter from
- * {
- * 'id': 'dataSetDemo_csv.Product_line',
- * 'columnId': 'dataSetDemo_csv.Product_line',
- * 'values': [],
- * 'excludedValues': [],
- * 'operator': 'notin',
- * 'type': null,
- * 'binsLabel': 'Product line'
- * }
- * to
- * {
- * "operator": "in",
- * "itemId": "dataSetDemo_csv.Product_line",
- * "values": ["dataSetDemo_csv.Product_line"]
- * }
- */
- DataQueryUtils.convertExcludeEmptyValuesFilters = function convertExcludeEmptyValuesFilters(filterSpecList, dataSource) {
- var remainingFilters = [];
- var excludeEmptyValuesFilters = _.filter(filterSpecList, function (filterSpec) {
- var isExcludeEmptyValues = filterSpec.operator === 'notin' && (!filterSpec.values || !filterSpec.values.length) && !filterSpec.conditions;
- if (!isExcludeEmptyValues) {
- remainingFilters.push(filterSpec);
- }
- return isExcludeEmptyValues;
- });
- if (excludeEmptyValuesFilters) {
- excludeEmptyValuesFilters.forEach(function (excludeEmptyValuesFilter) {
- var column = dataSource.getMetadataColumn(excludeEmptyValuesFilter.columnId);
- if (!column.isOlapColumn()) {
- var valueDataItemSpec = {
- id: excludeEmptyValuesFilter.id || excludeEmptyValuesFilter.columnId,
- itemId: excludeEmptyValuesFilter.columnId
- };
- var filterSpec = {
- operator: 'in',
- columnId: valueDataItemSpec.itemId
- };
- filterSpec.values = [{ u: valueDataItemSpec.itemId, d: valueDataItemSpec.itemId }];
- remainingFilters.push(filterSpec);
- }
- });
- }
- return remainingFilters;
- };
- DataQueryUtils.findFirstKeyOfMap = function findFirstKeyOfMap(mapObj) {
- /** the code here is to support IE. */
- var allKeys = [];
- mapObj.forEach(function (val, key) {
- allKeys.push(key);
- });
- return allKeys[0];
- };
- /**
- * @public
- * NonProjected range filters cannot be applied to any layer whose categories are not the same as the first mapped layer
- * (because the aggregate of different categories is different.)
- */
- DataQueryUtils.shouldExcludeNonProjectedRangeFilters = function shouldExcludeNonProjectedRangeFilters(layerToQuerySlotsMap, layerId) {
- var excludeNonProjectedRangeFilters = layerToQuerySlotsMap.size; // Should have at least one mapped layer.
- if (!excludeNonProjectedRangeFilters) {
- return false;
- }
- var firstKey = DataQueryUtils.findFirstKeyOfMap(layerToQuerySlotsMap);
- var categoryItemsForFirstMappedLayer = DataQueryUtils._getCategoryItemsForLayer(layerToQuerySlotsMap.get(firstKey)) || [];
- var categoryItemsForThisLayer = DataQueryUtils._getCategoryItemsForLayer(layerToQuerySlotsMap.get(layerId)) || [];
- return DataQueryUtils._categoriesAreDifferent(categoryItemsForFirstMappedLayer, categoryItemsForThisLayer);
- };
- //@returns true if categorySet1 and categorySet2 are different (in both directions)
- DataQueryUtils._categoriesAreDifferent = function _categoriesAreDifferent(categorySet1, categorySet2) {
- return _.difference(categorySet1 || [], categorySet2 || []).length > 0 || _.difference(categorySet2 || [], categorySet1 || []).length > 0;
- };
- //@returns the categorical items for the specified layer
- DataQueryUtils._getCategoryItemsForLayer = function _getCategoryItemsForLayer(slots) {
- var columnIdList = [];
- slots && slots.forEach(function (slot) {
- columnIdList.push.apply(columnIdList, _.map(slot.getDataItemList(), function (dataItem) {
- return dataItem.getColumnId();
- }));
- });
- return columnIdList;
- };
- DataQueryUtils.removeForecastFilters = function removeForecastFilters(spec) {
- //@returns querySpecList with values of form '"__ibm_ba_forecast__[0-9]*"' replaced by '""'.
- // Defect 286105: This is a temporary fix for sending filters on forecasted points to query service without them complaining
- // Resulting response would be empty if only a forecasted point filter is sent, or filtering on other selections
- // if filter includes other values. Filtering on forecasted points happens only when viz are brushed/filtered.
- var regex = new RegExp('"__ibm_ba_forecast__[0-9]*"', 'g');
- return JSON.parse(JSON.stringify(spec).replace(regex, '""'));
- };
- /**
- * Get the list of global filters that applies to the given visualization
- * @param {VisualizationAPI} visualization
- * @returns {Object[]} list of global filter specifications
- */
- DataQueryUtils.getFilterSpecListByVisualization = function getFilterSpecListByVisualization(content, dashboard) {
- var eventGroups = dashboard.getFeature('EventGroups');
- var globalFilters = dashboard.getFeature('GlobalFilters');
- var visualization = content.getFeature('Visualization');
- var filterQuerySpecList = [];
- var dataSource = visualization.getDataSource();
- var type = dashboard.getAppConfig('pageContainerType');
- var page = ContentUtil.getPageContent(content, type);
- var pageId = page && page.getId();
- if (dataSource) {
- filterQuerySpecList.push.apply(filterQuerySpecList, globalFilters.getFilterList({
- origin: 'filter',
- sourceId: dataSource.getId(),
- scope: pageId
- }, content.getId()));
- if (visualization.getDefinition().getProperty('reactToExternalBrushing') !== false) {
- var eventGroupId = eventGroups.getGroupId(content.getId());
- filterQuerySpecList.push.apply(filterQuerySpecList, globalFilters.getFilterList({
- origin: 'visualization',
- sourceId: dataSource.getId(),
- scope: pageId,
- eventGroupId: eventGroupId
- }, content.getId()));
- }
- }
- // Exclude binning filters since they are not fully supported by query service.
- return _.filter(filterQuerySpecList, function (filterSpec) {
- return !filterSpec.filterBins;
- });
- };
- /**
- * @function DataQueryUtils#getRelatedModelItemsForQueryHint
- * @description Get related model items used for query hint preferredModelItems
- * @public
- * @param {Object} Content API
- * @param {Object} Dashboard API
- * @return {Array} An arry of related model items
- */
- DataQueryUtils.getRelatedModelItemsForQueryHint = function getRelatedModelItemsForQueryHint(content, dashboard) {
- var eventGroups = dashboard.getFeature('EventGroups');
- var visualization = content.getFeature('Visualization');
- var dataSource = visualization.getDataSource();
- var sourceId = dataSource.getId();
- var contentId = content.getId();
- var groupId = eventGroups.getGroupId(contentId);
- var contentIdList = eventGroups.getContentIdList(groupId);
- if (!contentIdList) {
- return [];
- }
- var otherContentsInSameGroup = contentIdList.filter(function (id) {
- return id !== contentId;
- }).map(function (id) {
- return dashboard.getCanvas().getContent(id);
- });
- // TODO: back to it in R5, when deleting a widget, it has to get deleted from content.
- // Also, the content is null for the case we open a saved dashboard that it's vipr bundle is deleted, so it is in error state.
- // when deleting it, the content has null value
- otherContentsInSameGroup = otherContentsInSameGroup.filter(function (content) {
- var isValid = !!content;
- if (isValid) {
- var _visualization = content.getFeature('Visualization');
- var visDefinition = _visualization && _visualization.getDefinition();
- isValid = !(visDefinition && visDefinition.getState().getError());
- }
- return isValid;
- });
- var otherContentsInSameGroupWithSameSource = otherContentsInSameGroup.filter(function (content) {
- var otherVisualization = content.getFeature('Visualization');
- var dataSource = otherVisualization && otherVisualization.getDataSource();
- return dataSource && dataSource.getId() === sourceId;
- });
- var columnIdSet = {};
- otherContentsInSameGroupWithSameSource.forEach(function (content) {
- var slots = content.getFeature('Visualization').getSlots();
- slots.getDataItemList().forEach(function (dataItem) {
- // skip the fake multimeasure series dataitem
- if (!SlotAPIHelper.isMultiMeasuresSeriesOrValueDataItem(dataItem)) {
- var metadataColumn = dataItem.getMetadataColumn();
- if (metadataColumn && !metadataColumn.isOlapColumn()) {
- // Add related column id only when it exists and is not an olap column.
- columnIdSet[metadataColumn.getId()] = true;
- }
- }
- });
- });
- return Object.keys(columnIdSet);
- };
- return DataQueryUtils;
- }();
- });
- //# sourceMappingURL=DataQueryUtils.js.map
|