DBUtils.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2015, 2017
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. //TODO this is a singleton and needs to die!
  13. define(['underscore'], function (_) {
  14. /**
  15. * @private
  16. */
  17. var _instance = null;
  18. /**
  19. *we could pass options for initialization
  20. *@constructor
  21. */
  22. var DBUtils = function DBUtils() {};
  23. /**
  24. *@constant
  25. *@type {string}
  26. */
  27. DBUtils.prototype.CONSTANTS = {
  28. METADATA_ENDPOINT_PREFIX: '/bi/v1/metdata/proposals/',
  29. METADATA_ENDPOINT_POSTFIX: '/metadata'
  30. };
  31. /**
  32. * @param moserResponse, an Array of object, returned by moser intent search
  33. * service each array element contains dataset information, search terms,
  34. * and more
  35. */
  36. DBUtils.prototype.toIntentFormat = function (moserResponse) {
  37. var arrColumns = [];
  38. var dataSet = {};
  39. //Filter results that don't contain significant columns.
  40. var filteredResults = _.filter(moserResponse, function (searchResult) {
  41. return searchResult.proposal.metadataTreeViewFocus.significant && searchResult.proposal.metadataTreeViewFocus.significant.length > 0;
  42. });
  43. var result = _.map(filteredResults, function (searchResult) {
  44. arrColumns = searchResult.proposal.metadataTreeViewFocus.significant;
  45. var score = searchResult['relevant score'];
  46. var type = 'uploadedFile';
  47. if (searchResult.type === 'databases') {
  48. type = 'module';
  49. } else if (searchResult.type === 'files') {
  50. //Handlder for baseModule from uploaded files
  51. if (searchResult.parentId && searchResult.parentId.length > 0) {
  52. type = 'uploadedFile';
  53. searchResult.id = searchResult.parentId;
  54. } else if (searchResult.href.indexOf('/base_modules') !== -1 && searchResult.href.indexOf('datasets:') === -1) {
  55. type = 'base_module';
  56. }
  57. }
  58. dataSet = {
  59. 'id': searchResult.id.indexOf('datasets:') === 0 ? searchResult.id.replace('datasets:', '') : searchResult.id,
  60. 'last-modified': searchResult.lastModified,
  61. 'name': searchResult.label,
  62. 'url': DBUtils.prototype.CONSTANTS.METADATA_ENDPOINT_PREFIX + searchResult.id + DBUtils.prototype.CONSTANTS.METADATA_ENDPOINT_POSTFIX,
  63. 'influential': searchResult.proposal.metadataTreeViewFocus.influential,
  64. 'significant': searchResult.proposal.metadataTreeViewFocus.significant,
  65. 'intent': searchResult.proposal.metadataTreeViewFocus.intent,
  66. 'type': type,
  67. 'score': _.isNumber(score) ? score : parseInt(score, 10)
  68. };
  69. return {
  70. 'columns': arrColumns,
  71. 'dataSet': dataSet
  72. };
  73. });
  74. return _.sortBy(result, function (o) {
  75. return o.dataSet.score;
  76. }).reverse();
  77. };
  78. /**
  79. * Given a datasetID (indentifier), return an object of a proposal
  80. *
  81. * @param moserResponse @type {array of Object}
  82. * @param datasetID @type {String}
  83. */
  84. DBUtils.prototype.findDataset = function (moserResponse, datasetID) {
  85. var results = _.find(moserResponse, function (item) {
  86. return item.identifier === datasetID;
  87. });
  88. return results;
  89. };
  90. /**
  91. * @param {Object} services, dashboard services
  92. * @return {Promise} that can retrieve the CA global configuration object
  93. * */
  94. DBUtils.prototype.getGlobalConfigByName = function (services, params) {
  95. return this.glassContext.getCoreSvc('.Ajax').ajax(params);
  96. };
  97. var _singleton = {
  98. getInstance: function getInstance() {
  99. if (!_instance) {
  100. _instance = new DBUtils();
  101. }
  102. return _instance;
  103. }
  104. };
  105. return _singleton.getInstance();
  106. });
  107. //# sourceMappingURL=DBUtils.js.map