Name
global.ProjectChangeNotifier
Description
This will broadcast changes in shadow task in a predecessor project to downstream successor projects If it is soft relation, we will check and raise notification If it is hard relation, we will create notification and accept it
Script
var ProjectChangeNotifier = Class.create();
ProjectChangeNotifier.prototype = {
initialize: function() {
},
broadcastDownStream: function (shadowTaskIds) {
PPMDebug.log("Into ProjectChangeNotifier: aggregateAndRaiseEvent -> " + JSON.stringify(shadowTaskIds));
var topTasks = {};
// Only hard dependencies with update tasks are meant to reach here
for (var i = 0; i < shadowTaskIds.length; i++) {
var task = shadowTaskIds[i];
var relationApplied = task.relation_applied;
var relationRecord = ShadowTaskQueryHelper.relationRecord(relationApplied);
var isHard = ShadowTaskAndRelationChecker.isHard(relationRecord);
var hasOrigTopTaskId = JSUtil.notNil(task.orig_top_task_id);
PPMDebug.log("isHard -> " + isHard + " | hasOrigTopTaskId -> " + hasOrigTopTaskId);
if(isHard && hasOrigTopTaskId) {
if(JSUtil.nil(topTasks[task.orig_top_task_id]))
topTasks[task.orig_top_task_id] = [task];
else
topTasks[task.orig_top_task_id].push(task);
}
}
PPMDebug.log("ProjectChangeNotifier: getTopTasks -> " + JSON.stringify(topTasks));
for( var topTaskId in topTasks ) {
if(this.processHardDependencyInSync(topTaskId)) {
PPMDebug.log("Into ProjectChangeNotifier: processHardDependencyInSync -> In Sync");
this.raiseAndAcceptNotification(topTasks[topTaskId]);
} else {
PPMDebug.log("Into ProjectChangeNotifier: processHardDependencyInSync -> Async");
InterProjectEventManager.raiseEvent(topTaskId, JSON.stringify(topTasks[topTaskId]));
}
}
},
// Check if the Process Interproject Hard dependency is In Sync
processHardDependencyInSync: function (topTaskId) {
PPMDebug.log("Into ProjectChangeNotifier: processHardDependencyInSync -> " + topTaskId);
if(JSUtil.notNil(topTaskId)) {
var gr = new GlideRecord("planned_task");
if(gr.get(topTaskId)) {
return SNC.PPMConfig.getProperty("com.snc.project.process_hard_dependency_in_sync",
gr.getValue("sys_class_name"), 'true') == 'true';
}
}
return false;
},
raiseAndAcceptNotification: function (tasks) {
PPMDebug.log("Into ProjectChangeNotifier: raiseAndAcceptNotification -> " + JSON.stringify(tasks));
var notificationHandler = new PlannedTaskNotificationHandler();
if(JSUtil.notNil(tasks) && tasks.length > 0) {
for (var i = 0; i < tasks.length; i++) {
var task = tasks[i];
PPMDebug.log("Into ProjectChangeNotifier: raiseNotification -> " + JSON.stringify(task));
var event = notificationHandler.raiseNotification(task.sys_id, task.orig_sys_id, task.relation_applied, task.previous_start_date);
var notifRecord = event.record;
// re-query the notification - as dot walk records are missing
var notifRecordSysId = notifRecord.getValue("sys_id");
var notificationGr = new GlideRecord("planned_task_notification");
if(notificationGr.get(notifRecordSysId)) {
PPMDebug.log("Into ProjectChangeNotifier.acceptNotification -> " + notifRecordSysId );
notificationHandler.acceptNotification(notificationGr);
}
}
}
},
type: 'ProjectChangeNotifier'
};
Sys ID
0bd869519f532200598a5bb0657fcfdf