SmartIT_Extensions/BMC/smart-it-full-helix/scripts/app/ticket/ticket-service.js

706 lines
34 KiB
JavaScript

"use strict";
(function () {
'use strict';
angular.module('ticketModule')
.service('ticketService', ['$resource', '$http', 'systemAlertService', '$q', 'slaCalculatorService', 'approvalService', '$filter', '$state',
function ($resource, $http, systemAlertService, $q, slaCalculatorService, approvalService, $filter, $state) {
var resource = $resource('', {}, {
assignTickets: { url: '/smartit/rest/bulkupdate/assignee/', method: 'POST', isArray: true },
bulkUpdate: { url: '/smartit/rest/v2/bulkupdate/all', method: 'POST', isArray: true },
getBasicInformation: { url: '/smartit/rest/:type/:id', method: 'GET', isArray: true },
getBasicInformation_v2: { url: '/smartit/rest/v2/:type/:id', method: 'GET', isArray: true },
getARMessageInformation: { url: '/smartit/rest/ticket/:type/:id', method: 'GET', isArray: true },
getAttachmentsInfo: { url: '/smartit/rest/attachment/info/:type/:id', method: 'GET', isArray: true },
updateStatus: { url: '/smartit/rest/:type/status/:id', method: 'PUT', isArray: false },
update: { url: '/smartit/rest/:type/all/:id', method: 'PUT', isArray: true },
update_v2: { url: '/smartit/rest/v2/:type/all/:id', method: 'PUT', isArray: true },
getDraft: { url: '/smartit/rest/:type/draft', method: 'GET', isArray: true },
getDraft_v2: { url: '/smartit/rest/v2/:type/draft', method: 'GET', isArray: true },
getDraft_v3: { url: '/smartit/rest/v3/:type/draft', method: 'GET', isArray: true },
getDraft_WO_v2: { url: '/smartit/rest/v2/workorder/draft', method: 'POST', isArray: true },
saveDraft: { url: '/smartit/rest/:type', method: 'POST', isArray: true },
saveDraft_v2: { url: '/smartit/rest/v2/:type', method: 'POST', isArray: true },
getPriority: { url: '/smartit/rest/:type/calculatepriority', method: 'GET', isArray: true },
getChangePriority: { url: '/smartit/rest/change/calculatepriority', method: 'GET', isArray: true },
getChangeRiskRules: { url: '/smartit/rest/change/config/changerules', method: 'GET', isArray: true },
getIncidentRules: { url: '/smartit/rest/incident/config/rules', method: 'GET', isArray: true },
getReleasePriority: { url: '/smartit/rest/release/calculatepriority', method: 'GET', isArray: true },
getReleaseRisk: { url: '/smartit/rest/release/:id/calculateRisk', method: 'GET', isArray: false },
getGroupMembers: {
url: '/smartit/rest/person/supportgrouppersons/:groupId?:params',
method: 'GET',
isArray: true
},
getSupportGroupPersons: {
url: '/smartit/rest/person/supportgrouppersons',
method: 'GET',
isArray: true
},
applyAction: { url: '/smartit/rest/:type/action/:action/:id', method: 'POST', isArray: true },
getAvailableStatuses: {
url: '/smartit/rest/:type/availablestatuses/:id',
method: 'GET',
isArray: true
},
getTaskPhases: { url: '/smartit/rest/change/taskphases', method: 'GET', isArray: true },
getDraftForRelated: {
url: '/smartit/rest/ticket/create/:type/from/:fromType/:id',
method: 'POST',
isArray: true
},
getRelatedDraftFromAsset: {
url: '/smartit/rest/ticket/create/:type/from/asset',
method: 'POST',
isArray: true
},
saveImpactedAreas: {
method: 'POST',
isArray: false,
url: '/smartit/rest/impactedarea/:type/:id'
},
getRootCause: {
method: 'GET',
isArray: true,
url: '/smartit/rest/category/problem/rootcause/rootcauseList'
},
getImpactAnalysis: {
method: 'GET',
isArray: true,
url: '/smartit/rest/asset/impact/:type/:id?returnRelationships=true'
},
getImpactAnalysisMock: {
method: 'GET',
isArray: true,
url: 'mocks/impact-analysis-large.json'
},
getImpactAnalysisStatus: {
method: 'GET',
isArray: true,
url: '/smartit/rest/asset/impactjob/:type/:id'
},
impactAnalysisAction: {
method: 'POST',
isArray: true,
url: '/smartit/rest/asset/impactjob/:type/:id'
},
getAssigneeSupportGroupPersons: {
url: '/smartit/rest/person/assignment/supportgrouppersons',
method: 'POST',
isArray: true
},
getRecentlyUsedChangeTemplates: {
url: '/smartit/rest/change/recentTemplate',
method: 'POST',
isArray: true
},
getRecentlyUsedReleaseTemplates: {
url: '/smartit/rest/release/recentTemplate',
method: 'POST',
isArray: true
},
getURLforTaskFlow: {
url: '/smartit/rest/task/taskFlowURL/:id',
method: 'POST',
isArray: false,
responseType: 'text',
transformResponse: function (data) {
var flowURL = data;
data = {};
data.url = flowURL;
return data;
}
},
getVendorInfo: {
url: '/smartit/rest/mcsm/:type/remedy/:displayId',
// url: 'mocks/mcsm.json',
method: 'GET',
isArray: false
},
copyChange: {
url: '/smartit/rest/ticket/create/change/from/change/:ticketId',
method: 'POST',
isArray: true
},
getGUIDByDisplayID: {
url: '/smartit/rest/:type/displayid/:id',
method: 'GET',
isArray: true
}
});
function _encodeObjectValues(object) {
_.forEach(object, function (value, key) {
if (_.isString(value)) {
object[key] = encodeURIComponent(value);
}
else if (_.isObject(value)) {
_encodeObjectValues(value);
}
});
}
this.assignTickets = function (props) {
return resource.assignTickets(props).$promise;
};
function showNotesAndWarning(messageInfos) {
_.forEach(messageInfos, function (messageInfo) {
if (messageInfo.type === "Note") {
systemAlertService.info({
text: messageInfo.message,
hide: 15000
});
}
else if (messageInfo.type === "Warning") {
systemAlertService.warning({
text: messageInfo.message,
hide: 15000
});
}
});
}
this.getARMessageInformation = function (id, type) {
return resource.getARMessageInformation({ id: id, type: type }).$promise.then(function (response) {
showNotesAndWarning(response[0].items[0]);
});
};
this.getBasicInformation = function (id, type) {
var fn = type === EntityVO.TYPE_INCIDENT ? resource.getBasicInformation_v2 : resource.getBasicInformation;
return fn({ id: id, type: type }).$promise.then(function (response) {
var ticket = transformResponse(type, response[0].items[0]);
ticket.syncTime = response[0].syncTime;
return ticket;
});
};
this.getDraft = function (type, templateId, summary, companyName, customer) {
var fn = type === EntityVO.TYPE_INCIDENT ? resource.getDraft_v3 : resource.getDraft;
var params = { type: type };
if (templateId) {
params.templateId = templateId;
}
if (summary) {
params.draftSummary = summary;
}
if (companyName) {
params.companyName = companyName;
}
if (customer) {
params.customerId = customer.loginId;
}
return fn(params).$promise.then(function (response) {
return transformResponse(type, response[0].items[0]);
});
};
this.getDraftWorkOrder = function (type, templateId, summary, data) {
//SW00525630 check for WO case only
var fn = resource.getDraft_WO_v2;
var params = { type: type };
if (templateId) {
params.templateId = templateId;
}
if (summary) {
params.summary = summary;
}
if (data) {
if (data.contact) {
params.contact = data.contact;
}
if (data.customer) {
params.customer = data.customer;
}
if (data.template) {
params.templateName = data.template.name;
}
}
return fn(params).$promise.then(function (response) {
return transformResponse(type, response[0].items[0]);
});
};
function transformResponse(type, response) {
var dataObject = response;
if (type === EntityVO.TYPE_TASK) {
dataObject = new TaskVO().build(dataObject);
}
else if (type === EntityVO.TYPE_INCIDENT) {
dataObject = new IncidentVO().build(dataObject);
}
else if (type === EntityVO.TYPE_WORKORDER) {
dataObject = new WorkOrderVO().build(dataObject);
}
else if (type === EntityVO.TYPE_SERVICEREQUEST) {
dataObject = new ServiceRequestVO().build(dataObject);
approvalService.getApprovals(dataObject);
}
else if (type === EntityVO.TYPE_SBEREQUEST) {
dataObject = new SbeRequestVO().build(dataObject);
}
else if (type === EntityVO.TYPE_OUTAGE) {
dataObject = new OutageVO().build(dataObject);
}
else if (type === EntityVO.TYPE_CHANGE) {
dataObject = new ChangeVO().build(dataObject);
}
else if (type === EntityVO.TYPE_RELEASE) {
dataObject = new ReleaseVO().build(dataObject);
}
else if (type === EntityVO.TYPE_ACTIVITY) {
dataObject = new ActivityVO().build(dataObject);
}
else if (type === EntityVO.TYPE_KNOWNERROR) {
dataObject = new KnownErrorVO().build(dataObject);
}
else if (type === EntityVO.TYPE_PROBLEM) {
dataObject = new ProblemVO().build(dataObject);
}
else if (type === EntityVO.TYPE_KNOWLEDGE) {
dataObject = new KnowledgeArticleVO().build(dataObject);
}
else if (type === EntityVO.TYPE_DLP) {
dataObject = new DLPVO().build(dataObject);
}
if (dataObject.status && dataObject.serviceTargets && dataObject.serviceTargets.length > 0) {
slaCalculatorService.processServiceTarget(dataObject, dataObject.serviceTargets);
}
return dataObject;
}
this.getAttachmentsInfo = function (id, type) {
return resource.getAttachmentsInfo({ id: id, type: type }).$promise
.then(function (responce) {
if (responce[0].items.length) {
return responce[0].items;
}
return [];
});
};
this.updateStatus = function (ids, statusData) {
return resource.bulkUpdate({
ids: ids,
attributeValueMap: statusData
}).$promise.then(function (response) {
var transFormedResponse = [];
for (var i = 0; i < ids.length; i++) {
var statusInfo = response[0].items[i].statusInfo;
if (statusInfo && statusInfo.type === 'Warning') {
systemAlertService.warning({
text: statusInfo.message,
hide: 10000
});
}
if (statusInfo && statusInfo.type === 'Failure') {
systemAlertService.error({
text: statusInfo.message,
clear: false
});
}
else {
transFormedResponse.push(transformResponse(ids[i].type, response[0].items[i].responseObject));
}
}
if (transFormedResponse.length === 0) {
throw "";
}
return transFormedResponse;
});
};
this.update = function (id, type, data, doNotShowErrorMsg) {
var fn = type === EntityVO.TYPE_INCIDENT ? resource.update_v2 : resource.update;
return fn({ id: id, type: type }, data).$promise.then(function (result) {
if (result[0].items[0].statusInfo && result[0].items[0].statusInfo.type === 'Warning' && result[0].items[0].statusInfo.number !== 3000) {
systemAlertService.warning({
text: result[0].items[0].statusInfo.message
});
if (result[0].items[0].responseObject) {
return transformResponse(type, result[0].items[0].responseObject);
}
}
else if (result[0].items[0].responseObject) {
return transformResponse(type, result[0].items[0].responseObject);
}
else if (result[0].items[0].statusInfo && result[0].items[0].statusInfo.number === 3000) {
systemAlertService.modal({
title: $filter('i18n')('common.notification.dirty.title'),
text: result[0].items[0].statusInfo.message,
type: 'warning',
buttons: [
{
text: $filter('i18n')('common.button.continue')
}
]
}).result.then(function () {
$state.go('dashboard');
});
}
return {};
}).catch(function (err) {
//Added this flag doNotShowErrorMsg, as we do not want to display the error message as part of this defect fix SW00559519.
if (!doNotShowErrorMsg) {
systemAlertService.error({
text: err.data.error,
clear: false
});
}
return $q.reject(err);
});
};
this.editHeader = function (id, type, headerData) {
return this.update(id, type, headerData);
};
this.editCustomerCard = function (id, type, data) {
return this.update(id, type, data);
};
this.saveDraft = function (type, params) {
var fn = type === EntityVO.TYPE_INCIDENT ? resource.saveDraft_v2 : resource.saveDraft;
return fn({ type: type }, params).$promise.then(function (result) {
return result[0].items[0];
});
};
this.saveQuickTicketDraft = function (type, params) {
var fn = type === EntityVO.TYPE_INCIDENT ? resource.saveDraft_v2 : resource.saveDraft;
var criteria = { quickCreateMode: true };
return fn({ type: type, criteria: criteria }, params).$promise.then(function (result) {
return result[0].items[0];
});
};
this.getPriority = function (companyName, impact, urgency, type) {
return resource.getPriority({
type: type,
companyName: companyName,
impact: impact,
urgency: urgency
}).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.getChangePriority = function (companyName, impact, urgency) {
return resource.getChangePriority({
companyName: companyName,
impact: impact,
urgency: urgency
}).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.getChangeRiskRules = function (companyName) {
//change company name variable
return resource.getChangeRiskRules({
companyName: companyName
}).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.getIncidentRules = function (companyName) {
//change company name variable
return resource.getIncidentRules({
companyName: companyName
}).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.getReleasePriority = function (companyName, impact, urgency) {
return resource.getReleasePriority({
companyName: companyName,
impact: impact,
urgency: urgency
}).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.getReleaseRisk = function (releaseId) {
return resource.getReleaseRisk({ id: releaseId }).$promise.then(function (response) {
return response;
});
};
this.getGroupMembers = function (id, params) {
return resource.getGroupMembers({
groupId: id,
params: params,
thumbnail: true
}).$promise.then(function (result) {
return handleSupportGroupPersons(result[0].items[0].objects, true);
});
};
this.getAssigneeSupportGroupPersons = function (company, organization, personName, personLoginId, role, chunkSize, customerCompany, locationCompany, ownerCompany, primaryCompany, authorCompany, available, fromBlade) {
var inputParams = {
companyName: company
}, urlParams = {};
//inputParams.thumbnail = true; //to be enabled when thumbnail is supported
if (organization) {
inputParams.organization = organization;
}
if (personName) {
urlParams.searchText = personName;
}
if (personLoginId) {
inputParams.personLoginId = decodeURIComponent(personLoginId);
}
if (role) {
inputParams.role = role;
}
if (chunkSize) {
urlParams.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
}
if (customerCompany) {
inputParams.customerCompany = customerCompany;
}
if (locationCompany) {
inputParams.locationCompany = locationCompany;
}
if (angular.isDefined(ownerCompany)) {
inputParams.ownerCompany = ownerCompany;
}
if (primaryCompany) {
inputParams.primaryCompany = primaryCompany;
}
if (authorCompany) {
inputParams.authorCompany = authorCompany;
}
inputParams.available = available;
return resource.getAssigneeSupportGroupPersons(urlParams, inputParams).$promise
.then(function (result) {
if (!_.isUndefined(fromBlade) && fromBlade) {
return handleSupportGroupPersonsForBlade(result[0].items[0].objects, result[0].items[0].totalMatches, result[0].items[0].exceedsChunkSize);
}
return handleSupportGroupPersons(result[0].items[0].objects, result[0].items[0].exceedsChunkSize);
});
};
this.getPersonsBySupportCompanyAndOrg = function (company, organization, personName, role, chunkSize, customerCompany, locationCompany, ownerCompany, primaryCompany, fromBlade) {
var inputParams = {
companyName: company,
thumbnail: true
};
if (organization) {
inputParams.organization = organization;
}
if (personName) {
inputParams.personText = personName;
}
if (role) {
inputParams.role = role;
}
if (chunkSize) {
inputParams.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
}
if (customerCompany) {
inputParams.customerCompany = customerCompany;
}
if (locationCompany) {
inputParams.locationCompany = locationCompany;
}
if (angular.isDefined(ownerCompany)) {
inputParams.ownerCompany = ownerCompany;
}
if (primaryCompany) {
inputParams.primaryCompany = primaryCompany;
}
return resource.getSupportGroupPersons(inputParams).$promise
.then(function (result) {
if (!_.isUndefined(fromBlade) && fromBlade) {
return handleSupportGroupPersonsForBlade(result[0].items[0].objects, result[0].items[0].totalMatches, result[0].items[0].exceedsChunkSize);
}
else {
return handleSupportGroupPersons(result[0].items[0].objects, result[0].items[0].exceedsChunkSize);
}
});
};
this.getAssigneeBySupportGroupId = function (supportGroupId, personName, personLoginId, customerCompany, role, chunkSize, available, primaryCompany, locationCompany, ownerCompany, authorCompany, fromBlade) {
var inputParams = {
supportGroupId: supportGroupId
}, urlParams = {};
//inputParams.thumbnail = true //to be enabled when thumbnail is supported
if (personName) {
urlParams.searchText = personName;
}
if (personLoginId) {
inputParams.personLoginId = personLoginId;
}
if (customerCompany) {
inputParams.customerCompany = customerCompany;
}
if (locationCompany) {
inputParams.locationCompany = locationCompany;
}
if (angular.isDefined(ownerCompany)) {
inputParams.ownerCompany = ownerCompany;
}
if (angular.isDefined(authorCompany)) {
inputParams.authorCompany = authorCompany;
}
if (role) {
inputParams.role = role;
}
if (chunkSize) {
urlParams.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
}
if (primaryCompany) {
inputParams.primaryCompany = primaryCompany;
}
inputParams.available = available;
return resource.getAssigneeSupportGroupPersons(urlParams, inputParams).$promise
.then(function (result) {
if (!_.isUndefined(fromBlade) && fromBlade) {
return handleSupportGroupPersonsForBlade(result[0].items[0].objects, result[0].items[0].totalMatches, result[0].items[0].exceedsChunkSize);
}
return handleSupportGroupPersons(result[0].items[0].objects, result[0].items[0].exceedsChunkSize);
});
};
this.getPersonsBySupportGroupId = function (supportGroupId, personName, role, chunkSize, fromBlade) {
var inputParams = {
supportGroupId: supportGroupId,
thumbnail: true
};
if (personName) {
inputParams.personText = personName;
}
if (role) {
inputParams.role = role;
}
if (chunkSize) {
inputParams.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
}
return resource.getSupportGroupPersons(inputParams).$promise
.then(function (result) {
if (!_.isUndefined(fromBlade) && fromBlade) {
return handleSupportGroupPersonsForBlade(result[0].items[0].objects, result[0].items[0].totalMatches, result[0].items[0].exceedsChunkSize);
}
return handleSupportGroupPersons(result[0].items[0].objects, result[0].items[0].exceedsChunkSize);
});
};
function handleSupportGroupPersonsForBlade(result, totalMatches, exceedsChunkSize) {
var supportPersonList = result.map(function (person) {
return new PersonVO().build(person);
});
var results;
results = _.uniqBy(supportPersonList, function (supportPerson) {
return supportPerson.loginId + '*' + supportPerson.supportGroupId;
});
var searchResult = {};
searchResult.results = results;
searchResult.totalMatches = totalMatches;
searchResult.exceedsChunkSize = exceedsChunkSize;
return searchResult;
}
function handleSupportGroupPersons(result, exceedsChunkSize) {
var supportPersonList = result.map(function (person) {
return new PersonVO().build(person);
});
var results;
results = _.uniqBy(supportPersonList, function (supportPerson) {
return supportPerson.loginId + '*' + supportPerson.supportGroupId;
});
var searchResult = {};
searchResult.results = results;
searchResult.exceedsChunkSize = exceedsChunkSize;
return searchResult;
}
this.applyAction = function (id, type, action, data) {
return resource.applyAction({ id: id, type: type, action: action }, data).$promise;
};
this.getAvailableStatuses = function (id, type) {
return resource.getAvailableStatuses({ id: id, type: type }).$promise.then(function (response) {
return response[0].items || [];
});
};
this.getTaskPhases = function (params) {
return resource.getTaskPhases(params).$promise
.then(function (response) {
return response[0].items;
});
};
this.getDraftForRelated = function (type, fromType, id, templateId) {
//passing empty data to POST call - for params to get replaced in the url
var params = {
id: id,
fromType: fromType,
type: type
};
if (templateId) {
params.templateId = templateId;
}
return resource.getDraftForRelated(params, {}).$promise.then(function (response) {
return transformResponse(type, response[0].items[0]);
});
};
this.getRelatedDraftFromAsset = function (type, asset, templateId) {
var params = {
type: type
};
if (templateId) {
params.templateId = templateId;
}
delete asset.accessMappings;
delete asset.allCategories;
delete asset.lifecycleDates;
return resource.getRelatedDraftFromAsset(params, asset).$promise.then(function (response) {
return transformResponse(type, response[0].items[0]);
});
};
this.saveImpactedAreas = function (id, type, params) {
return resource.saveImpactedAreas({ id: id, type: type }, params).$promise;
};
this.deleteImpactedAreas = function (id, type, params) {
return $http({
method: 'DELETE',
headers: { 'Content-Type': 'application/json' },
url: '/smartit/rest/impactedarea/' + type + '/' + id,
data: params
})
.catch(function (err) {
systemAlertService.error({
text: err.data && (err.data.defaultMessage || err.data.error),
clear: false
});
return $q.reject(err);
});
};
this.getRootCause = function (params) {
return resource
.getRootCause({ criteria: params })
.$promise.then(function (response) {
var rootCause = [];
for (var i = 0; i < response[0].items[0].length; i++) {
rootCause.push({
name: response[0].items[0][i],
label: response[0].items[0][i]
});
}
return rootCause;
});
};
this.getImpactAnalysisVisualisationData = function (type, id) {
return resource.getImpactAnalysis({ id: id, type: type }).$promise;
//return resource.getImpactAnalysisMock().$promise;
};
this.getImpactAnalysisStatus = function (id, type) {
return resource.getImpactAnalysisStatus({ id: id, type: type }).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.impactAnalysisAction = function (id, type, params) {
return resource.impactAnalysisAction({ id: id, type: type }, params).$promise.then(function (response) {
return response[0].items[0] || [];
});
};
this.getRecentlyUsedChangeTemplates = function (templateList) {
return resource.getRecentlyUsedChangeTemplates({ 'templateList': templateList }).$promise;
};
this.getRecentlyUsedReleaseTemplates = function (templateList) {
return resource.getRecentlyUsedReleaseTemplates({ 'templateList': templateList }).$promise;
};
this.getURLforTaskFlow = function (id, params) {
return resource.getURLforTaskFlow({ id: id }, params).$promise;
};
this.getVendorInfo = function (displayId, type) {
return resource.getVendorInfo({ displayId: displayId, type: type }).$promise.then(function (response) {
return response && response.tickets || [];
});
};
this.copyChange = function (ticketId, params) {
return resource.copyChange({ ticketId: ticketId }, params).$promise.then(function (response) {
return transformResponse('change', response[0].items[0]);
});
};
this.getGUIDByDisplayID = function (type, id) {
return resource.getGUIDByDisplayID({ type: type, id: id }).$promise.then(function (response) {
return response[0].items[0] && response[0].items[0].id || undefined;
});
};
}]);
}());