MissingOriginalCustomGroupItemId.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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
  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(['underscore', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) {
  16. var MissingOriginalCustomGroupItemId = function (_UpgradeBase) {
  17. _inherits(MissingOriginalCustomGroupItemId, _UpgradeBase);
  18. function MissingOriginalCustomGroupItemId() {
  19. _classCallCheck(this, MissingOriginalCustomGroupItemId);
  20. var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this));
  21. _this.VERSION = 1403;
  22. return _this;
  23. }
  24. /**
  25. * Perform upgrade to add "originalCustomGroupItemId" to the dataItem when it represents a custom group
  26. * @param {object} spec - spec to perform upgrade on
  27. * @return {Promise} Promise to be resolved when upgrade performed
  28. */
  29. MissingOriginalCustomGroupItemId.prototype.up = function up(spec) {
  30. if (!spec) {
  31. return Promise.resolve(spec);
  32. }
  33. if (!WidgetUpgradeUtils.specHasWidgets(spec)) {
  34. return Promise.resolve(spec);
  35. }
  36. return this._upgradeWidgets(spec);
  37. };
  38. MissingOriginalCustomGroupItemId.prototype.down = function down(spec) {
  39. // Downgrades are not available in CA
  40. return Promise.resolve(spec);
  41. };
  42. MissingOriginalCustomGroupItemId.prototype._upgradeWidgets = function _upgradeWidgets(spec) {
  43. var _this2 = this;
  44. try {
  45. _.each(spec.widgets, function (model) {
  46. _this2._upgradeWidget(model, spec);
  47. });
  48. return Promise.resolve(spec);
  49. } catch (error) {
  50. throw error;
  51. }
  52. };
  53. MissingOriginalCustomGroupItemId.prototype._upgradeWidget = function _upgradeWidget(model, spec) {
  54. var _this3 = this;
  55. _.each(model.data && model.data.dataViews, function (dataView) {
  56. var moduleId = dataView.modelRef;
  57. var dataItems = dataView.dataItems;
  58. var dataSources = spec.dataSources;
  59. _this3._setOriginalCustomGroupItemId(dataSources && dataSources.sources, moduleId, dataItems);
  60. });
  61. };
  62. MissingOriginalCustomGroupItemId.prototype._setOriginalCustomGroupItemId = function _setOriginalCustomGroupItemId(sources, moduleId, dataItems) {
  63. var source = _.findWhere(sources, { id: moduleId });
  64. if (source) {
  65. var moserJSON = source.shaping && source.shaping.moserJSON;
  66. var calculations = moserJSON && moserJSON.calculation;
  67. _.each(dataItems, function (dataItem) {
  68. var calculation = _.findWhere(calculations, { identifier: dataItem.itemId });
  69. if (calculation) {
  70. var uiExprProperties = _.where(calculation.property, { name: 'ui_expr' });
  71. if (uiExprProperties) {
  72. _.find(uiExprProperties, function (property) {
  73. var value = JSON.parse(property.value);
  74. if (value.func === 'customGroup') {
  75. dataItem.originalCustomGroupItemId = value.basedOnMoserObject;
  76. return true;
  77. }
  78. });
  79. }
  80. }
  81. });
  82. }
  83. };
  84. return MissingOriginalCustomGroupItemId;
  85. }(UpgradeBase);
  86. return new MissingOriginalCustomGroupItemId();
  87. });
  88. //# sourceMappingURL=MissingOriginalCustomGroupItemId.js.map