SummaryTask.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Dashboard
  5. * (C) Copyright IBM Corp. 2018, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. *
  8. */
  9. define(['underscore', '../../../visualizations/renderer/sequence/BaseTask', './SummaryTypes'], function (_, BaseTask, SummaryTypes) {
  10. 'use strict';
  11. /**
  12. * @class SummaryTask
  13. * Task to run the summary queries as part of the render sequence
  14. */
  15. var SummaryTask = BaseTask.extend({
  16. init: function init(options, moduleOptions) {
  17. SummaryTask.inherited('init', this, arguments);
  18. this.feature = moduleOptions.summaryFeature;
  19. this.visualization = moduleOptions.visualization;
  20. this.content = moduleOptions.content;
  21. },
  22. /**
  23. * @private
  24. * @function _requiresSummaryQuery
  25. * Check if the current data mapping requires a summary query
  26. * @return {boolean} true if visualization requires a summary query based on the current mapping, otherwise false
  27. */
  28. _requiresSummaryQuery: function _requiresSummaryQuery() {
  29. // Check the visualization property first if it requires summaries
  30. var v2QuerySupported = this.content.getFeature('Visualization').getType() === 'Crosstab';
  31. if (v2QuerySupported || this.feature.isNotSupported() || this.content.getPropertyValue('hideSummaries') === true) {
  32. return false;
  33. }
  34. // We assume the SummaryTask is created because
  35. // the visualization supports summary queries
  36. // question is it required to do sumbit a summary query
  37. return _.find(this.visualization.getSlots().getMappedSlotList(), function (slotAPI) {
  38. return _.find(slotAPI.getDataItemList(), function (dataItemAPI) {
  39. if (dataItemAPI.getType() === 'fact' && slotAPI.getDefinition().getProperty('summaryValues')) {
  40. return SummaryTypes.indexOf(dataItemAPI.getAggregation()) > -1;
  41. }
  42. });
  43. }) ? true : false;
  44. },
  45. /**
  46. * @public
  47. * @override
  48. * @function process
  49. * Process the summaries
  50. * @param {Object} renderContext - The render renderContext
  51. * @returns {Promise} - Promise which resolves when the task is finished
  52. */
  53. process: function process(renderContext) {
  54. var _this = this;
  55. if (this._isStepComplete(renderContext, this.getId())) {
  56. return Promise.resolve(renderContext);
  57. }
  58. if (this._requiresSummaryQuery()) {
  59. this._queryExecution = this._queryExecution || this.content.getFeature('DataQueryExecution');
  60. this._queryModifier = this._queryModifier || this.content.getFeature('SummaryQueryModifier');
  61. this._queryModifier.resetDataItemIdList();
  62. var projectionsList = this._getProjectionList();
  63. _.each(projectionsList, function (projections, idx) {
  64. _this._queryModifier.addDataItemIdList(projections);
  65. _this.feature.addSummaryQueryResult(idx, _this._queryExecution.executeQueries('summary'));
  66. });
  67. }
  68. this._completeStep(renderContext, this.getId(), arguments);
  69. return Promise.resolve(renderContext);
  70. },
  71. /**
  72. * @private
  73. * Assemble the query projections from category and measure unique ids.
  74. * @returns {string[]} An array of arrays corresponding to the summary query projection list.
  75. * @example
  76. * oQueryProjections = {
  77. * aCategoryUIds: [[A],[AB],[ABC],[D],[DE],[EDF],[AD],[ADE],[ADEF],[ABD],[ABDE],[ABDEF],[ABCD],[ABCDE]],
  78. * aOrdinalUIds: [G, H]
  79. * }
  80. * result = [
  81. ['A','G','H'],
  82. ['A','B','G','H'],
  83. ['A','B','C','G','H'],
  84. ['D','G','H'],
  85. ['D','E','G','H'],
  86. ['D','E','F','G','H'],
  87. ['A','D','G','H'],
  88. ['A','D','E','G','H'],
  89. ['A','D','E','F','G','H'],
  90. ['A','B','D','G','H'],
  91. ['A','B','D','E','G','H'],
  92. ['A','B','D','E','F','G','H'],
  93. ['A','B','C','D','G','H'],
  94. ['A','B','C','D','E','G','H'],
  95. ['G','H']
  96. ]
  97. */
  98. _getProjectionList: function _getProjectionList() {
  99. var oQueryProjections = this.feature && this.feature.getProjectionListObj();
  100. if (_.isEmpty(oQueryProjections)) {
  101. return [];
  102. }
  103. var aSummaryQueryProjections = _.map(oQueryProjections.aCategoryUIds, function (uIds) {
  104. return uIds.concat(oQueryProjections.aOrdinalUIds);
  105. });
  106. aSummaryQueryProjections.push(oQueryProjections.aOrdinalUIds); // The last query is the overall summary query.
  107. return aSummaryQueryProjections;
  108. }
  109. });
  110. return SummaryTask;
  111. });
  112. //# sourceMappingURL=SummaryTask.js.map