Name
sn_grc.IGContentToEntityTypeActionHandler
Description
No description available
Script
var IGContentToEntityTypeActionHandler = Class.create();
IGContentToEntityTypeActionHandler.prototype = {
initialize: function(action, strategy) {
this.actionType = action.action;
this.source = action.source;
this.sourceTable = action.table;
this.entityTypeId = action.entity_type_id;
this.contentId = action.content_id;
this.strategy = strategy;
},
execute: function() {
if (this.actionType == 'add_content_to_entity_type') {
this._addContentToEntityType();
} else if (this.actionType == 'remove_content_from_entity_type') {
this._removeContentToEntityType();
}
},
/**
The following behavior will be happened when adding content to entity type:
1. The association of a PA Indicator to a content triggers for all associated items the generation of the association PA indicator to item. In addition if the PA Indicator has an element breakdown matching the item's entity. The generated PA indicator will be set with this element breakdown.
2. Generate Item for all the entities from given entity type and content if item doesnt exist, or item will be activated if the item exists.
3. The "souce" of the item will be populated as given entity type id
**/
_addContentToEntityType: function() {
// GRC PA
var paContentIndicatorList = {};
if (GlidePluginManager.isActive('com.sn_grc_pa')) {
paContentIndicatorList = (new sn_grc_pa.GRCPAIndicatorUtils()).getIndicatorBreakdownList(this.contentId);
}
// Get the entities associated with the entity type
var entityToEntityType = new GlideRecord('sn_grc_m2m_profile_profile_type');
entityToEntityType.addQuery('profile_type', this.entityTypeId);
entityToEntityType.addQuery('profile.active', true);
entityToEntityType.query();
while (entityToEntityType.next()) {
var entityId = entityToEntityType.getValue('profile');
var itemId = this.strategy.generateItem(entityId, this.contentId, this.entityTypeId);
if (GlidePluginManager.isActive('com.sn_grc_pa')) {
var item = new GlideRecord('sn_grc_item');
if (itemId != '' && item.get(itemId)) {
for (var paContentIndicatorId in paContentIndicatorList) {
(new sn_grc_pa.GRCPAIndicatorUtils()).generatePAIndicatorItemRelationship(item, paContentIndicatorId, paContentIndicatorList[paContentIndicatorId]);
}
}
}
}
//check for Risk Statement to Control Objective record
// Update strategy as Risk To Control can only be done from RISK Side
if (new ItemGenerationV2Conditions().checkIfRiskComplianceInstalled()) {
this.strategy = new ItemGenerationV2Utils().getStrategy('sn_risk');
var RStoCO = new GlideRecord('sn_risk_m2m_risk_definition_policy_statement');
RStoCO.addQuery('sn_compliance_policy_statement', this.contentId).addOrCondition('sn_risk_definition', this.contentId);
RStoCO.query();
while (RStoCO.next()) {
var actionParams = {
'action': 'add_content_to_content',
'source': RStoCO.getUniqueValue(),
'table': RStoCO.getTableName(),
'content_id': RStoCO.getValue('sn_risk_definition')
};
new sn_grc.IGContentActionHandler(actionParams, this.strategy, true).execute();
}
}
},
/**
The following behavior will be happened when removing content from entity type:
1. The given entity type will be removed from "souce" of the item
**/
_removeContentToEntityType: function() {
var util = new ItemGenerationV2Utils();
var item = new GlideRecord(this.strategy.itemTable);
item.addQuery('instance', 'true');
item.addQuery('content', this.contentId);
item.addQuery('source', 'CONTAINS', this.entityTypeId);
item.query();
while (item.next()) {
util.deleteSourceInItem(item, this.entityTypeId);
}
},
type: 'IGContentToEntityTypeActionHandler'
};
Sys ID
31b369ff07d22010bbc77f04a9d30066