<commit_before>var debug = require('debug')('OSMBC:model:messageCenter');
var async = require('async');
var path = require('path');
var should = require('should');
var config = require('../config.js');
var logModule = require('../model/logModule.js');
var messageFilter = require('../model/messageFilter.js');
var MailReceiver = require('../model/mailReceiver.js');

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var EmailTemplate = require('email-templates').EmailTemplate;




function MessageCenter() {
  debug('MessageCenter::MessageCenter');
  this.receiverList = [];
}

MessageCenter.prototype.sendInfo = function(object,callback) {
  debug('MessageCenter::sendInfo');
  async.each(this.receiverList,function sendIt(element,cb){
    element.sendInfo(object,cb);
  },function final(err) {callback(err);});
};

MessageCenter.prototype.updateArticle = function (user,article,change,callback) {
  debug('MessageCenter::updateArticle');
  async.each(this.receiverList,function sendIt(element,cb){
    element.updateArticle(user,article,change,cb);
  },function final(err) {callback(err);});
};


function ConsoleReceiver() {
  debug("ConsoleReceiver::ConsoleReceiver");

}
ConsoleReceiver.prototype.sendInfo = function(object,cb) {
  console.log("ConsoleReceiver::Info Received");
  console.dir(object);
  cb();
};

ConsoleReceiver.prototype.updateArticle = function(user,article,change,cb) { //jshint ignore:line
  console.log("Update Artcile was called");
  return cb();
};

function LogModuleReceiver() {}

LogModuleReceiver.prototype.sendInfo= function(object,cb) {
  debug('LogModuleReceiver::sendInfo');
  logModule.log(object,cb);
};

LogModuleReceiver.prototype.updateArticle= function(user,article,change,cb) {
  debug('LogModuleReceiver::sendInfo');
  should.exist(article.id);
  should(article.id).not.equal(0);
  var logblog = article.blog;
  if (change.blog) logblog = change.blog;
  async.forEachOf(change,function setAndSaveEachOf(value,key,cb_eachOf){
    // There is no Value for the key, so do nothing
    if (typeof(value)=='undefined') return cb_eachOf();

    // The Value to be set, is the same then in the object itself
    // so do nothing
    if (value == article[key]) return cb_eachOf();
    if (typeof(article[key])==='undefined' && value === '') return cb_eachOf();
    async.series ( [
        function(cb) {
           logModule.log({oid:article.id,blog:logblog,user:user.displayName,table:"article",property:key,from:article[key],to:value},cb);
        }
      ],function(err){
        cb_eachOf(err);
      });
  },function finalFunction(err) {cb(err);});
};


MessageCenter.prototype.registerReceiver = function(receiver) {
  debug('MessageCenter::registerReceiver');
  this.receiverList.push(receiver);
};

var messageCenter = new MessageCenter();

messageCenter.registerReceiver(new messageFilter.withParam.comment("TheFive",new ConsoleReceiver()));
messageCenter.registerReceiver(new messageFilter.global.newCollection(new ConsoleReceiver()));
messageCenter.registerReceiver(new messageFilter.global.newCollection(new MailReceiver(null)));
messageCenter.registerReceiver(new messageFilter.global.allComment(new MailReceiver(null)));
messageCenter.registerReceiver(new LogModuleReceiver());


module.exports = messageCenter;<commit_msg>Logging the same time for a transaction.<commit_after>var debug = require('debug')('OSMBC:model:messageCenter');
var async = require('async');
var path = require('path');
var should = require('should');
var config = require('../config.js');
var logModule = require('../model/logModule.js');
var messageFilter = require('../model/messageFilter.js');
var MailReceiver = require('../model/mailReceiver.js');

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');
var EmailTemplate = require('email-templates').EmailTemplate;




function MessageCenter() {
  debug('MessageCenter::MessageCenter');
  this.receiverList = [];
}

MessageCenter.prototype.sendInfo = function(object,callback) {
  debug('MessageCenter::sendInfo');
  async.each(this.receiverList,function sendIt(element,cb){
    element.sendInfo(object,cb);
  },function final(err) {callback(err);});
};

MessageCenter.prototype.updateArticle = function (user,article,change,callback) {
  debug('MessageCenter::updateArticle');
  async.each(this.receiverList,function sendIt(element,cb){
    element.updateArticle(user,article,change,cb);
  },function final(err) {callback(err);});
};


function ConsoleReceiver() {
  debug("ConsoleReceiver::ConsoleReceiver");

}
ConsoleReceiver.prototype.sendInfo = function(object,cb) {
  console.log("ConsoleReceiver::Info Received");
  console.dir(object);
  cb();
};

ConsoleReceiver.prototype.updateArticle = function(user,article,change,cb) { //jshint ignore:line
  console.log("Update Artcile was called");
  return cb();
};

function LogModuleReceiver() {}

LogModuleReceiver.prototype.sendInfo= function(object,cb) {
  debug('LogModuleReceiver::sendInfo');
  logModule.log(object,cb);
};

LogModuleReceiver.prototype.updateArticle= function(user,article,change,cb) {
  debug('LogModuleReceiver::sendInfo');
  should.exist(article.id);
  should(article.id).not.equal(0);
  var logblog = article.blog;
  if (change.blog) logblog = change.blog;
  var timestamp = new Date();
  async.forEachOf(change,function setAndSaveEachOf(value,key,cb_eachOf){
    // There is no Value for the key, so do nothing
    if (typeof(value)=='undefined') return cb_eachOf();

    // The Value to be set, is the same then in the object itself
    // so do nothing
    if (value == article[key]) return cb_eachOf();
    if (typeof(article[key])==='undefined' && value === '') return cb_eachOf();
    async.series ( [
        function(cb) {
           logModule.log({oid:article.id,
                          blog:logblog,
                          user:user.displayName,
                          table:"article",
                          property:key,
                          from:article[key],
                          to:value,
                          timestamp:timestamp},cb);
        }
      ],function(err){
        cb_eachOf(err);
      });
  },function finalFunction(err) {cb(err);});
};


MessageCenter.prototype.registerReceiver = function(receiver) {
  debug('MessageCenter::registerReceiver');
  this.receiverList.push(receiver);
};

var messageCenter = new MessageCenter();

messageCenter.registerReceiver(new messageFilter.withParam.comment("TheFive",new ConsoleReceiver()));
messageCenter.registerReceiver(new messageFilter.global.newCollection(new ConsoleReceiver()));
messageCenter.registerReceiver(new messageFilter.global.newCollection(new MailReceiver(null)));
messageCenter.registerReceiver(new messageFilter.global.allComment(new MailReceiver(null)));
messageCenter.registerReceiver(new LogModuleReceiver());


module.exports = messageCenter;
{'fraction_non_alphanumeric': 0.14820705610179294, 'fraction_numerical': 0.0002891844997108155, 'mean_word_length': 5.175892857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2094174', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1945, 'n_words': 350}