Name
sn_entitlement.SubscriptionDetailService
Description
No description available
Script
var SubscriptionDetailService = Class.create();
SubscriptionDetailService.prototype = {
initialize: function() {
this._allocationService = new sn_entitlement.AllocationDataService();
this._statsService = new sn_entitlement.SubscriptionStatsService();
this._sdDao = new sn_entitlement.dao_SubscriptionDetail();
this._instanceStatsDao = new sn_entitlement.dao_SubscriptionInstanceStats();
this._licenseDetailDao = new sn_entitlement.LicenseDetailDaoV1();
this._engineUtils = new sn_lef.EntitlementEngineUtils();
},
/**
* Initiates creation of subscription_detail records and all related records and stats
*
*
*/
createSubscriptionDetails: function() {
const map = this._allocationService.createEntries();
const stats = this._allocationService.getSubscriptionStatsAccumulator();
// stats
Object.keys(map).forEach(subscriptionId => {
const detailId = map[subscriptionId];
let detailEntry = {};
detailEntry.sysId = detailId;
detailEntry.subscription = subscriptionId;
detailEntry.unconfirmedUserCount = stats.getUnallocatedUserCount(subscriptionId);
detailEntry.allocatedUserCount = stats.getAllocatedUserCount(subscriptionId);
detailEntry.unconfirmedGroupCount = stats.getUnallocatedGroupCount(subscriptionId);
detailEntry.allocatedUserWithoutLicensableRoleCount = stats.getAllocatedUsersWithoutLicensableRoleCount(subscriptionId);
// TODO: Need a different calculation method for this.
// The current statsService.calculateAllocatedUserCount() does not take roles into consideration
// as a user is allocated if they are mapped to a subscription. Their roles don't matter. So a
// different calculation is needed for this stat.
detailEntry.allocatedUserOobCount = 0;
// Note: Due to performance issues with the previous code, this is being set explicitly to 0 for now
// until a more performant implementation can be made.
detailEntry.unconfirmedUserOobCount = 0;
detailEntry.licensableGroupCount = stats.getLicensableGroupCount(subscriptionId);
detailEntry.licensableGroupSubscribedCount = stats.getLicensableGroupSubscribedCount(subscriptionId);
// this is v1 specific and need a different approach for v2, but fails gracefully in v2
const licenseQuotaId = this._licenseDetailDao.getQuotaId(subscriptionId);
const quotaCount = this._engineUtils.calculateAllocation(licenseQuotaId, "");
detailEntry.allocatedQuotaCount = Number.isInteger(parseInt(quotaCount)) ? quotaCount : 0;
detailEntry.allocatedCustomTableCount = 0;
this._sdDao.updateRecord(detailEntry);
});
//write instance level stats
const unallocatedUserMultiSubscriptionCount = stats.getUnallocatedUserMultiSubscriptionCount();
const allocatedUserMultiSubscriptionCount = stats.getAllocatedUserMultiSubscriptionCount();
const allocatedLicensableUserCount = stats.getUsersWithALicensableRoleAndSubscriptionCount();
const licensableUserCount = stats.getUsersWithALicensableRoleCount();
this._instanceStatsDao.markOldInstanceStatsRecords();
this._instanceStatsDao.writeSubscriptionInstanceStats({
"licensableUserCount": licensableUserCount,
"allocatedLicensableUserCount": allocatedLicensableUserCount,
"allocatedUserMultiBucketCount": allocatedUserMultiSubscriptionCount,
"unconfirmedUserMultiBucketCount": unallocatedUserMultiSubscriptionCount
});
//done with stats
this._sdDao.completeSubscriptionDetails(map); // todo include a union of the useless details entries(ie. non per user)
},
type: 'SubscriptionDetailService'
};
Sys ID
ee0bfc62ff212110d185612a453bf1f1