QueryDataItemBuilder.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. *
  8. */
  9. define(['./VisQuerySelectionBuilder'], function (VisQuerySelectionBuilder) {
  10. // noinspection JSAnnotator
  11. /**
  12. * INTENT: VisQueryDataItemBuilder is used to construct a dataItem in the form needed by the query.
  13. * building the dataItem involves a number of 'on the fly' steps such as:
  14. * inserting the appropriate initial selection based on the current drill state,
  15. * deciding if a filter should be a dataItem selection
  16. * ensuring that selections are performed in a predictable order (initial selection (root members or drill members), keep/remove, topN, sort)
  17. */
  18. var QueryDataItemBuilder = function () {
  19. function QueryDataItemBuilder(_ref) {
  20. var internalVisualization = _ref.internalVisualization,
  21. layerToQuerySlotsMap = _ref.layerToQuerySlotsMap,
  22. applyServerSort = _ref.applyServerSort;
  23. _classCallCheck(this, QueryDataItemBuilder);
  24. this.internalVisualization = internalVisualization;
  25. this.visQuerySelectionBuilder = new VisQuerySelectionBuilder({ internalVisualization: internalVisualization, layerToQuerySlotsMap: layerToQuerySlotsMap, applyServerSort: applyServerSort });
  26. }
  27. QueryDataItemBuilder.prototype._isExistingDrillSelection = function _isExistingDrillSelection(dataItem) {
  28. var drillSelection = dataItem.getDrillDownValue() || dataItem.getDrillUpValue();
  29. return !!drillSelection;
  30. };
  31. /*
  32. * @private
  33. * @return {Array} An array of Data Item objects assigned to a single slot.
  34. **/
  35. QueryDataItemBuilder.prototype.build = function build(dataItem, slot, outputEdgeFilterExceptions) {
  36. //todo: before here is oldDataItemAPI.toQueryJSON()
  37. var oDataItemJSON = {
  38. id: dataItem.getId(),
  39. itemId: dataItem.getColumnId()
  40. };
  41. if (!dataItem.getBinning() && this._isExistingDrillSelection(dataItem) && dataItem.getMetadataColumn().isNamedSet()) {
  42. oDataItemJSON.itemId = dataItem.getMetadataColumn().getReferencedHierarchyId();
  43. }
  44. if (dataItem.getType() === 'fact') {
  45. //MappedDataItemAPI#getType
  46. // If the final slot type is ordinal, it means we are querying the data item
  47. // in a ordinal form, which in this case we want to respect the aggregation type
  48. // except 'none'
  49. oDataItemJSON.aggregate = dataItem.getAggregation();
  50. }
  51. var finalSelection = this.visQuerySelectionBuilder.build(dataItem, slot, outputEdgeFilterExceptions);
  52. if (finalSelection.length) {
  53. oDataItemJSON.selection = finalSelection;
  54. }
  55. var binningSpec = this._buildAutoBinningSpec(dataItem);
  56. //binned dataItem type will be attribute, so if it has aggregate we need to remove it.
  57. // binningDefinition is part of toQueryJSON (need for copy/paste), but dss query has different format
  58. if (binningSpec) {
  59. //remove old selection, since it may have top/bottom
  60. if (!finalSelection.length) {
  61. delete oDataItemJSON.selection;
  62. }
  63. delete oDataItemJSON.aggregate;
  64. oDataItemJSON.binning = binningSpec;
  65. }
  66. return oDataItemJSON;
  67. };
  68. QueryDataItemBuilder.prototype._buildAutoBinningSpec = function _buildAutoBinningSpec(dataItem) {
  69. var MAX_DECIMAL_PLACES_DEFAULT = 2;
  70. var binning = dataItem.getBinning();
  71. if (binning) {
  72. var binningQuerySpec = {
  73. auto: {
  74. numberOfBins: binning.bins,
  75. maxDecPlaces: MAX_DECIMAL_PLACES_DEFAULT
  76. }
  77. };
  78. var format = dataItem.getFormat();
  79. if (format && Number.isInteger(format.maximumFractionDigits)) {
  80. binningQuerySpec.auto.maxDecPlaces = format.maximumFractionDigits;
  81. }
  82. return binningQuerySpec;
  83. }
  84. return null;
  85. };
  86. return QueryDataItemBuilder;
  87. }();
  88. return QueryDataItemBuilder;
  89. });
  90. //# sourceMappingURL=QueryDataItemBuilder.js.map