352 lines
16 KiB
JavaScript
352 lines
16 KiB
JavaScript
"use strict";
|
|
(function () {
|
|
'use strict';
|
|
angular.module('assetModule')
|
|
.factory('assetModel', ['assetService', '$q', 'relationModel', 'screenConfigurationService', 'userModel',
|
|
function (assetService, $q, relationModel, screenConfigurationService, userModel) {
|
|
var assetModel = {
|
|
assetDetails: {},
|
|
assetOwner: {},
|
|
poiOwner: {},
|
|
assetId: {},
|
|
assetClassId: {},
|
|
assetPeopleRelations: {},
|
|
flattenRelations: {},
|
|
bcmFilteredActions: {},
|
|
cache: {}
|
|
};
|
|
/**
|
|
* Public functions
|
|
*/
|
|
/**
|
|
* Fetch asset details.
|
|
*
|
|
* @param {String} assetId
|
|
* @param {String} assetClassId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.getAssetDetailsByID = function (assetId, assetClassId) {
|
|
if (!_.isEmpty(assetModel.assetDetails) && (assetId === assetModel.assetDetails.reconciliationId) && (assetClassId === assetModel.assetDetails.classId)) {
|
|
return $q.when(assetModel.assetDetails);
|
|
}
|
|
return assetService.getAssetDetailsByID(assetId, assetClassId).then(function (data) {
|
|
assetModel.assetDetails = data;
|
|
assetModel.bcmFilteredActions = {
|
|
actions: {
|
|
ConfigSummary: true,
|
|
PerformAudit: true,
|
|
Ping: true,
|
|
Reboot: true,
|
|
Shutdown: true,
|
|
WakeUp: true
|
|
},
|
|
configLoaded: false
|
|
};
|
|
return assetModel.assetDetails;
|
|
});
|
|
};
|
|
/**
|
|
* Fetch asset primary contact.
|
|
*
|
|
* @param {String} assetId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.getPrimaryContact = function (assetId) {
|
|
var criteria = {
|
|
types: 'person',
|
|
criteria: {
|
|
primaryContact: true
|
|
}
|
|
};
|
|
return relationModel.getRelations(assetId, EntityVO.TYPE_ASSET, null, criteria).then(function (data) {
|
|
assetModel.assetPrimaryContact = _.find(data, function (person) {
|
|
return person.realObject.isPrimaryContact === 'Yes';
|
|
}) || {};
|
|
});
|
|
};
|
|
/**
|
|
* Fetch asset people relations.
|
|
*
|
|
* @param {String} assetId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.getPeopleRelations = function (assetId) {
|
|
return relationModel.getRelations(assetId, EntityVO.TYPE_ASSET).then(function (data) {
|
|
assetModel.assetPeopleRelations = _.chain(data)
|
|
.filter({ type: EntityVO.TYPE_PERSON })
|
|
.filter({ realObject: { isPrimaryContact: 'No' } })
|
|
.groupBy('relationshipType').value();
|
|
assetModel.assetPrimaryContact = _.find(data, function (person) {
|
|
return person.realObject.isPrimaryContact === 'Yes';
|
|
}) || {};
|
|
});
|
|
};
|
|
/**
|
|
* Fetch asset people relations.
|
|
*
|
|
* @param {String} assetId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.refreshPeopleRelations = function (assetId) {
|
|
return relationModel.refreshRelations(assetId, EntityVO.TYPE_ASSET).then(function (data) {
|
|
assetModel.assetPeopleRelations = _.chain(data)
|
|
.filter({ type: EntityVO.TYPE_PERSON })
|
|
.filter({ realObject: { isPrimaryContact: 'No' } })
|
|
.groupBy('relationshipType').value();
|
|
assetModel.assetPrimaryContact = _.find(data, function (person) {
|
|
return person.realObject.isPrimaryContact === 'Yes';
|
|
}) || {};
|
|
});
|
|
};
|
|
/**
|
|
* Fetch asset flatten relations.
|
|
*
|
|
* @param {String} assetId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.getFlattenRelations = function (assetId) {
|
|
return relationModel.getRelations(assetId, EntityVO.TYPE_ASSET).then(function (data) {
|
|
assetModel.flattenRelations = _.chain(data)
|
|
.filter({ type: EntityVO.TYPE_ASSET })
|
|
.filter({ relationshipClassId: 'BMC_HostedSystemComponents' })
|
|
.groupBy('realObject.classId').value();
|
|
//['BMC_PROCESSOR', 'BMC_OPERATINGSYSTEM', 'BMC_DISKDRIVE']
|
|
});
|
|
};
|
|
/**
|
|
* Fetch asset flatten relations.
|
|
*
|
|
* @param {String} assetId
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.refreshFlattenRelations = function (assetId) {
|
|
return relationModel.refreshRelations(assetId, EntityVO.TYPE_ASSET).then(function (data) {
|
|
assetModel.flattenRelations = _.chain(data)
|
|
.filter({ type: EntityVO.TYPE_ASSET })
|
|
.filter({ relationshipClassId: 'BMC_HostedSystemComponents' })
|
|
.groupBy('realObject.classId').value();
|
|
//['BMC_PROCESSOR', 'BMC_OPERATINGSYSTEM', 'BMC_DISKDRIVE']
|
|
});
|
|
};
|
|
assetModel.getAssetOwnerDetails = function (id) {
|
|
if (userModel.userId !== id) {
|
|
id = encodeURIComponent(id);
|
|
}
|
|
return assetService.getAssetOwnerDetails(id).then(function (data) {
|
|
assetModel.assetOwner = data;
|
|
});
|
|
};
|
|
assetModel.getPoiOwnerDetails = function (id) {
|
|
if (userModel.userId !== id) {
|
|
id = encodeURIComponent(id);
|
|
}
|
|
return assetService.getAssetOwnerDetails(id).then(function (data) {
|
|
assetModel.poiOwner = data;
|
|
});
|
|
};
|
|
assetModel.update = function (data) {
|
|
return assetService.update(assetModel.assetDetails.reconciliationId, assetModel.assetDetails.instanceId, assetModel.assetClassId, data).then(function (response) {
|
|
return _.head(response).items[0].responseObject;
|
|
});
|
|
};
|
|
assetModel.updateCacheAssetDetails = function (assetDetails) {
|
|
_.extend(assetModel.assetDetails, assetDetails);
|
|
assetModel.assetDetails.postBuild(); //call it again to do the mapping
|
|
if (_.isUndefined(assetDetails.manufacturer)) {
|
|
assetModel.assetDetails.manufacturer = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.floor)) {
|
|
assetModel.assetDetails.floor = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.invoiceNumber)) {
|
|
assetModel.assetDetails.invoiceNumber = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.partNumber)) {
|
|
assetModel.assetDetails.partNumber = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.serialNumber)) {
|
|
assetModel.assetDetails.serialNumber = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.supplier)) {
|
|
assetModel.assetDetails.supplier = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.systemRole)) {
|
|
assetModel.assetDetails.systemRole = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.room)) {
|
|
assetModel.assetDetails.room = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.impact)) {
|
|
assetModel.assetDetails.impact = null;
|
|
}
|
|
if (_.isUndefined(assetDetails.urgency)) {
|
|
assetModel.assetDetails.urgency = null;
|
|
}
|
|
if (!_.isUndefined(assetDetails.financials)) {
|
|
if (_.isUndefined(assetDetails.financial.costCenter)) {
|
|
assetModel.assetDetails.financial.costCenter = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.financial.budgetCode)) {
|
|
assetModel.assetDetails.financial.budgetCode = '';
|
|
}
|
|
if (_.isUndefined(assetDetails.financial.projectNumber)) {
|
|
assetModel.assetDetails.financial.projectNumber = '';
|
|
}
|
|
}
|
|
};
|
|
assetModel.addPeople = function (personData) {
|
|
return relationModel.addRelation({
|
|
uuid: assetModel.assetId,
|
|
type: EntityVO.TYPE_ASSET
|
|
}, [personData]);
|
|
};
|
|
assetModel.removePeople = function (people) {
|
|
return assetService.removePeople(people);
|
|
};
|
|
assetModel.followAsset = function (userLoginId, assetId) {
|
|
return assetService.followAsset(userLoginId, assetId);
|
|
};
|
|
assetModel.unfollowAsset = function (userLoginId, assetId) {
|
|
return assetService.unfollowAsset(userLoginId, assetId);
|
|
};
|
|
assetModel.searchInventory = function (data) {
|
|
return assetService.searchInventory(data);
|
|
};
|
|
assetModel.putIntoInventory = function (assetId, assetClassId, params) {
|
|
return assetService.putIntoInventory(assetId, assetClassId, params).then(function (response) {
|
|
return _.head(response).items[0];
|
|
});
|
|
};
|
|
assetModel.getRelationshipTypes = function (data) {
|
|
if (assetModel.cache[data.classId1] && assetModel.cache[data.classId1][data.classId2]) {
|
|
return $q.resolve(angular.copy(assetModel.cache[data.classId1][data.classId2]));
|
|
}
|
|
var promise = assetService.getRelationshipTypes(data).then(function (response) {
|
|
assetModel.cache[data.classId1] = assetModel.cache[data.classId1] ? assetModel.cache[data.classId1] : {};
|
|
assetModel.cache[data.classId1][data.classId2] = response;
|
|
return angular.copy(response);
|
|
});
|
|
return promise;
|
|
};
|
|
assetModel.addBulkRelations = function (data) {
|
|
return assetService.addBulkRelations(data);
|
|
};
|
|
assetModel.bulkUpdateRelateAsset = function (data) {
|
|
return assetService.bulkUpdateRelateAsset(data);
|
|
};
|
|
/**
|
|
* Fetch asset costcenter list by search text.
|
|
*
|
|
* @param {String} search text
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.getCostCentersByCompanyName = function (text, company) {
|
|
return screenConfigurationService.loadDynamicSelectionFieldLabels({
|
|
datasource: 'asset',
|
|
menuName: 'SHR:CostCenterAllForCompany',
|
|
searchText: text
|
|
}, { companyName: company });
|
|
};
|
|
/**
|
|
* Fetch asset costcenter list by search text.
|
|
*
|
|
* @param {String} search text
|
|
* @returns {*} HTTP request promise
|
|
*/
|
|
assetModel.getCapabilityListByName = function (text, chunkSize) {
|
|
var data = {
|
|
datasource: 'asset',
|
|
menuName: 'SHR:SDF:AST-Capabilities',
|
|
searchText: text
|
|
};
|
|
if (chunkSize) {
|
|
data.chunkInfo = { startIndex: 0, chunkSize: chunkSize };
|
|
}
|
|
return screenConfigurationService.loadDynamicSelectionFieldLabels(data, {});
|
|
};
|
|
/**
|
|
* Fetch details from BCM
|
|
*
|
|
*/
|
|
assetModel.getBcmFilteredActions = function () {
|
|
return assetModel.bcmFilteredActions;
|
|
};
|
|
assetModel.getBcmFilteredActionsFromServer = function () {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
if (assetModel.bcmFilteredActions.configLoaded) {
|
|
return $q.when(assetModel.bcmFilteredActions);
|
|
}
|
|
else {
|
|
var prom = assetService.getBcmFilteredActions(deviceId).then(function (data) {
|
|
assetModel.bcmFilteredActions = {
|
|
actions: data,
|
|
configLoaded: true
|
|
};
|
|
return assetModel.bcmFilteredActions;
|
|
});
|
|
prom.catch(function () {
|
|
assetModel.bcmFilteredActions = {
|
|
actions: {
|
|
ConfigSummary: false,
|
|
PerformAudit: false,
|
|
Ping: false,
|
|
Reboot: false,
|
|
Shutdown: false,
|
|
WakeUp: false
|
|
},
|
|
configLoaded: true
|
|
};
|
|
});
|
|
return prom;
|
|
}
|
|
};
|
|
assetModel.getBcmAssetGeneralData = function () {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
return assetService.getBcmAssetGeneralData(deviceId);
|
|
};
|
|
assetModel.getBcmAssetHardwareData = function () {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
return assetService.getBcmAssetHardwareData(deviceId);
|
|
};
|
|
assetModel.getBcmAssetSoftwareData = function (offset) {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
return assetService.getBcmAssetSoftwareData(deviceId, offset);
|
|
};
|
|
assetModel.getBcmAssetFinancialData = function () {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
return assetService.getBcmAssetFinancialData(deviceId);
|
|
};
|
|
assetModel.getBcmAssetSecurityData = function () {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
return assetService.getBcmAssetSecurityData(deviceId);
|
|
};
|
|
assetModel.getBcmAssetActionHistory = function (offset) {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId;
|
|
return assetService.getBcmAssetActionHistory(deviceId, offset);
|
|
};
|
|
assetModel.performBCMAction = function (action) {
|
|
var deviceId = assetModel.assetDetails.bcmDeviceId, actionPromise, reconId = assetModel.assetDetails.reconciliationId;
|
|
switch (action) {
|
|
case 'performAuditFromBCM':
|
|
actionPromise = assetService.performAuditFromBCM(deviceId, reconId);
|
|
break;
|
|
case 'pingDeviceFromBCM':
|
|
actionPromise = assetService.pingDeviceFromBCM(deviceId, reconId);
|
|
break;
|
|
case 'rebootDeviceFromBCM':
|
|
actionPromise = assetService.rebootDeviceFromBCM(deviceId, reconId);
|
|
break;
|
|
case 'wakeupDeviceFromBCM':
|
|
actionPromise = assetService.wakeupDeviceFromBCM(deviceId, reconId);
|
|
break;
|
|
case 'shutdownDeviceFromBCM':
|
|
actionPromise = assetService.shutdownDeviceFromBCM(deviceId, reconId);
|
|
break;
|
|
}
|
|
return actionPromise;
|
|
};
|
|
return assetModel;
|
|
}
|
|
]);
|
|
}());
|