'use strict'; /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: BI Dashboard *| (C) Copyright IBM Corp. 2015, 2017 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ //TODO this is a singleton and needs to die! define(['underscore'], function (_) { /** * @private */ var _instance = null; /** *we could pass options for initialization *@constructor */ var DBUtils = function DBUtils() {}; /** *@constant *@type {string} */ DBUtils.prototype.CONSTANTS = { METADATA_ENDPOINT_PREFIX: '/bi/v1/metdata/proposals/', METADATA_ENDPOINT_POSTFIX: '/metadata' }; /** * @param moserResponse, an Array of object, returned by moser intent search * service each array element contains dataset information, search terms, * and more */ DBUtils.prototype.toIntentFormat = function (moserResponse) { var arrColumns = []; var dataSet = {}; //Filter results that don't contain significant columns. var filteredResults = _.filter(moserResponse, function (searchResult) { return searchResult.proposal.metadataTreeViewFocus.significant && searchResult.proposal.metadataTreeViewFocus.significant.length > 0; }); var result = _.map(filteredResults, function (searchResult) { arrColumns = searchResult.proposal.metadataTreeViewFocus.significant; var score = searchResult['relevant score']; var type = 'uploadedFile'; if (searchResult.type === 'databases') { type = 'module'; } else if (searchResult.type === 'files') { //Handlder for baseModule from uploaded files if (searchResult.parentId && searchResult.parentId.length > 0) { type = 'uploadedFile'; searchResult.id = searchResult.parentId; } else if (searchResult.href.indexOf('/base_modules') !== -1 && searchResult.href.indexOf('datasets:') === -1) { type = 'base_module'; } } dataSet = { 'id': searchResult.id.indexOf('datasets:') === 0 ? searchResult.id.replace('datasets:', '') : searchResult.id, 'last-modified': searchResult.lastModified, 'name': searchResult.label, 'url': DBUtils.prototype.CONSTANTS.METADATA_ENDPOINT_PREFIX + searchResult.id + DBUtils.prototype.CONSTANTS.METADATA_ENDPOINT_POSTFIX, 'influential': searchResult.proposal.metadataTreeViewFocus.influential, 'significant': searchResult.proposal.metadataTreeViewFocus.significant, 'intent': searchResult.proposal.metadataTreeViewFocus.intent, 'type': type, 'score': _.isNumber(score) ? score : parseInt(score, 10) }; return { 'columns': arrColumns, 'dataSet': dataSet }; }); return _.sortBy(result, function (o) { return o.dataSet.score; }).reverse(); }; /** * Given a datasetID (indentifier), return an object of a proposal * * @param moserResponse @type {array of Object} * @param datasetID @type {String} */ DBUtils.prototype.findDataset = function (moserResponse, datasetID) { var results = _.find(moserResponse, function (item) { return item.identifier === datasetID; }); return results; }; /** * @param {Object} services, dashboard services * @return {Promise} that can retrieve the CA global configuration object * */ DBUtils.prototype.getGlobalConfigByName = function (services, params) { return this.glassContext.getCoreSvc('.Ajax').ajax(params); }; var _singleton = { getInstance: function getInstance() { if (!_instance) { _instance = new DBUtils(); } return _instance; } }; return _singleton.getInstance(); }); //# sourceMappingURL=DBUtils.js.map