"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(); });