<commit_before>var mongoose = require('mongoose'),
  Schema = mongoose.Schema,
  Promise = require('promise')
/**
 * Access to a repository to store aggregated exchanges to support pluggable implementations.
 *
 * @version
 */
  , AggregationRepositorySchema = new Schema({
      correlationId: {type: String, unique: true},
      entries: [Schema.Types.Mixed]
    },
    {collection: 'aggregation_repository'});

/**
 * Add event
 * @param key
 * @param event
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.add = function (key, event) {
  return new Promise(function (fulfill, reject) {
    var upsertObj = {
      $push: {
        entries: event
      }
    };
    AggregationRepository.findOneAndUpdate({correlationId: key},
      upsertObj,
      {
        upsert: true
      }
    ).exec(function (err, data) {
        if (err) {
          reject(err);
        } else {
          fulfill(data);
        }
      });

  });
};

/**
 * Get events of specified correlationId
 * @param key
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.get = function (key) {
  return new Promise(function (fulfill, reject) {
    AggregationRepository.findOne({correlationId: key}).exec(function (err, data) {
      if (err) {
        reject(err);
      } else {
        fulfill(data);
      }
    });
  });
};

/**
 * Remove events for specified correlationId
 * @param key
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.remove = function (key) {
  return new Promise(function (fulfill, reject) {
    AggregationRepository.findOneAndRemove({correlationId: key}, function(err, data) {
      if (err) {
        reject(err);
      } else {
        fulfill(data);
      }
    });
  });
};

/**
 * Get all correlationIds info
 * @returns {*|exports|module.exports}
 */
AggregationRepositorySchema.statics.getKeys = function () {
  return new Promise(function (fulfill, reject) {
    AggregationRepository.find({}).exec(function (err, data) {
      if (err) {
        reject(err);
      } else {
        fulfill(data);<commit_msg>Added extra fields(status, contextId) and functions in AggregationRepository<commit_after>var mongoose = require('mongoose'),
  Schema = mongoose.Schema

/**
 * Access to a repository to store aggregated exchanges to support pluggable implementations.
 *
 * @version
 */
  , AggregationRepositorySchema = new Schema({
      correlationId: {type: String, unique: true},
      contextId: {type: String},
      events: [Schema.Types.Mixed],
      status: {type: String}
    },
    {collection: 'aggregation_repository'});

AggregationRepositorySchema.index({correlationId: 1, contextId: 1}, {unique: true});

/**
 * Add event
 * @param correlationId
 * @param contextId
 * @param event
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.add = function (correlationId, contextId, event) {
  return new Promise(function (fulfill, reject) {
    var upsertObj = {
      $push: {
        events: event,
        status: 'initial'
      }
    };
    AggregationRepository.findOneAndUpdate({correlationId: correlationId, contextId: contextId},
      upsertObj,
      {
        upsert: true
      }
    ).exec(function (err, data) {
        if (err) {
          reject(err);
        } else {
          fulfill(data);
        }
      });

  });
};

/**
 * Get events of specified correlationId
 * @param correlationId
 * @param contextId
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.get = function (correlationId, contextId) {
  return new Promise(function (fulfill, reject) {
    AggregationRepository.findOne({correlationId: correlationId, contextId: contextId}).exec(function (err, data) {
      if (err) {
        reject(err);
      } else {
        fulfill(data);
      }
    });
  });
};

/**
 * Remove events for specified correlationId
 * @param correlationId
 * @param contextId
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.remove = function (correlationId, contextId) {
  return new Promise(function (fulfill, reject) {
    AggregationRepository.findOneAndRemove({correlationId: correlationId, contextId: contextId}, function(err, data) {
      if (err) {
        reject(err);
      } else {
        fulfill(data);
      }
    });
  });
};

/**
 * Marks as completed the specific correlationId, contextId tuple
 * @param correlationId
 * @param contextId
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.complete = function (correlationId, contextId) {
  return this.updateStatus(correlationId, contextId, 'completed');
};

/**
 * Marks as expired the specific correlationId, contextId tuple
 * @param correlationId
 * @param contextId
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.expire = function (correlationId, contextId) {
  return this.updateStatus(correlationId, contextId, 'expired');
};

/**
 * Updates the status of a specific correlationId, contextId tuple
 * @param correlationId
 * @param contextId
 * @param status
 * @returns {Promise}
 */
AggregationRepositorySchema.statics.updateStatus = function (correlationId, contextId, status) {
  return new Promise(function (fulfill, reject) {
    var updateObj = {
      $push: {
        status: status
      }
    };
    AggregationRepository.findOneAndUpdate({correlationId: correlationId, contextId: contextId},
      updateObj).exec(function (err, data) {
        if (err) {
          reject(err);
        } else {
          fulfill(data);
        }
      });
  });
};

/**
 * Get all correlationIds info for a specific contextId
 * @param contextId
 * @returns {Promise}
 * @returns {*|exports|module.exports}
 */
AggregationRepositorySchema.statics.getKeys = function (contextId) {
  return new Promise(function (fulfill, reject) {
    AggregationRepository.find({contextId: contextId}).exec(function (err, data) {
      if (err) {
        reject(err);
      } else {
        fulfill(data);
{'fraction_non_alphanumeric': 0.1261690188743411, 'fraction_numerical': 0.0003400782179901377, 'mean_word_length': 3.153954802259887, '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': '4535839', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1682, 'n_words': 411}