123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2021
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule
- * Contract with IBM Corp.
- */
- define(['jquery', 'underscore', 'q', 'bi/admin/common/services/ApiBase'], function ($, _, Q, ApiBase) {
- 'use strict'; //NOSONAR: meant to be strict
- var _singletonInstance = null;
- var ApiService = ApiBase.extend({
- useSearchService: true,
- AdvancedFilterItems: ['status', 'priority', 'objectClass', 'scheduleType'],
- ActivityType: {
- 'SCHEDULE': 'schedule',
- 'UPCOMING': 'upcoming',
- 'PAST': 'past',
- 'CURRENT': 'current',
- 'INTERACTIVE': 'interactive'
- },
- GroupBy: {
- 'HOUR': 'hour',
- 'DAY': 'day',
- 'WEEK': 'week'
- },
- Status: {
- schedule: ['enabled', 'disabled'],
- upcoming: ['scheduled', 'cancelled', 'suspended'],
- current: ['inactive', 'pending', 'executing', 'suspended'],
- past: ['succeeded', 'failed', 'terminated', 'purged'],
- interactive: ['executing', 'pending']
- },
- ScheduleObjectClasses: ['interactiveReport', 'agentDefinition', 'agentDefinitionView', 'analysis', 'contentTask', 'dataMovementTask', 'dataMovementTaskAlias', 'exportDeployment', 'importDeployment', 'indexUpdateTask', 'jobDefinition', 'migrationTask', 'jupyterNotebook', 'planningMacroTask', 'planningTask', 'powerPlay8Report', 'powerPlay8ReportView', 'query', 'queryServiceTask', 'report', 'reportView', 'dashboard'],
- SchedulePriorities: ['1', '2', '3', '4', '5'],
- SchedulePriority: {
- '1': '1',
- '2': '2',
- '3': '3',
- '4': '4',
- '5': '5'
- },
- defaultPageSize: 1000,
- _getActivityPostData: function _getActivityPostData(type, filters, sortOrder, pageSize) {
- type = type || this.ActivityType.SCHEDULE;
- filters = filters || {};
- pageSize = pageSize || this.defaultPageSize;
- var typeCode = type;
- if (!this.useSearchService) {
- switch (type) {
- case this.ActivityType.PAST:
- typeCode = 'past_cm';
- break;
- case this.ActivityType.SCHEDULE:
- typeCode = 'schedule_cm';
- break;
- }
- }
- var data = {
- type: typeCode,
- filters: filters,
- pageSize: pageSize
- };
- switch (type) {
- case this.ActivityType.UPCOMING:
- data.sort = {
- order: 'ascending',
- sortItem: 'startTime'
- };
- if (_.has(filters, 'startTime') && _.has(filters, 'endTime')) {
- data.summary = _.clone(filters);
- data.summary.groupBy = this.GroupBy.HOUR;
- }
- break;
- case this.ActivityType.CURRENT:
- data.sort = {
- order: 'ascending',
- sortItem: 'startTime'
- };
- break;
- }
- return data;
- },
- _bumpTestData: function _bumpTestData(type, filters) {
- var deferred = Q.defer();
- var layerNames = [];
- if (type === this.ActivityType.UPCOMING) {
- layerNames = ['scheduled', 'suspended', 'cancelled'];
- }
- if (type === this.ActivityType.PAST) {
- layerNames = ['succeeded', 'failed', 'cancelled'];
- }
- var hours = [];
- var t = new Date(filters.startTime);
- while (t < filters.endTime) {
- hours.push(t.toISOString());
- t = new Date(t.getTime() + 60 * 60 * 1000);
- }
- var result = {
- data: _.map(layerNames, function (ln) {
- var total = 0;
- var value = _.map(hours, function (h) {
- var num = Math.round(Math.random() * 20) + 1;
- total += num;
- return {
- use: h,
- display: num
- };
- });
- return {
- total: total,
- name: ln,
- value: value
- };
- })
- };
- deferred.resolve(result);
- return deferred.promise;
- },
- _getSessionPostData: function _getSessionPostData(session, type, secondaryRequest) {
- var data = _.pick(session, 'primaryRequest', 'tracking');
- data.type = type;
- data.secondaryRequest = secondaryRequest;
- return data;
- },
- getActivitySummary: function getActivitySummary(type, filters) {
- var data = this._getActivityPostData(type, filters);
- var resourceName = type === this.ActivityType.SCHEDULE ? 'activity_schedule_summary' : 'activity_summary';
- return this._ajax(resourceName, this._getRestOptions('POST', data));
- },
- getActivities: function getActivities(type, filters, sortOrder, pageSize) {
- var data;
- if (_.has(filters, 'tracking')) {
- data = this._getSessionPostData(filter, type, 'nextPage');
- } else {
- data = this._getActivityPostData(type, filters, sortOrder, pageSize);
- }
- var resourceName = type === this.ActivityType.SCHEDULE ? 'activity_schedules' : 'activities';
- return this._ajax(resourceName, this._getRestOptions('POST', data));
- },
- updateScheduleCredentials: function updateScheduleCredentials(scheduleId, credential) {
- var data = {
- 'properties': {
- 'type': 'schedule',
- 'credential': [{
- 'searchPath': credential.searchPath,
- 'type': credential.type
- }]
- }
- };
- var path = 'expressbus/content-manager/' + scheduleId;
- return this._ajax(path, this._getRestOptions('PUT', data));
- },
- updateScheduleStatus: function updateScheduleStatus(scheduleId, status) {
- var data = {
- 'active': status,
- 'type': 'schedule'
- };
- var path = 'objects/' + scheduleId;
- return this._ajax(path, this._getRestOptions('PUT', data));
- },
- updateSchedulePriority: function updateSchedulePriority(scheduleId, priority) {
- var data = {
- 'priority': priority,
- 'type': 'schedule'
- };
- var path = 'objects/' + scheduleId;
- return this._ajax(path, this._getRestOptions('PUT', data));
- },
- // supports current and upcoming activities
- updateUpcomingActivityPriority: function updateUpcomingActivityPriority(eventId, priority, activityType) {
- var path = 'activities';
- var data = {
- status: activityType,
- activities: [{
- eventID: eventId,
- priority: priority
- }]
- };
- return this._ajax(path, this._getRestOptions('PUT', data));
- },
- suspendSchedule: function suspendSchedule(type, eventIds) {
- var data = {
- type: type,
- activities: eventIds
- };
- return this._ajax('activities/suspend', this._getRestOptions('POST', data));
- },
- releaseSchedule: function releaseSchedule(type, eventIds) {
- var data = {
- type: type,
- activities: eventIds
- };
- return this._ajax('activities/release', this._getRestOptions('POST', data));
- },
- deleteSchedule: function deleteSchedule(scheduleId) {
- var path = 'objects/' + scheduleId;
- return this._ajax(path, this._getRestOptions('DELETE'));
- },
- releaseRequest: function releaseRequest(activityType, session) {
- var path = 'activities';
- var data = {
- "type": activityType,
- "secondaryRequest": "release",
- "primaryRequest": session.primaryRequest,
- "tracking": session.tracking
- };
- return this._ajax(path, this._getRestOptions('POST', data));
- },
- getDispatcherNameMap: function getDispatcherNameMap() {
- var path = 'search/cm?filter=type%7Cconfiguration&hide_internal=none';
- var self = this;
- var deferred = $.Deferred();
- this._ajax(path, this._getRestOptions('GET')).then(function (data) {
- var id = data && data.results[0] && data.results[0].id;
- if (id !== undefined) {
- path = 'objects/' + id + '/items?fields=defaultName%2CdispatcherID&types=dispatcher';
- self._ajax(path, self._getRestOptions('GET')).then(function (data) {
- var map = {};
- data.data.forEach(function (item) {
- map[item.dispatcherID] = item.defaultName;
- });
- deferred.resolve(map);
- });
- }
- });
- return deferred.promise();
- },
- cancelActivity: function cancelActivity(type, eventIds) {
- var data = {
- type: type,
- activities: eventIds
- };
- return this._ajax('activities/cancel', this._getRestOptions('POST', data));
- }
- });
- var _static = {
- getInstance: function getInstance() {
- if (!_singletonInstance) {
- _singletonInstance = new ApiService();
- }
- return _singletonInstance;
- }
- };
- return _static.getInstance();
- });
|