'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: Dashboard * (C) Copyright IBM Corp. 2017, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../DynamicFileLoader'], function (DynamicFileLoader) { var RelinkUtils = function () { function RelinkUtils() { _classCallCheck(this, RelinkUtils); } RelinkUtils.relink = function relink(source, newSourceInfo, dashboardApi) { var oldCMAssetId = source.getAssetId(); return dashboardApi.getFeature('.LifeCycleManager').invokeLifeCycleHandlers('pre:relink').then(function () { return Promise.all([source.relink(newSourceInfo), DynamicFileLoader.load(['dashboard-analytics/dataSources/utils/RelinkItemIdInSpec'])]); }).then(function (Results) { var logger = dashboardApi.getGlassCoreSvc('.Logger'); var sourceInfo = Results[0]; var RelinkItemIdInSpec = Results[1][0]; var newDashboardJSONSpec = void 0; var oldDashboardSpec = dashboardApi.getFeature('internal').getBoardModel().toJSON(); if (sourceInfo) { var newCMAssetId = newSourceInfo.assetId; var relinkItemIdInSpec = new RelinkItemIdInSpec(oldDashboardSpec, { sourceId: sourceInfo.sourceId, oldCMAssetId: oldCMAssetId, newCMAssetId: newCMAssetId }, logger); var oldItemIds = relinkItemIdInSpec.getItemIds(); var newItemIds = sourceInfo.relinkIdForExpressions(oldItemIds); newDashboardJSONSpec = relinkItemIdInSpec.replaceItemIds(newItemIds); } //relink is only supported for uploaded files. For non-uploaded files use the oldDashboardSpec since newDashboardJSONSpec is undefined return dashboardApi.reloadFromJSONSpec(newDashboardJSONSpec || oldDashboardSpec); }).then(function (dashboardApi) { return dashboardApi.getFeature('.LifeCycleManager').invokeLifeCycleHandlers('post:relink'); }); }; return RelinkUtils; }(); return RelinkUtils; }); //# sourceMappingURL=RelinkUtils.js.map