PostProcessOlapProperties.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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; }
  5. /*
  6. *+------------------------------------------------------------------------+
  7. *| Licensed Materials - Property of IBM
  8. *| IBM Cognos Products: BI Dashboard
  9. *| (C) Copyright IBM Corp. 2019, 2020
  10. *|
  11. *| US Government Users Restricted Rights - Use, duplication or disclosure
  12. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  13. *+------------------------------------------------------------------------+
  14. */
  15. define(['./QueryPostProcessor'], function (QueryPostProcessor) {
  16. /**
  17. * @description Property display value is used for dashboard rendering, and the corresponding member unique id is
  18. * used for filters or other actions. V2 query response has property display values embedded in its parent valueSet.
  19. * This class maps olap property display value to '.d' in identifier to make v2 query response algin with
  20. * current dashboard implementation so v1 and v2 queries can follow the same logic.
  21. *
  22. * @example The response identifiers with an olap property:
  23. * '1': {
  24. * 'ihId': 1,
  25. * 'd': 'Camping Equipment',<-corresponding member display value
  26. * 'u': '[Sales (analysis)].[Products].[Products].[Product line]->[Products].[991]',<-corresponding member unique id
  27. * 'Product line code': {<-property name
  28. * 'v': 991<-property display value
  29. * }
  30. * }
  31. *
  32. * After process:
  33. * '1': {
  34. * 'ihId': 1,
  35. * 'd': 991,
  36. * 'u': '[Sales (analysis)].[Products].[Products].[Product line]->[Products].[991]',<-corresponding member unique id
  37. * }
  38. **/
  39. return function (_QueryPostProcessor) {
  40. _inherits(PostProcessOlapProperties, _QueryPostProcessor);
  41. /**
  42. * @Constructor
  43. * @param {Object} queryResultData The raw query result data
  44. * @param {VisualizationAPI} visualization The {@link VisualizationAPI}
  45. */
  46. function PostProcessOlapProperties(_ref) {
  47. var queryResultData = _ref.queryResultData,
  48. visualization = _ref.visualization;
  49. _classCallCheck(this, PostProcessOlapProperties);
  50. var _this = _possibleConstructorReturn(this, _QueryPostProcessor.call(this, { queryResultData: queryResultData }));
  51. _this.visualization = visualization;
  52. _this.visDataItems = _this.visualization.getSlots().getDataItemList() || [];
  53. _this.edges = _this._queryResultData.edges;
  54. return _this;
  55. }
  56. /**
  57. * Apply the users overrides
  58. * @return {QueryResultData}
  59. */
  60. PostProcessOlapProperties.prototype._processData = function _processData() {
  61. // TODO Need to handle list viz post endor r5.
  62. if (this.edges) {
  63. // Build properties map from slots data items with property id as the key and the property label as the value.
  64. var properties = {};
  65. this.visDataItems.forEach(function (visDataItem) {
  66. var metadataColumn = visDataItem.getMetadataColumn();
  67. if (metadataColumn && metadataColumn.isProperty()) {
  68. properties[visDataItem.getId()] = metadataColumn.getLabel();
  69. }
  70. });
  71. var propertiesIds = Object.keys(properties);
  72. var propertyIdx = -1;
  73. if (propertiesIds.length) {
  74. // Build ihId and property name map from query response if query has any property projected
  75. var ihIdAndPropertyNameMap = {};
  76. this.edges.forEach(function (edge) {
  77. edge.itemClasses.forEach(function (itemClass) {
  78. itemClass.h.forEach(function (header) {
  79. propertyIdx = propertiesIds.indexOf(header.di);
  80. if (propertyIdx !== -1) {
  81. ihIdAndPropertyNameMap[header.ihId] = properties[propertiesIds[propertyIdx]];
  82. }
  83. });
  84. });
  85. var ihIdsOfProperties = Object.keys(ihIdAndPropertyNameMap);
  86. if (ihIdsOfProperties.length) {
  87. // Replace identifiers .d value: replace member caption with projected property value.
  88. ihIdsOfProperties.forEach(function (ihId) {
  89. //edge.identifiers might not be defined;
  90. edge.identifiers && Object.values(edge.identifiers).forEach(function (identifier) {
  91. if (identifier.ihId === parseInt(ihId)) {
  92. var propertyName = ihIdAndPropertyNameMap[ihId];
  93. if (identifier[propertyName]) {
  94. identifier.d = identifier[propertyName].v;
  95. delete identifier[propertyName];
  96. }
  97. }
  98. });
  99. });
  100. ihIdAndPropertyNameMap = {};
  101. }
  102. });
  103. }
  104. }
  105. return this._queryResultData;
  106. };
  107. return PostProcessOlapProperties;
  108. }(QueryPostProcessor);
  109. });
  110. //# sourceMappingURL=PostProcessOlapProperties.js.map