<commit_before>//Copyright (c) 2018, Livio, Inc.
const app = require('../app');
const flame = app.locals.flame;
const model = require('./model.js');
const setupSqlCommand = app.locals.db.setupSqlCommand;
const sql = require('./sql.js');
const sqlApps = require('../applications/sql.js');
const funcGroupSql = require('../groups/sql.js');
const messagesSql = require('../messages/sql.js');
const moduleConfigSql = require('../module-config/sql.js');
const messages = require('../messages/helper.js');
const cache = require('../../../custom/cache');
const log = require('../../../custom/loggers/winston');
const GET = require('lodash.get');

//validation functions

function validateCorePost (req, res) {
    if (!req.body.policy_table) {
        return res.errorMsg = "Please provide policy table information";
    } else if (!req.body.policy_table.app_policies) {
        return res.errorMsg = "Please provide app policies information";
    } else if (!req.body.policy_table.consumer_friendly_messages) {
        return res.errorMsg = "Please provide consumer friendly messages information";
    } else if (!req.body.policy_table.device_data) {
        return res.errorMsg = "Please provide device data information";
    } else if (!req.body.policy_table.functional_groupings) {
        return res.errorMsg = "Please provide functional groupings information";
    } else if (!req.body.policy_table.module_config) {
        return res.errorMsg = "Please provide module config information";
    } else if (!req.body.policy_table.usage_and_error_counts) {
        return res.errorMsg = "Please provide usage and error counts information";
    }
}

function validateAppPolicyOnlyPost (req, res) {
    if (!req.body.policy_table) {
        return res.errorMsg = "Please provide policy table information";
    } else if (!req.body.policy_table.app_policies) {
        return res.errorMsg = "Please provide app policies information";
    }
}

//helper functions

function generatePolicyTable (isProduction, useLongUuids = false, appPolicyObj, returnPreview, cb) {
    let makePolicyTable = {};
    if (appPolicyObj) { //existence of appPolicyObj implies to return the app policy object
        makePolicyTable.appPolicies = setupAppPolicies(isProduction, useLongUuids, appPolicyObj);
    }

    cache.getCacheData(isProduction, app.locals.version, cache.policyTableKey, function (err, cacheData) {
        if (cacheData) {
            if(cacheData.moduleConfig){
                cacheData.moduleConfig.full_app_id_supported = useLongUuids;
            }
            const policyTableMakeFlow = flame.flow(makePolicyTable, {method: 'parallel', eventLoop: true});<commit_msg>+ debugging occasional caching issues<commit_after>//Copyright (c) 2018, Livio, Inc.
const app = require('../app');
const flame = app.locals.flame;
const model = require('./model.js');
const setupSqlCommand = app.locals.db.setupSqlCommand;
const sql = require('./sql.js');
const sqlApps = require('../applications/sql.js');
const funcGroupSql = require('../groups/sql.js');
const messagesSql = require('../messages/sql.js');
const moduleConfigSql = require('../module-config/sql.js');
const messages = require('../messages/helper.js');
const cache = require('../../../custom/cache');
const log = require('../../../custom/loggers/winston');
const GET = require('lodash.get');

//validation functions

function validateCorePost (req, res) {
    if (!req.body.policy_table) {
        return res.errorMsg = "Please provide policy table information";
    } else if (!req.body.policy_table.app_policies) {
        return res.errorMsg = "Please provide app policies information";
    } else if (!req.body.policy_table.consumer_friendly_messages) {
        return res.errorMsg = "Please provide consumer friendly messages information";
    } else if (!req.body.policy_table.device_data) {
        return res.errorMsg = "Please provide device data information";
    } else if (!req.body.policy_table.functional_groupings) {
        return res.errorMsg = "Please provide functional groupings information";
    } else if (!req.body.policy_table.module_config) {
        return res.errorMsg = "Please provide module config information";
    } else if (!req.body.policy_table.usage_and_error_counts) {
        return res.errorMsg = "Please provide usage and error counts information";
    }
}

function validateAppPolicyOnlyPost (req, res) {
    if (!req.body.policy_table) {
        return res.errorMsg = "Please provide policy table information";
    } else if (!req.body.policy_table.app_policies) {
        return res.errorMsg = "Please provide app policies information";
    }
}

//helper functions

function generatePolicyTable (isProduction, useLongUuids = false, appPolicyObj, returnPreview, cb) {
    let makePolicyTable = {};
    if (appPolicyObj) { //existence of appPolicyObj implies to return the app policy object
        makePolicyTable.appPolicies = setupAppPolicies(isProduction, useLongUuids, appPolicyObj);
    }

    cache.getCacheData(isProduction, app.locals.version, cache.policyTableKey, function (err, cacheData) {
        if (GET(cacheData, "moduleConfig")
        && GET(cacheData, "functionalGroups")
        && GET(cacheData, "consumerFriendlyMessages")) {
            if(cacheData.moduleConfig){
                cacheData.moduleConfig.full_app_id_supported = useLongUuids;
            }
            const policyTableMakeFlow = flame.flow(makePolicyTable, {method: 'parallel', eventLoop: true});
{'fraction_non_alphanumeric': 0.12525104984480556, 'fraction_numerical': 0.001460653642505021, 'mean_word_length': 3.722413793103448, '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': '4476026', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1518, 'n_words': 390}