QueryService2.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. /**
  6. * Licensed Materials - Property of IBM
  7. * IBM Cognos Products: Dashboard
  8. * (C) Copyright IBM Corp. 2019, 2020
  9. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../widgets/livewidget/query/CommonQueryHelper', './QueryDefinition', './api/QueryService2API'], function (APIFactory, CommonQueryHelper, QueryDefinition, QueryServiceAPI2) {
  12. var QueryService2 = function (_CommonQueryHelper) {
  13. _inherits(QueryService2, _CommonQueryHelper);
  14. function QueryService2(options) {
  15. _classCallCheck(this, QueryService2);
  16. var internalQueryService = options.features['QueryService.internal'];
  17. var _this = _possibleConstructorReturn(this, _CommonQueryHelper.call(this, {
  18. queryService: internalQueryService
  19. }, options.features['Logger']));
  20. _this.dashboard = options.features['API'];
  21. _this.internalQueryService = internalQueryService;
  22. _this.queryClasses = {};
  23. return _this;
  24. }
  25. QueryService2.prototype.getAPI = function getAPI() {
  26. if (!this.queryServiceAPI) {
  27. this.queryServiceAPI = APIFactory.createAPI(this, [QueryServiceAPI2]);
  28. }
  29. return this.queryServiceAPI;
  30. };
  31. QueryService2.prototype.registerQueryClass = function registerQueryClass(queryProtocol, QueryClass) {
  32. if (this.queryClasses[queryProtocol]) {
  33. throw new Error('There is already a query class registered for ' + queryProtocol);
  34. }
  35. this.queryClasses[queryProtocol] = QueryClass;
  36. };
  37. QueryService2.prototype.createQueryDefinition = function createQueryDefinition(id, type) {
  38. return new QueryDefinition({ id: id, type: type }).getAPI();
  39. };
  40. QueryService2.prototype._getProtocol = function _getProtocol(definitionList) {
  41. var datasource = definitionList && definitionList.length > 0 ? definitionList[0].getDataSource() : null;
  42. return datasource && datasource.getProtocol();
  43. };
  44. QueryService2.prototype.createQuery = function createQuery(definitionList) {
  45. var queryProtocol = this._getProtocol(definitionList);
  46. var QueryClass = this.queryClasses[queryProtocol];
  47. if (QueryClass) {
  48. return new QueryClass({
  49. dashboard: this.dashboard,
  50. internalQueryService: this.internalQueryService,
  51. definitionList: definitionList
  52. });
  53. } else {
  54. throw new Error('Query class is not registered for ' + queryProtocol);
  55. }
  56. };
  57. return QueryService2;
  58. }(CommonQueryHelper);
  59. return QueryService2;
  60. });
  61. //# sourceMappingURL=QueryService2.js.map