ApiSvc.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2015, 2021
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule
  7. * Contract with IBM Corp.
  8. */
  9. define(['jquery', 'underscore', 'q', 'bi/admin/common/services/ApiBase'], function ($, _, Q, ApiBase) {
  10. 'use strict'; //NOSONAR: meant to be strict
  11. var _singletonInstance = null;
  12. var ApiService = ApiBase.extend({
  13. useSearchService: true,
  14. AdvancedFilterItems: ['status', 'priority', 'objectClass', 'scheduleType'],
  15. ActivityType: {
  16. 'SCHEDULE': 'schedule',
  17. 'UPCOMING': 'upcoming',
  18. 'PAST': 'past',
  19. 'CURRENT': 'current',
  20. 'INTERACTIVE': 'interactive'
  21. },
  22. GroupBy: {
  23. 'HOUR': 'hour',
  24. 'DAY': 'day',
  25. 'WEEK': 'week'
  26. },
  27. Status: {
  28. schedule: ['enabled', 'disabled'],
  29. upcoming: ['scheduled', 'cancelled', 'suspended'],
  30. current: ['inactive', 'pending', 'executing', 'suspended'],
  31. past: ['succeeded', 'failed', 'terminated', 'purged'],
  32. interactive: ['executing', 'pending']
  33. },
  34. ScheduleObjectClasses: ['interactiveReport', 'agentDefinition', 'agentDefinitionView', 'analysis', 'contentTask', 'dataMovementTask', 'dataMovementTaskAlias', 'exportDeployment', 'importDeployment', 'indexUpdateTask', 'jobDefinition', 'migrationTask', 'jupyterNotebook', 'planningMacroTask', 'planningTask', 'powerPlay8Report', 'powerPlay8ReportView', 'query', 'queryServiceTask', 'report', 'reportView', 'dashboard'],
  35. SchedulePriorities: ['1', '2', '3', '4', '5'],
  36. SchedulePriority: {
  37. '1': '1',
  38. '2': '2',
  39. '3': '3',
  40. '4': '4',
  41. '5': '5'
  42. },
  43. defaultPageSize: 1000,
  44. _getActivityPostData: function _getActivityPostData(type, filters, sortOrder, pageSize) {
  45. type = type || this.ActivityType.SCHEDULE;
  46. filters = filters || {};
  47. pageSize = pageSize || this.defaultPageSize;
  48. var typeCode = type;
  49. if (!this.useSearchService) {
  50. switch (type) {
  51. case this.ActivityType.PAST:
  52. typeCode = 'past_cm';
  53. break;
  54. case this.ActivityType.SCHEDULE:
  55. typeCode = 'schedule_cm';
  56. break;
  57. }
  58. }
  59. var data = {
  60. type: typeCode,
  61. filters: filters,
  62. pageSize: pageSize
  63. };
  64. switch (type) {
  65. case this.ActivityType.UPCOMING:
  66. data.sort = {
  67. order: 'ascending',
  68. sortItem: 'startTime'
  69. };
  70. if (_.has(filters, 'startTime') && _.has(filters, 'endTime')) {
  71. data.summary = _.clone(filters);
  72. data.summary.groupBy = this.GroupBy.HOUR;
  73. }
  74. break;
  75. case this.ActivityType.CURRENT:
  76. data.sort = {
  77. order: 'ascending',
  78. sortItem: 'startTime'
  79. };
  80. break;
  81. }
  82. return data;
  83. },
  84. _bumpTestData: function _bumpTestData(type, filters) {
  85. var deferred = Q.defer();
  86. var layerNames = [];
  87. if (type === this.ActivityType.UPCOMING) {
  88. layerNames = ['scheduled', 'suspended', 'cancelled'];
  89. }
  90. if (type === this.ActivityType.PAST) {
  91. layerNames = ['succeeded', 'failed', 'cancelled'];
  92. }
  93. var hours = [];
  94. var t = new Date(filters.startTime);
  95. while (t < filters.endTime) {
  96. hours.push(t.toISOString());
  97. t = new Date(t.getTime() + 60 * 60 * 1000);
  98. }
  99. var result = {
  100. data: _.map(layerNames, function (ln) {
  101. var total = 0;
  102. var value = _.map(hours, function (h) {
  103. var num = Math.round(Math.random() * 20) + 1;
  104. total += num;
  105. return {
  106. use: h,
  107. display: num
  108. };
  109. });
  110. return {
  111. total: total,
  112. name: ln,
  113. value: value
  114. };
  115. })
  116. };
  117. deferred.resolve(result);
  118. return deferred.promise;
  119. },
  120. _getSessionPostData: function _getSessionPostData(session, type, secondaryRequest) {
  121. var data = _.pick(session, 'primaryRequest', 'tracking');
  122. data.type = type;
  123. data.secondaryRequest = secondaryRequest;
  124. return data;
  125. },
  126. getActivitySummary: function getActivitySummary(type, filters) {
  127. var data = this._getActivityPostData(type, filters);
  128. var resourceName = type === this.ActivityType.SCHEDULE ? 'activity_schedule_summary' : 'activity_summary';
  129. return this._ajax(resourceName, this._getRestOptions('POST', data));
  130. },
  131. getActivities: function getActivities(type, filters, sortOrder, pageSize) {
  132. var data;
  133. if (_.has(filters, 'tracking')) {
  134. data = this._getSessionPostData(filter, type, 'nextPage');
  135. } else {
  136. data = this._getActivityPostData(type, filters, sortOrder, pageSize);
  137. }
  138. var resourceName = type === this.ActivityType.SCHEDULE ? 'activity_schedules' : 'activities';
  139. return this._ajax(resourceName, this._getRestOptions('POST', data));
  140. },
  141. updateScheduleCredentials: function updateScheduleCredentials(scheduleId, credential) {
  142. var data = {
  143. 'properties': {
  144. 'type': 'schedule',
  145. 'credential': [{
  146. 'searchPath': credential.searchPath,
  147. 'type': credential.type
  148. }]
  149. }
  150. };
  151. var path = 'expressbus/content-manager/' + scheduleId;
  152. return this._ajax(path, this._getRestOptions('PUT', data));
  153. },
  154. updateScheduleStatus: function updateScheduleStatus(scheduleId, status) {
  155. var data = {
  156. 'active': status,
  157. 'type': 'schedule'
  158. };
  159. var path = 'objects/' + scheduleId;
  160. return this._ajax(path, this._getRestOptions('PUT', data));
  161. },
  162. updateSchedulePriority: function updateSchedulePriority(scheduleId, priority) {
  163. var data = {
  164. 'priority': priority,
  165. 'type': 'schedule'
  166. };
  167. var path = 'objects/' + scheduleId;
  168. return this._ajax(path, this._getRestOptions('PUT', data));
  169. },
  170. // supports current and upcoming activities
  171. updateUpcomingActivityPriority: function updateUpcomingActivityPriority(eventId, priority, activityType) {
  172. var path = 'activities';
  173. var data = {
  174. status: activityType,
  175. activities: [{
  176. eventID: eventId,
  177. priority: priority
  178. }]
  179. };
  180. return this._ajax(path, this._getRestOptions('PUT', data));
  181. },
  182. suspendSchedule: function suspendSchedule(type, eventIds) {
  183. var data = {
  184. type: type,
  185. activities: eventIds
  186. };
  187. return this._ajax('activities/suspend', this._getRestOptions('POST', data));
  188. },
  189. releaseSchedule: function releaseSchedule(type, eventIds) {
  190. var data = {
  191. type: type,
  192. activities: eventIds
  193. };
  194. return this._ajax('activities/release', this._getRestOptions('POST', data));
  195. },
  196. deleteSchedule: function deleteSchedule(scheduleId) {
  197. var path = 'objects/' + scheduleId;
  198. return this._ajax(path, this._getRestOptions('DELETE'));
  199. },
  200. releaseRequest: function releaseRequest(activityType, session) {
  201. var path = 'activities';
  202. var data = {
  203. "type": activityType,
  204. "secondaryRequest": "release",
  205. "primaryRequest": session.primaryRequest,
  206. "tracking": session.tracking
  207. };
  208. return this._ajax(path, this._getRestOptions('POST', data));
  209. },
  210. getDispatcherNameMap: function getDispatcherNameMap() {
  211. var path = 'search/cm?filter=type%7Cconfiguration&hide_internal=none';
  212. var self = this;
  213. var deferred = $.Deferred();
  214. this._ajax(path, this._getRestOptions('GET')).then(function (data) {
  215. var id = data && data.results[0] && data.results[0].id;
  216. if (id !== undefined) {
  217. path = 'objects/' + id + '/items?fields=defaultName%2CdispatcherID&types=dispatcher';
  218. self._ajax(path, self._getRestOptions('GET')).then(function (data) {
  219. var map = {};
  220. data.data.forEach(function (item) {
  221. map[item.dispatcherID] = item.defaultName;
  222. });
  223. deferred.resolve(map);
  224. });
  225. }
  226. });
  227. return deferred.promise();
  228. },
  229. cancelActivity: function cancelActivity(type, eventIds) {
  230. var data = {
  231. type: type,
  232. activities: eventIds
  233. };
  234. return this._ajax('activities/cancel', this._getRestOptions('POST', data));
  235. }
  236. });
  237. var _static = {
  238. getInstance: function getInstance() {
  239. if (!_singletonInstance) {
  240. _singletonInstance = new ApiService();
  241. }
  242. return _singletonInstance;
  243. }
  244. };
  245. return _static.getInstance();
  246. });