189 lines
9.0 KiB
JavaScript
189 lines
9.0 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by ygowtham on 6/16/2015.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('changeModule')
|
|
.factory('collisionModel', ['collisionService', '$q',
|
|
function (collisionService, $q) {
|
|
var collisionModel = {};
|
|
/**
|
|
* Added by ygowtham on 6/16/2015 (I1 - G1.3)
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionModel#getListOfCollisions
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the context
|
|
* @param {Object} context - Object that has information about the ticket/KA required in the request API.
|
|
*/
|
|
collisionModel.getListOfCollisionsById = function (context, includeCIDetails) {
|
|
/**
|
|
* @namespace
|
|
* @property {object} context - Collision Request parameters.
|
|
* @property {string} context.id - UUID of the ticket/change
|
|
* @property {boolean} includeCIDetails - Flag to include CI Details in response or not.
|
|
*/
|
|
var params = { id: context.id, includeCIDetails: includeCIDetails };
|
|
return collisionService.getListOfCollisionsById(params);
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionModel#getListOfCollisionsAndCiByDate
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the specified context and date interval
|
|
* @param {String} contextId - ticket id to exclude itself from the result.
|
|
* @param {Date} start - scheduled start date of the request interval.
|
|
* @param {Date} end - scheduled end date of the request interval.
|
|
* @param {Array} linkedCIs - list of CIs to run collision detection.
|
|
*/
|
|
collisionModel.getListOfCollisionsAndCiByDate = function (start, end, linkedCIs) {
|
|
var params = {
|
|
scheduledDateRange: {
|
|
start: start.getTime(),
|
|
end: end.getTime()
|
|
},
|
|
configurationItems: []
|
|
};
|
|
_.forEach(linkedCIs, function (item) {
|
|
params.configurationItems.push({
|
|
reconciliationId: item.id
|
|
});
|
|
});
|
|
return collisionService.getListOfCollisionsAndCiByDate(params);
|
|
};
|
|
collisionModel.changeCalendarCollisionGet = function (start, end, changeId, mode) {
|
|
var params = {
|
|
scheduledDateRange: {
|
|
start: start.getTime(),
|
|
end: end.getTime()
|
|
},
|
|
changeId: changeId,
|
|
mode: mode
|
|
};
|
|
return collisionService.getListOfCollisionsAndCiByDate(params);
|
|
};
|
|
collisionModel.changeCalendarGet = function (contextId, start, end, filters, mode) {
|
|
if (!start || !end) {
|
|
return $q.when({
|
|
changeRequests: [],
|
|
outages: []
|
|
});
|
|
}
|
|
var params = {
|
|
types: [
|
|
EntityVO.TYPE_BUSINESS_EVENT,
|
|
EntityVO.TYPE_CHANGE,
|
|
EntityVO.TYPE_OUTAGE
|
|
],
|
|
scheduledDateRange: {
|
|
start: start.getTime(),
|
|
end: end.getTime()
|
|
},
|
|
changeId: contextId,
|
|
mode: mode
|
|
}, filterCriteria;
|
|
filterCriteria = _.extend(params, filters);
|
|
return collisionService
|
|
.getListOfCollisionsByDate({ filterCriteria: filterCriteria })
|
|
.then(function (response) {
|
|
var data = response[0] && response[0].items && response[0].items[0] && response[0].items[0].objects, result = {};
|
|
result.changeRequests = data ? _.filter(data, { "type": EntityVO.TYPE_CHANGE }) : [];
|
|
result.changeRequests = _.filter(result.changeRequests, function (item) { return item.id != contextId; });
|
|
result.outages = data ? _.filter(data, { "type": EntityVO.TYPE_OUTAGE }) : [];
|
|
result.businessEvents = data ? _.filter(data, { "type": EntityVO.TYPE_BUSINESS_EVENT }) : [];
|
|
result.changeRequests = normalizeTimings(result.changeRequests);
|
|
result.outages = normalizeTimings(result.outages);
|
|
result.businessEvents = normalizeTimings(result.businessEvents);
|
|
return result;
|
|
});
|
|
};
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionModel#getListOfCollisionsByDate
|
|
*
|
|
* @description
|
|
* Retrieves collision information for the specified context and date interval
|
|
* @param {String} contextId - ticket id to exclude itself from the result.
|
|
* @param {Date} start - scheduled start date of the request interval.
|
|
* @param {Date} end - scheduled end date of the request interval.
|
|
* @param {Array} linkedCIs - list of CIs to run collision detection.
|
|
* @param {Array} filters - the set of filters that will be applied to the resulting collisions.
|
|
*/
|
|
collisionModel.getListOfCollisionsByDate = function (contextId, start, end, linkedCIs, filters) {
|
|
if (!start || !end) {
|
|
return $q.when({
|
|
changeRequests: [],
|
|
outages: []
|
|
});
|
|
}
|
|
var params = {
|
|
types: [
|
|
EntityVO.TYPE_BUSINESS_EVENT
|
|
],
|
|
scheduledDateRange: {
|
|
start: start.getTime(),
|
|
end: end.getTime()
|
|
},
|
|
configurationItems: []
|
|
};
|
|
if (linkedCIs && linkedCIs.length) {
|
|
params.types.push(EntityVO.TYPE_CHANGE);
|
|
params.types.push(EntityVO.TYPE_OUTAGE);
|
|
_.forEach(linkedCIs, function (item) {
|
|
params.configurationItems.push({
|
|
reconciliationId: item.id
|
|
});
|
|
});
|
|
}
|
|
var filterCriteria = _.extend(params, filters);
|
|
return collisionService
|
|
.getListOfCollisionsByDate({ filterCriteria: filterCriteria })
|
|
.then(function (response) {
|
|
var data = response[0] && response[0].items && response[0].items[0] && response[0].items[0].objects, result = {};
|
|
result.changeRequests = data ? _.filter(data, { "type": EntityVO.TYPE_CHANGE }) : [];
|
|
result.changeRequests = _.filter(result.changeRequests, function (item) { return item.id != contextId; });
|
|
result.outages = data ? _.filter(data, { "type": EntityVO.TYPE_OUTAGE }) : [];
|
|
result.businessEvents = data ? _.filter(data, { "type": EntityVO.TYPE_BUSINESS_EVENT }) : [];
|
|
result.changeRequests = normalizeTimings(result.changeRequests);
|
|
result.outages = normalizeTimings(result.outages);
|
|
result.businessEvents = normalizeTimings(result.businessEvents);
|
|
return result;
|
|
});
|
|
};
|
|
function normalizeTimings(events) {
|
|
var result = [];
|
|
_.forEach(events, function (event) {
|
|
_.forEach(event.timings, function (timing) {
|
|
var eventCopy = _.cloneDeep(event);
|
|
eventCopy.scheduledStartDate = timing.startDate;
|
|
eventCopy.scheduledEndDate = timing.endDate;
|
|
eventCopy.title = eventCopy.additionalInformation.timeSegmentDesc || eventCopy.title;
|
|
delete eventCopy.timings;
|
|
result.push(eventCopy);
|
|
});
|
|
});
|
|
return result;
|
|
}
|
|
/**
|
|
* @ngdoc method
|
|
* @name myitsmApp.collisionModel#addCollisionStatuses
|
|
*
|
|
* @description
|
|
* Updates collision statuses
|
|
* @param {String} collisionPayload - Collision statuses
|
|
*/
|
|
collisionModel.addCollisionStatuses = function (collisionPayload, id) {
|
|
/**
|
|
* @namespace
|
|
* @property {string} id - UUID of the ticket/change
|
|
*/
|
|
var params = collisionPayload;
|
|
return collisionService.addCollisionStatuses(params, id);
|
|
};
|
|
return collisionModel;
|
|
}
|
|
]);
|
|
})();
|