123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: admin
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', 'bi/commons/ui/core/Class', 'bi/admin/datasource/services/ApiSvc', 'bi/admin/nls/StringResource'], function (_, Class, Api, StringResource) {
- 'use strict'; //NOSONAR: meant to be strict
- var _singletonInstance = null;
- var DataSourceApp = Class.extend({
- systemTypes: ['JDBC', 'CUBE', 'JSON', 'ODATA'],
- exclusiveTypes: ['CUBE', 'JSON', 'ODATA'],
- _contexts: [],
- PASSWORD: '###PASSWORD###',
- init: function init() {
- var filterTypes = _.difference(this.systemTypes, this.exclusiveTypes);
- Api.filterTypes = filterTypes;
- },
- SlideOutDataSourceList: function SlideOutDataSourceList(glassContext, parentSlideout, dataSourceListTitle) {
- this._baseSlideOut = parentSlideout ? parentSlideout : this._baseSlideOut;
- this._glassContext = glassContext ? glassContext : this._glassContext;
- Api.glassContext = this._glassContext;
- if (dataSourceListTitle === undefined) {
- dataSourceListTitle = StringResource.get('dataServerPaneTitle');
- }
- glassContext.appController.showSlideOut({
- parent: this._baseSlideOut,
- overlay: true,
- width: '400px',
- label: dataSourceListTitle,
- content: {
- module: 'bi/admin/datasource/slideout/DataSourceListPane',
- id: 'DataSourcePane',
- title: dataSourceListTitle,
- showGobackButton: true
- }
- }); // get current sign on name space
- return this.getCurrentNameSpace().then(function (nsObj) {
- this._glassContext._currentNameSpace = nsObj;
- }.bind(this));
- },
- getCurrentNameSpace: function getCurrentNameSpace() {
- // get current sign on name space
- var url = 'v1/identity';
- return this.glassContext.services.fetch.get(url).then(function (response) {
- var identity = response.data;
- var inNS = _.find(identity.data, function (item) {
- return item.type === 'namespace' && item.searchPath.split('"')[1] === ":";
- });
- var exNS = _.find(identity.data, function (item) {
- return item.type === 'namespace' && item.searchPath.split('"')[1] !== ":";
- });
- var currentNS = exNS ? exNS : inNS;
- return {
- id: currentNS.id,
- searchPath: currentNS.searchPath,
- type: currentNS.type
- };
- }.bind(this));
- },
- //get all tables within a schema
- getTables: function getTables(schemaId, signonInfo) {
- return new Promise(function (resolve, reject) {
- var url = 'v1/metadata/schemas/tables?id=' + encodeURIComponent(schemaId);
- var connObj = {
- connections: signonInfo
- };
- var connectionSpec = "connectionSpec=" + encodeURIComponent(JSON.stringify(connObj));
- var ajaxOptions = {
- 'dataType': 'json',
- 'type': 'GET',
- 'url': url,
- 'data': connectionSpec
- };
- return this.glassContext.getCoreSvc('.Ajax').ajax(ajaxOptions).then(function (response) {
- resolve(response.data);
- }, function (error) {
- if (error.jqXHR) {
- var errorMessage = error.jqXHR.responseJSON ? error.jqXHR.responseJSON.msg : error.jqXHR.responseText;
- this.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
- }
- reject(error);
- }.bind(this));
- }.bind(this));
- },
- //get schema load options spec.
- getSchema: function getSchema(schemaId, signonInfo) {
- return new Promise(function (resolve, reject) {
- var url = 'v1/metadata/schemas/?id=' + encodeURIComponent(schemaId);
- var connObj = {
- connections: signonInfo
- };
- var connectionSpec = "connectionSpec=" + encodeURIComponent(JSON.stringify(connObj));
- var ajaxOptions = {
- 'dataType': 'json',
- 'type': 'GET',
- 'url': url,
- 'data': connectionSpec
- };
- return this.glassContext.getCoreSvc('.Ajax').ajax(ajaxOptions).then(function (response) {
- resolve(response.data.data[0]);
- }, function (error) {
- if (error.jqXHR) {
- var errorMessage = error.jqXHR.responseJSON ? error.jqXHR.responseJSON.msg : error.jqXHR.responseText;
- this.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
- }
- reject(error);
- }.bind(this));
- }.bind(this));
- },
- //update schema with load option spec.
- updateSchema: function updateSchema(schemaId, data) {
- return new Promise(function (resolve, reject) {
- Api.schemas.update(schemaId, data).then(resolve, function (err, jqXHR) {
- var errorMessage = jqXHR.responseJSON ? jqXHR.responseJSON.msg : jqXHR.responseText;
- this.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
- reject(err, jqXHR);
- }.bind(this));
- }.bind(this));
- },
- //create new schema in sources
- createSchemaSource: function createSchemaSource(connId, data) {
- return new Promise(function (resolve, reject) {
- Api.schemaSources.create(connId, data).then(function () {
- //return the Moser response containing storeId of new created schema.
- var obj = {
- getResponseHeader: arguments[2].getResponseHeader
- };
- resolve(obj);
- }, function (err, jqXHR) {
- var errorMessage = jqXHR.responseJSON ? jqXHR.responseJSON.msg : jqXHR.responseText;
- this.glassContext.appController.showErrorMessage(errorMessage, StringResource.get('error'));
- reject(err, jqXHR);
- }.bind(this));
- }.bind(this));
- },
- CancelTask: function CancelTask(taskId, xCaAffinity) {
- return new Promise(function (resolve, reject) {
- Api.tasks.cancel(taskId, xCaAffinity).then(resolve, function (err, jqXHR) {
- this.glassContext.appController.showErrorMessage(jqXHR.responseJSON.messages[0], StringResource.get('error'));
- reject(err, jqXHR);
- }.bind(this));
- }.bind(this));
- },
- /**
- * This method fetches the history of the schema with schemaID. Makes a call to ApiSvc._getHistoryApiSet.
- * @param {String} The schemaID of the selected schema
- * @return {Promise} A promise with the schema history data
- */
- getHistory: function getHistory(schemaId) {
- return new Promise(function (resolve, reject) {
- Api.history.list(schemaId).then(function (response) {
- resolve(response.data);
- }, function (err, jqXHR) {
- this.glassContext.appController.showErrorMessage(jqXHR.responseJSON.msg, StringResource.get('error'));
- reject(err, jqXHR);
- }.bind(this));
- }.bind(this));
- },
- CreateSchema: function CreateSchema(item, view) {
- var dataItem = {
- schema: item.schema,
- catalog: item.catalog,
- type: item.type,
- schemaType: item.schemaType || 'user',
- defaultName: item.defaultName,
- specification: item.specification,
- status: 'pending'
- };
- return this.createSchemaSource(view.conn.id, dataItem);
- },
- ClearSchema: function ClearSchema(item) {
- return new Promise(function (resolve, reject) {
- Api.schemas.clear(item.id).then(resolve, function (err, jqXHR) {
- this.glassContext.appController.showErrorMessage(jqXHR.responseJSON.messages[0], StringResource.get('error'));
- reject(err, jqXHR);
- }.bind(this));
- }.bind(this));
- },
- /**
- * get data source connection info and render GroupListView.
- * @private
- * @param dataSources {Array<Object>} each object includes the specified data source info.
- * dataSources[i]: {
- * _type: 'dataSource', activeConnection: Object, connectionString: ';LOCAL;OL;DBInfo_Type=MS;...', context: Object, defaultDescription: 'Description goes here',
- * defaultName: 'new', disabled: 'false', hasChildren: 'true', hidden: 'false', id: 'iF0651295A97E464A83F22D202AA9E797', objectClass: 'dataSource',
- * permissions: Array, searchPath: 'CAMID(":")/dataSource[@name='new']', shown: 'true', tenantID: '', usage: 'object'
- * }
- */
- FillConnectionList: function FillConnectionList(dataSource, formView) {
- var items = _.map(dataSource.connections, function (conn) {
- var writable = conn.permissions && conn.permissions.indexOf('write') > -1 ? true : false;
- return {
- id: dataSource.id,
- connId: conn.id,
- title: conn.defaultName,
- defaultName: conn.defaultName,
- defaultDescription: conn.defaultDescription,
- connectionString: conn.connectionString,
- credentialNamespaces: conn.credentialNamespaces,
- disabled: conn.disabled,
- hidden: conn.hidden,
- writable: writable
- };
- });
- items = _.filter(items, function (item) {
- return item != null;
- });
- var viewObj = {};
- viewObj.items = items;
- viewObj.writable = dataSource.writable;
- viewObj.datasourceName = dataSource.defaultName; // defaultDescription will be undefined when user save a "", so need to change it to "" here
- viewObj.datasourceDescription = dataSource.defaultDescription || '';
- viewObj.datasourceId = dataSource.id;
- formView.items = items;
- formView.render(viewObj);
- this._dcListView = formView;
- }
- });
- var _static = {
- getInstance: function getInstance() {
- if (!_singletonInstance) {
- _singletonInstance = new DataSourceApp();
- }
- return _singletonInstance;
- }
- };
- return _static.getInstance();
- });
|