<commit_before>/***************************************************************
 *
 * DASHBOARD CORE_PROVISION
 *
 ***************************************************************/
var soajs = require("soajs");
var async = require("async");

const dataFolder = process.env.SOAJS_DATA_FOLDER;
delete require.cache[process.env.SOAJS_PROFILE];
const profile = require(process.env.SOAJS_PROFILE);

profile.name = "core_provision";
var mongo = new soajs.mongo(profile);


mongo.dropDatabase(function () {
	lib.addEnvs(function () {
		lib.addProducts(function () {
			lib.addServices(function () {
				lib.addTenants(function () {
					lib.addGitAccounts(function () {
						lib.addCatalogs(function () {
							mongo.closeDb();
							profile.name = "DBTN_urac";
							mongo = new soajsModules.mongo(profile);
							mongo.dropDatabase(function () {
								lib.addUsers(function () {
									lib.addGroups(function () {
										lib.uracIndex(function () {
											mongo.closeDb();
										});
									});
								});
							});
						});
					});
				});
			});
		});
	});
});

const lib = {
	/*
	 Environments
	 */
	"addEnvs": function (cb) {
		var record = require(dataFolder + "environments/dashboard.js");
		record._id = mongo.ObjectId(record._id);
		mongo.insert("environment", record, cb);
	},

	/*
	 Products
	 */
	"addProducts": function (cb) {
		var record = require(dataFolder + "products/dsbrd.js");
		record._id = mongo.ObjectId(record._id);
		mongo.insert("products", record, cb);
	},

	/*
	 Services
	 */
	"addServices": function (cb) {
		var record = require(dataFolder + "services/index.js");
		mongo.insert("services", record, cb);
	},

	/*
	 Tenants
	 */
	"addTenants": function (cb) {
		var record = require(dataFolder + "tenants/owner.js");

		record._id = mongo.ObjectId(record._id);
		record.applications.forEach(function (oneApp) {
			oneApp.appId = mongo.ObjectId(oneApp.appId);
		});

		mongo.insert("tenants", record, cb);
	},

	/*
	 Git Accounts
	 */
	"addGitAccounts": function (cb) {
		var record = require(dataFolder + "gitAccounts/soajsRepos.js");
		record._id = mongo.ObjectId(record._id);
		mongo.insert("git_accounts", record, cb);
	},

	/*
	 Catalogs
	 */
	"addCatalogs": function (cb) {
		var records = require(dataFolder + "catalogs/index.js");
		mongo.insert("catalogs", records, cb);
	},

	/***************************************************************
	 *
	 * DASHBOARD URAC
	 *
	 ***************************************************************/
	/*
	 Users
	 */
	"addUsers": function (cb) {
		var record = require(dataFolder + "urac/users/owner.js");
		mongo.insert("users", record, cb);
	},

	/*
	 Groups
	 */
	"addGroups": function (cb) {
		var record = require(dataFolder + "urac/groups/owner.js");
		mongo.insert("groups", record, cb);
	},

	"errorLogger": function (error) {
		if (error) {
			return console.log(error);
		}
	},

	"uracIndex": function (cb) {
		var indexes = [
			{
				col: 'users',
				index: {username: 1},
				options: {unique: true}
			},
			{
				col: 'users',
				index: {email: 1},
				options: {unique: true}
			},
			{
				col: 'users',
				index: {username: 1, status: 1},
				options: null
			},
			{
				col: 'users',
				index: {email: 1, status: 1},
				options: null
			},
			{
				col: 'users',
				index: {groups: 1, 'tenant.id': 1},
				options: null
			},
			{
				col: 'users',
				index: {username: 1, 'tenant.id': 1},
				options: null
			},
			{
				col: 'users',
				index: {status: 1},
				options: null
			},
			{
				col: 'users',
				index: {locked: 1},
				options: null
			},
			{
				col: 'users',
				index: {'tenant.id': 1},
				options: null
			},
			{
				col: 'groups',
				index: {code: 1, 'tenant.id': 1},
				options: null
			},
			{
				col: 'groups',
				index: {code: 1},
				options: null
			},
			{
				col: 'groups',
				index: {'tenant.id': 1},
				options: null
			},
			{
				col: 'groups',
				index: {locked: 1},
				options: null
			},
			{
				col: 'tokens',
				index: {token: 1},
				options: {unique: true}
			},
			{
				col: 'tokens',
				index: {userId: 1, service: 1, status: 1},
				options: null
			},
			{
				col: 'tokens',
				index: {token: 1, service: 1, status: 1},
				options: null
			}
		];

		async.each(indexes, function (oneIndex, callback) {
			mongo.ensureIndex(oneIndex.col, oneIndex.index, oneIndex.options, function (error) {
				lib.errorLogger(error);
				return callback();
			});
		}, cb);
	}
};

<commit_msg>minor modification.<commit_after>/***************************************************************
 *
 * DASHBOARD CORE_PROVISION
 *
 ***************************************************************/
var soajs = require("soajs");
var async = require("async");

const dataFolder = process.env.SOAJS_DATA_FOLDER;
delete require.cache[process.env.SOAJS_PROFILE];
const profile = require(process.env.SOAJS_PROFILE);

profile.name = "core_provision";
var mongo = new soajs.mongo(profile);


mongo.dropDatabase(function () {
	lib.addEnvs(function () {
		lib.addProducts(function () {
			lib.addServices(function () {
				lib.addTenants(function () {
					lib.addGitAccounts(function () {
						lib.addCatalogs(function () {
							mongo.closeDb();
							profile.name = "DBTN_urac";
							mongo = new soajs.mongo(profile);
							mongo.dropDatabase(function () {
								lib.addUsers(function () {
									lib.addGroups(function () {
										lib.uracIndex(function () {
											mongo.closeDb();
										});
									});
								});
							});
						});
					});
				});
			});
		});
	});
});

const lib = {
	/*
	 Environments
	 */
	"addEnvs": function (cb) {
		var record = require(dataFolder + "environments/dashboard.js");
		record._id = mongo.ObjectId(record._id);
		mongo.insert("environment", record, cb);
	},

	/*
	 Products
	 */
	"addProducts": function (cb) {
		var record = require(dataFolder + "products/dsbrd.js");
		record._id = mongo.ObjectId(record._id);
		mongo.insert("products", record, cb);
	},

	/*
	 Services
	 */
	"addServices": function (cb) {
		var record = require(dataFolder + "services/index.js");
		mongo.insert("services", record, cb);
	},

	/*
	 Tenants
	 */
	"addTenants": function (cb) {
		var record = require(dataFolder + "tenants/owner.js");

		record._id = mongo.ObjectId(record._id);
		record.applications.forEach(function (oneApp) {
			oneApp.appId = mongo.ObjectId(oneApp.appId);
		});

		mongo.insert("tenants", record, cb);
	},

	/*
	 Git Accounts
	 */
	"addGitAccounts": function (cb) {
		var record = require(dataFolder + "gitAccounts/soajsRepos.js");
		record._id = mongo.ObjectId(record._id);
		mongo.insert("git_accounts", record, cb);
	},

	/*
	 Catalogs
	 */
	"addCatalogs": function (cb) {
		var records = require(dataFolder + "catalogs/index.js");
		mongo.insert("catalogs", records, cb);
	},

	/***************************************************************
	 *
	 * DASHBOARD URAC
	 *
	 ***************************************************************/
	/*
	 Users
	 */
	"addUsers": function (cb) {
		var record = require(dataFolder + "urac/users/owner.js");
		mongo.insert("users", record, cb);
	},

	/*
	 Groups
	 */
	"addGroups": function (cb) {
		var record = require(dataFolder + "urac/groups/owner.js");
		mongo.insert("groups", record, cb);
	},

	"errorLogger": function (error) {
		if (error) {
			return console.log(error);
		}
	},

	"uracIndex": function (cb) {
		var indexes = [
			{
				col: 'users',
				index: {username: 1},
				options: {unique: true}
			},
			{
				col: 'users',
				index: {email: 1},
				options: {unique: true}
			},
			{
				col: 'users',
				index: {username: 1, status: 1},
				options: null
			},
			{
				col: 'users',
				index: {email: 1, status: 1},
				options: null
			},
			{
				col: 'users',
				index: {groups: 1, 'tenant.id': 1},
				options: null
			},
			{
				col: 'users',
				index: {username: 1, 'tenant.id': 1},
				options: null
			},
			{
				col: 'users',
				index: {status: 1},
				options: null
			},
			{
				col: 'users',
				index: {locked: 1},
				options: null
			},
			{
				col: 'users',
				index: {'tenant.id': 1},
				options: null
			},
			{
				col: 'groups',
				index: {code: 1, 'tenant.id': 1},
				options: null
			},
			{
				col: 'groups',
				index: {code: 1},
				options: null
			},
			{
				col: 'groups',
				index: {'tenant.id': 1},
				options: null
			},
			{
				col: 'groups',
				index: {locked: 1},
				options: null
			},
			{
				col: 'tokens',
				index: {token: 1},
				options: {unique: true}
			},
			{
				col: 'tokens',
				index: {userId: 1, service: 1, status: 1},
				options: null
			},
			{
				col: 'tokens',
				index: {token: 1, service: 1, status: 1},
				options: null
			}
		];

		async.each(indexes, function (oneIndex, callback) {
			mongo.ensureIndex(oneIndex.col, oneIndex.index, oneIndex.options, function (error) {
				lib.errorLogger(error);
				return callback();
			});
		}, cb);
	}
};


{'fraction_non_alphanumeric': 0.22407801815939918, 'fraction_numerical': 0.005604752830400179, 'mean_word_length': 2.864010394110004, 'pattern_counts': {'":': 20, '<': 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': '344242', 'n_tokens_mistral': 3930, 'n_tokens_neox': 3064, 'n_words': 609}