123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- '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, 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../../../DynamicFileLoader', 'underscore'], function (DynamicFileLoader, _) {
- 'use strict';
- return function () {
- function SourceManager(options) {
- _classCallCheck(this, SourceManager);
- this.sourceModel = options.sourceModel;
- this.dashboardApi = options.dashboardApi;
- this.sourcesCollectionManager = options.sourcesCollectionManager;
- // If the source was just added then we should already have the localized name
- if (this.sourceModel) {
- this.localizedName = this.sourceModel.get('localizedName') || null;
- this.cmObjectExists = this.sourceModel.get('cmObjectExists') || undefined;
- this.modificationTime = this.sourceModel.get('modificationTime') || null;
- this.sourceModel.setAjaxSvc(this.dashboardApi.getGlassCoreSvc('.Ajax'));
- this.sourceModel.setUserProfileSvc(this.dashboardApi.getGlassCoreSvc('.UserProfile'));
- }
- }
- /**
- * Returns a promise which will resolve with a module API wrapper around the moserJS module object
- * @param moduleID optional moduleID that already exists on the server
- * @param {boolean} [showErrorToast] optional flag for showing error toast
- * @param {boolean} [clearTemporaryModule] optional flag to clear temporary module (e.g. when relinking)
- * @return {Promise} Promise that will get resolved with the ModuleAPI object
- */
- SourceManager.prototype.getModule = function getModule(moduleId, showErrorToast, clearTemporaryModule) {
- var _this = this;
- if (this._moduleAPI) {
- if (this.isInErrorState()) {
- return Promise.reject({
- sourceInfo: {
- name: this.localizedName
- }
- });
- }
- if (clearTemporaryModule) {
- this._moduleAPI.clearTemporaryModule();
- }
- // wait for the temporary module to be loaded
- // which can take longer without optimizations
- return this._moduleAPI.whenTemporaryModuleReady().then(function () {
- return _this._moduleAPI;
- });
- }
- //if the load module is in progress, return the current promise instead of creating another module.
- if (this.modulePromise) {
- return this.modulePromise;
- }
- // Delay loading this class as long as possible since it loads the modelling code
- this.modulePromise = DynamicFileLoader.load(['dashboard-analytics/dataSources/modelapis/ModuleAPI']).then(this._loadModuleAPI.bind(this, moduleId, showErrorToast)).then(function (res) {
- _this.modulePromise = null;
- return res;
- }).catch(function (error) {
- _this.dashboardApi.getGlassCoreSvc('.Logger').error(error);
- _this.sourceModel.set({
- state: 'error'
- }, {
- silent: true
- });
- _this.modulePromise = null;
- throw error;
- });
- return this.modulePromise;
- };
- SourceManager.prototype._loadModuleAPI = function _loadModuleAPI(moduleId, showErrorToast, modules) {
- var _this2 = this;
- var ModuleAPI = modules[0];
- var moduleAPI = new ModuleAPI({
- 'sourceModel': this.sourceModel,
- 'dashboardApi': this.dashboardApi,
- 'sourceModelManager': this
- });
- // Make sure we call load before resolving the promise. The load will take care of making
- // sure the moserJS object is initialzed with the metadata
- return moduleAPI.load(moduleId, showErrorToast).then(function () {
- _this2._moduleAPI = moduleAPI;
- return _this2._moduleAPI;
- }).catch(function (error) {
- _this2.dashboardApi.getGlassCoreSvc('.Logger').error(error);
- _this2.sourceModel.set({
- state: 'error',
- errorCode: error.code
- }, {
- silent: true
- });
- _this2._moduleAPI = moduleAPI;
- throw error;
- });
- };
- /**
- * Returns the type of the intiial source
- * @return {String} The type of the source
- */
- SourceManager.prototype.getType = function getType() {
- return this.sourceModel.get('type');
- };
- SourceManager.prototype._queryCMObject = function _queryCMObject() {
- if (this.hasQueriedCM) {
- return Promise.resolve();
- }
- if (this.sourceModel.hasInlineModule()) {
- this._handleQueryCMObjectSuccess({
- data: {
- data: [{
- defaultName: this.sourceModel.name,
- searchPath: this.sourceModel.assetId,
- modificationTime: null
- }]
- }
- });
- return Promise.resolve();
- }
- if (!this._queryCMObjectPromise) {
- // Should query sourceModel only once.
- this._queryCMObjectPromise = this.dashboardApi.getGlassCoreSvc('.Ajax').ajax({
- url: 'v1/objects/' + this.sourceModel.get('assetId') + '?fields=userInterfaces,defaultName,searchPath',
- type: 'GET',
- headers: {
- 'Accept': 'application/json'
- }
- }).then(this._handleQueryCMObjectSuccess.bind(this)).catch(this._handleQueryCMObjectError.bind(this));
- }
- return this._queryCMObjectPromise;
- };
- SourceManager.prototype._handleQueryCMObjectSuccess = function _handleQueryCMObjectSuccess(response) {
- var data = response.data.data;
- this.hasQueriedCM = true;
- if (data && data.length > 0) {
- this.localizedName = data[0].defaultName;
- this.modificationTime = data[0].modificationTime;
- this.sourceModel.searchPath = data[0].searchPath;
- if (data[0].type === 'package' && data[0].userInterfaces && _.indexOf(data[0].userInterfaces, 'analysisStudio') >= 0) {
- this.sourceModel.isOlapPackage = true;
- } else {
- this.sourceModel.isOlapPackage = false;
- }
- this.cmObjectExists = true;
- } else {
- this._setErrorState();
- }
- if (this.sourceModel.get('pinSourceName')) {
- this.localizedName = this.localizedName + ' - ' + this.sourceModel.get('pinSourceName');
- }
- };
- SourceManager.prototype._handleQueryCMObjectError = function _handleQueryCMObjectError() {
- this._setErrorState();
- };
- SourceManager.prototype._setErrorState = function _setErrorState() {
- this.localizedName = this.sourceModel.get('name');
- this.cmObjectExists = false;
- this.sourceModel.set({
- state: 'error'
- }, {
- silent: true
- });
- };
- /**
- * Get the localized name of the source
- * @return {Promise} Promise that will be resolved with localized name of the data source
- */
- SourceManager.prototype.getLocalizedName = function getLocalizedName() {
- var _this3 = this;
- if (this.localizedName) {
- return Promise.resolve(this.localizedName);
- }
- return this._queryCMObject().then(function () {
- return _this3.localizedName;
- });
- };
- SourceManager.prototype.getSearchPath = function getSearchPath() {
- var _this4 = this;
- if (this.sourceModel.searchPath) {
- return Promise.resolve(this.sourceModel.searchPath);
- }
- return this._queryCMObject().then(function () {
- return _this4.sourceModel.searchPath;
- });
- };
- SourceManager.prototype.exists = function exists() {
- var _this5 = this;
- if (this.cmObjectExists !== undefined) {
- return Promise.resolve(this.cmObjectExists);
- }
- return this._queryCMObject().then(function () {
- return _this5.cmObjectExists;
- });
- };
- SourceManager.prototype.getModificationTime = function getModificationTime() {
- var _this6 = this;
- if (this.modificationTime) {
- return Promise.resolve(this.modificationTime);
- }
- return this._queryCMObject().then(function () {
- return _this6.modificationTime;
- });
- };
- SourceManager.prototype.relink = function relink(newDatasourceInfo) {
- var _this7 = this;
- delete this.localizedName;
- delete this.modificationTime;
- delete this.cmObjectExists;
- this.hasQueriedCM = false;
- this.sourceModel.set({
- state: '',
- errorCode: ''
- }, {
- silent: true
- });
- this.sourceModel.set(newDatasourceInfo, {
- payloadData: {
- skipUndoRedo: true
- }
- });
- return this.getModule(null, null, true).then(function (moduleAPI) {
- return moduleAPI.relink(_this7.sourceModel);
- }).then(function (payload) {
- return payload;
- }).catch(this.generalRequestErrorHandler.bind(this));
- };
- SourceManager.prototype.reloadMetadata = function reloadMetadata() {
- if (!this._moduleAPI) {
- return Promise.resolve();
- }
- return this._moduleAPI.reloadMetadata().catch(this.generalRequestErrorHandler.bind(this));
- };
- /*
- * A generic error handler that sets the state in the source model and re-throws the error
- */
- SourceManager.prototype.generalRequestErrorHandler = function generalRequestErrorHandler(error) {
- this.sourceModel.set({
- state: 'error'
- });
- throw error;
- };
- SourceManager.prototype.getState = function getState() {
- return this.sourceModel.get('state');
- };
- SourceManager.prototype.setState = function setState(state) {
- this.sourceModel.set({
- state: state
- });
- };
- SourceManager.prototype.getLastModified = function getLastModified() {
- return this._lastModified;
- };
- SourceManager.prototype.setLastModified = function setLastModified(lastModified) {
- this._lastModified = lastModified;
- };
- SourceManager.prototype.isInErrorState = function isInErrorState() {
- return this.sourceModel.get('state') === 'error';
- };
- return SourceManager;
- }();
- });
- //# sourceMappingURL=SourceModelManager.js.map
|