<commit_before>/*!
  GPII JSON Settings Handler

  Copyright 2012 OpenDirective and Raising the Floor - International

  Licensed under the New BSD license. You may not use this file except in
  compliance with this License.

  You may obtain a copy of the License at
  https://github.com/gpii/universal/LICENSE.txt
*/

(function () {

    "use strict";

    var fluid = require("infusion"),
        fs = require("fs"),
        gpii = fluid.registerNamespace("gpii");

    fluid.registerNamespace("gpii.settingsHandlers.JSONSettingsHandler");

    // TODO: When FLUID-4852 is fixed, remove these definitions
    var getParser = {
        parser: {
            parse: fluid.pathUtil.parseEL,
            compose: fluid.pathUtil.composePath
        },
        strategies: [fluid.model.defaultFetchStrategy]
    };

    var setParser = {
        parser: {
            parse: fluid.pathUtil.parseEL,
            compose: fluid.pathUtil.composePath
        },
        strategies: [fluid.model.defaultFetchStrategy, fluid.model.defaultCreatorStrategy]
    };

    gpii.settingsHandlers.JSONSettingsHandler.set = function (profile) {
        var returnObj = fluid.copy(profile);
        return fluid.transform(returnObj, function (solution) {
            return fluid.transform(solution, function(solutionEntry) {
                var options = solutionEntry.options;
                var userRequestedSettings = solutionEntry.settings;
                var defaultSettings,
                    newSettingsResponse,
                    settingKey,
                    oldValue,
                    newValue;

                if (options && options.path) {
                    //we cant simply use require as that'll break if the file doesn't end on .json
                    //var content = fs.readFileSync(options.path);
                    // load the default settings
                    defaultSettings = require(options.path); //JSON.parse(content); //require(options.path);
                    newSettingsResponse = {};
                    // record differences between required and default settings
                    // so that they default settings can be restored
                    fluid.each(userRequestedSettings, function (settingVal, settingKey) {
                        oldValue = fluid.get(defaultSettings, settingKey, getParser);
                        fluid.set(defaultSettings, settingKey, settingVal, setParser);
                        newSettingsResponse[settingKey] = {
                            "oldValue": oldValue,
                            "newValue": settingVal<commit_msg>GPII-71: Fixed some minor issues with set and ensured that it will run properly with ORCA<commit_after>/*!
  GPII JSON Settings Handler

  Copyright 2012 OpenDirective and Raising the Floor - International

  Licensed under the New BSD license. You may not use this file except in
  compliance with this License.

  You may obtain a copy of the License at
  https://github.com/gpii/universal/LICENSE.txt
*/

(function () {

    "use strict";

    var fluid = require("infusion"),
        fs = require("fs"),
        gpii = fluid.registerNamespace("gpii");

    fluid.registerNamespace("gpii.settingsHandlers.JSONSettingsHandler");

    // TODO: When FLUID-4852 is fixed, remove these definitions
    var getParser = {
        parser: {
            parse: fluid.pathUtil.parseEL,
            compose: fluid.pathUtil.composePath
        },
        strategies: [fluid.model.defaultFetchStrategy]
    };

    var setParser = {
        parser: {
            parse: fluid.pathUtil.parseEL,
            compose: fluid.pathUtil.composePath
        },
        strategies: [fluid.model.defaultFetchStrategy, fluid.model.defaultCreatorStrategy]
    };

    gpii.settingsHandlers.JSONSettingsHandler.set = function (profile) {
        var returnObj = fluid.copy(profile);
        return fluid.transform(returnObj, function (solution) {
            return fluid.transform(solution, function(solutionEntry) {
                var options = solutionEntry.options;
                var userRequestedSettings = solutionEntry.settings;
                var defaultSettings,
                    newSettingsResponse,
                    settingKey,
                    oldValue,
                    newValue;

                if (options && options.path) {
                    //we cant simply use require as that'll break if the file doesn't end on .json
                    var content = fs.readFileSync(options.path);
                    defaultSettings = JSON.parse(content); 
                    newSettingsResponse = {};
                    // record differences between required and default settings
                    // so that they default settings can be restored
                    fluid.each(userRequestedSettings, function (settingVal, settingKey) {
                        oldValue = fluid.get(defaultSettings, settingKey, getParser);
                        fluid.set(defaultSettings, settingKey, settingVal, setParser);
                        newSettingsResponse[settingKey] = {
                            "oldValue": oldValue,
                            "newValue": settingVal
{'fraction_non_alphanumeric': 0.07998454404945904, 'fraction_numerical': 0.0034775888717156105, 'mean_word_length': 1.910061832490163, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6815743', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1194, 'n_words': 340}