SmartsService.js 2.9 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: BI Cloud (C) Copyright IBM Corp. 2018, 2019
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. */
  10. define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../widgets/livewidget/query/ServiceBase', './api/SmartsServiceAPI', 'underscore'], function (APIFactory, ServiceBase, SmartsServiceAPI, _) {
  11. 'use strict';
  12. var SmartsService = function (_ServiceBase) {
  13. _inherits(SmartsService, _ServiceBase);
  14. function SmartsService(options) {
  15. _classCallCheck(this, SmartsService);
  16. var _this = _possibleConstructorReturn(this, _ServiceBase.call(this));
  17. _this.ajaxSvc = options.features['API'].getGlassCoreSvc('.Ajax');
  18. _this.logger = options.features['API'].getGlassCoreSvc('.Logger');
  19. return _this;
  20. }
  21. SmartsService.prototype.getAPI = function getAPI() {
  22. return APIFactory.createAPI(this, [SmartsServiceAPI]);
  23. };
  24. SmartsService.prototype.runQuery = function runQuery(options) {
  25. return this._runQuery(options);
  26. };
  27. /**
  28. * @public api to excute query against Smart service.
  29. *
  30. * @param {Object} options.querySpec Mandatory: the query specification to be sent to annotation service
  31. * @returns a promise.
  32. */
  33. SmartsService.prototype._runQuery = function _runQuery(options) {
  34. var _this2 = this;
  35. var requestId = this.getRequestId(options.sender);
  36. return new Promise(function (resolve, reject) {
  37. _this2.ajaxSvc.ajax({
  38. type: 'post',
  39. url: options.url,
  40. contentType: 'application/json',
  41. data: JSON.stringify(options.querySpec)
  42. }).then(function (data) {
  43. if (_this2.isActiveRequest(requestId, options.sender)) {
  44. resolve(data);
  45. } else {
  46. reject(_.extend(new Error(), {
  47. reason: 'staleRequest'
  48. }));
  49. }
  50. }, function (err) {
  51. reject(err);
  52. });
  53. });
  54. };
  55. return SmartsService;
  56. }(ServiceBase);
  57. return SmartsService;
  58. });
  59. //# sourceMappingURL=SmartsService.js.map