'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; } 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; } /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: BI Dashboard *| (C) Copyright IBM Corp. 2019 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['underscore', '../../../lib/@waca/upgrades/UpgradeBase', './utils/WidgetUpgradeUtils'], function (_, UpgradeBase, WidgetUpgradeUtils) { var MissingOriginalCustomGroupItemId = function (_UpgradeBase) { _inherits(MissingOriginalCustomGroupItemId, _UpgradeBase); function MissingOriginalCustomGroupItemId() { _classCallCheck(this, MissingOriginalCustomGroupItemId); var _this = _possibleConstructorReturn(this, _UpgradeBase.call(this)); _this.VERSION = 1403; return _this; } /** * Perform upgrade to add "originalCustomGroupItemId" to the dataItem when it represents a custom group * @param {object} spec - spec to perform upgrade on * @return {Promise} Promise to be resolved when upgrade performed */ MissingOriginalCustomGroupItemId.prototype.up = function up(spec) { if (!spec) { return Promise.resolve(spec); } if (!WidgetUpgradeUtils.specHasWidgets(spec)) { return Promise.resolve(spec); } return this._upgradeWidgets(spec); }; MissingOriginalCustomGroupItemId.prototype.down = function down(spec) { // Downgrades are not available in CA return Promise.resolve(spec); }; MissingOriginalCustomGroupItemId.prototype._upgradeWidgets = function _upgradeWidgets(spec) { var _this2 = this; try { _.each(spec.widgets, function (model) { _this2._upgradeWidget(model, spec); }); return Promise.resolve(spec); } catch (error) { throw error; } }; MissingOriginalCustomGroupItemId.prototype._upgradeWidget = function _upgradeWidget(model, spec) { var _this3 = this; _.each(model.data && model.data.dataViews, function (dataView) { var moduleId = dataView.modelRef; var dataItems = dataView.dataItems; var dataSources = spec.dataSources; _this3._setOriginalCustomGroupItemId(dataSources && dataSources.sources, moduleId, dataItems); }); }; MissingOriginalCustomGroupItemId.prototype._setOriginalCustomGroupItemId = function _setOriginalCustomGroupItemId(sources, moduleId, dataItems) { var source = _.findWhere(sources, { id: moduleId }); if (source) { var moserJSON = source.shaping && source.shaping.moserJSON; var calculations = moserJSON && moserJSON.calculation; _.each(dataItems, function (dataItem) { var calculation = _.findWhere(calculations, { identifier: dataItem.itemId }); if (calculation) { var uiExprProperties = _.where(calculation.property, { name: 'ui_expr' }); if (uiExprProperties) { _.find(uiExprProperties, function (property) { var value = JSON.parse(property.value); if (value.func === 'customGroup') { dataItem.originalCustomGroupItemId = value.basedOnMoserObject; return true; } }); } } }); } }; return MissingOriginalCustomGroupItemId; }(UpgradeBase); return new MissingOriginalCustomGroupItemId(); }); //# sourceMappingURL=MissingOriginalCustomGroupItemId.js.map