<commit_before>/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/**
 * Checks if provided input is valid against RegEx input.
 *
 * @param regExp Regular expression
 * @param inputString Input string to check
 * @returns {boolean} Returns true if input matches RegEx
 */
function inputIsValid(regExp, inputString) {
    return regExp.test(inputString);
}

/**
 * Checks if an email address has the valid format or not.
 *
 * @param email Email address
 * @returns {boolean} true if email has the valid format, otherwise false.
 */
function emailIsValid(email) {
    var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    return regExp.test(email);
}

var notifierTypeConstants = {
    "LOCAL": "1",
    "GCM": "2"
};
// Constants to define platform types available
var platformTypeConstants = {
    "ANDROID": "android",
    "IOS": "ios",
    "WINDOWS": "windows"
};

var responseCodes = {
    "CREATED": "Created",
    "SUCCESS": "201",
    "INTERNAL_SERVER_ERROR": "Internal Server Error"
};

var configParams = {
    "NOTIFIER_TYPE": "notifierType",
    "NOTIFIER_FREQUENCY": "notifierFrequency",
    "GCM_API_KEY": "gcmAPIKey",
    "GCM_SENDER_ID": "gcmSenderId",
    "ANDROID_EULA": "androidEula",
    "IOS_EULA": "iosEula",
    "CONFIG_COUNTRY": "configCountry",
    "CONFIG_STATE": "configState",
    "CONFIG_LOCALITY": "configLocality",
    "CONFIG_ORGANIZATION": "configOrganization",
    "CONFIG_ORGANIZATION_UNIT": "configOrganizationUnit",
    "MDM_CERT_PASSWORD": "<PASSWORD>",
    "MDM_CERT_TOPIC_ID": "MDMCertTopicID",
    "APNS_CERT_PASSWORD": "<PASSWORD>",
    "MDM_CERT": "MDMCert",
    "MDM_CERT_NAME": "MDMCertName",
    "APNS_CERT": "APNSCert",
    "APNS_CERT_NAME": "APNSCertName",
    "ORG_DISPLAY_NAME": "organizationDisplayName",
    "GENERAL_EMAIL_HOST": "emailHost",
    "GENERAL_EMAIL_PORT": "emailPort",
    "GENERAL_EMAIL_USERNAME": "emailUsername",
    "GENERAL_EMAIL_PASSWORD": "<PASSWORD>",
    "GENERAL_EMAIL_SENDER_ADDRESS": "emailSender",
    "GENERAL_EMAIL_TEMPLATE": "emailTemplate",
    "COMMON_NAME": "commonName",
    "KEYSTORE_PASSWORD": "<PASSWORD>",
    "PRIVATE_KEY_PASSWORD": "<PASSWORD>",
    "BEFORE_EXPIRE": "beforeExpire",
    "AFTER_EXPIRE": "afterExpire",
    "WINDOWS_EULA": "windowsLicense"
};

$(document).ready(function () {
    $("#gcm-inputs").hide();
    tinymce.init({
        selector: "textarea",
        theme: "modern",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime image table contextmenu paste"
        ],
        toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });

    var getAndroidConfigAPI = "/mdm-android-agent/configuration";
    var getGeneralConfigAPI = "/mdm-admin/configuration";
    var getIosConfigAPI = "/ios/configuration";
    var getWindowsConfigAPI = "/mdm-windows-agent/services/configuration";

    /**
     * Following requests would execute
     * on page load event of tenant configuration page in WSO2 EMM Console.
     * Upon receiving the response, the parameters will be set to the fields,
     * in case those configurations are already set.
     */
    invokerUtil.get(
        getAndroidConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["NOTIFIER_TYPE"]){
                        $("#android-config-notifier").val(config.value);
                        if(config.value != notifierTypeConstants["GCM"] ) {
                            $("#gcm-inputs").hide();
                        }else{
                            $("#gcm-inputs").show();
                        }
                    } else if(config.name == configParams["NOTIFIER_FREQUENCY"]){
                        $("input#android-config-notifier-frequency").val(config.value);
                    } else if(config.name == configParams["GCM_API_KEY"]){
                        $("input#android-config-gcm-api-key").val(config.value);
                    } else if(config.name == configParams["GCM_SENDER_ID"]){
                        $("input#android-config-gcm-sender-id").val(config.value);
                    } else if(config.name == configParams["ANDROID_EULA"]){
                        $("#android-eula").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );

    invokerUtil.get(
        getGeneralConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["GENERAL_EMAIL_HOST"]){
                        $("input#email-config-host").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_PORT"]){
                        $("input#email-config-port").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_USERNAME"]){
                        $("input#email-config-username").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_PASSWORD"]){
                        $("input#email-config-password").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_SENDER_ADDRESS"]){
                        $("input#email-config-sender-email").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_TEMPLATE"]){
                        $("input#email-config-template").val(config.value);
                    } else if(config.name == configParams["NOTIFIER_FREQUENCY"]){
                        $("input#monitoring-config-frequency").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );

    invokerUtil.get(
        getIosConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["CONFIG_COUNTRY"]){
                        $("input#ios-config-country").val(config.value);
                    } else if(config.name == configParams["CONFIG_STATE"]){
                        $("input#ios-config-state").val(config.value);
                    } else if(config.name == configParams["CONFIG_LOCALITY"]){
                        $("input#ios-config-locality").val(config.value);
                    } else if(config.name == configParams["CONFIG_ORGANIZATION"]){
                        $("input#ios-config-organization").val(config.value);
                    } else if(config.name == configParams["CONFIG_ORGANIZATION_UNIT"]){
                        $("input#ios-config-organization-unit").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_PASSWORD"]){
                        $("input#ios-config-mdm-certificate-password").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_TOPIC_ID"]){
                        $("input#ios-config-mdm-certificate-topic-id").val(config.value);
                    } else if(config.name == configParams["APNS_CERT_PASSWORD"]){
                        $("input#ios-config-apns-certificate-password").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_NAME"]){
                        $("#mdm-cert-file-name").html(config.value);
                    } else if(config.name == configParams["APNS_CERT_NAME"]){
                        $("#apns-cert-file-name").html(config.value);
                    } else if(config.name == configParams["ORG_DISPLAY_NAME"]){
                        $("input#ios-org-display-name").val(config.value);
                    } else if(config.name == configParams["IOS_EULA"]){
                        $("#ios-eula").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );

    invokerUtil.get(
        getWindowsConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["NOTIFIER_FREQUENCY"]){
                        $("input#windows-config-notifier-frequency").val(config.value);
                    } else if(config.name == configParams["COMMON_NAME"]){
                        $("input#windows-config-mdm-cn").val(config.value);
                    } else if(config.name == configParams["KEYSTORE_PASSWORD"]){
                        $("input#windows-config-mdm-keystore-password").val(config.value);
                    } else if(config.name == configParams["PRIVATE_KEY_PASSWORD"]){
                        $("input#windows-config-mdm-pk-password").val(config.value);
                    } else if(config.name == configParams["BEFORE_EXPIRE"]){
                        $("input#windows-config-before-expire").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_NAME"]){
                        $("#windows-mdm-cert-file-name").html(config.value);
                    } else if(config.name == configParams["AFTER_EXPIRE"]){
                        $("input#windows-config-after-expire").val(config.value);
                    } else if(config.name == configParams["WINDOWS_EULA"]){
                        $("#windows-eula").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );


    $("select.select2[multiple=multiple]").select2({
        tags : true
    });

    $("#android-config-notifier").change(function() {
        var notifierType = $("#android-config-notifier").find("option:selected").attr("value");
        if(notifierType  != notifierTypeConstants["GCM"] ) {
            $("#gcm-inputs").hide();
            $("#local-inputs").show();
        }else{
            $("#local-inputs").hide();
            $("#gcm-inputs").show();
        }
    });
    /**
     * Following click function would execute
     * when a user clicks on "Save" button
     * on Android tenant configuration page in WSO2 EMM Console.
     */
    $("button#save-android-btn").click(function() {
        var notifierType = $("#android-config-notifier").find("option:selected").attr("value");
        var notifierFrequency = $("input#android-config-notifier-frequency").val();
        var gcmAPIKey = $("input#android-config-gcm-api-key").val();
        var gcmSenderId = $("input#android-config-gcm-sender-id").val();
        var androidLicense = tinymce.get('android-eula').getContent();

        var errorMsgWrapper = "#android-config-error-msg";
        var errorMsg = "#android-config-error-msg span";
        if (!notifierFrequency) {
            $(errorMsg).text("Notifier frequency is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!$.isNumeric(notifierFrequency)) {
            $(errorMsg).text("Provided notifier frequency is invalid. Please check.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (notifierType == notifierTypeConstants["GCM"] && !gcmAPIKey) {
            $(errorMsg).text("GCM API Key is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (notifierType == notifierTypeConstants["GCM"] && !gcmSenderId) {
            $(errorMsg).text("GCM Sender ID is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else {

            var addConfigFormData = {};
            var configList = new Array();

            var type = {
                "name": configParams["NOTIFIER_TYPE"],
                "value": notifierType,
                "contentType": "text"
            };

            var frequency = {
                "name": configParams["NOTIFIER_FREQUENCY"],
                "value": notifierFrequency,
                "contentType": "text"
            };

            var gcmKey = {
                "name": configParams["GCM_API_KEY"],
                "value": gcmAPIKey,
                "contentType": "text"
            };

            var gcmId = {
                "name": configParams["GCM_SENDER_ID"],
                "value": gcmSenderId,
                "contentType": "text"
            };

            var androidEula = {
                "name": configParams["ANDROID_EULA"],
                "value": androidLicense,
                "contentType": "text"
            };

            configList.push(type);
            configList.push(frequency);
            configList.push(androidEula);
            if (notifierType == notifierTypeConstants["GCM"]) {
                configList.push(gcmKey);
                configList.push(gcmId);
            }

            addConfigFormData.type = platformTypeConstants["ANDROID"];
            addConfigFormData.configuration = configList;

            var addConfigAPI = "/mdm-android-agent/configuration";

            invokerUtil.post(
                addConfigAPI,
                addConfigFormData,
                function (data) {
                    if (data.responseCode == responseCodes["CREATED"]) {
                        $("#config-save-form").addClass("hidden");
                        $("#record-created-msg").removeClass("hidden");
                    } else if (data == 500) {
                        $(errorMsg).text("Exception occurred at backend.");
                    } else if (data == 403) {
                        $(errorMsg).text("Action was not permitted.");
                    } else {
                        $(errorMsg).text("An unexpected error occurred.");
                    }

                    $(errorMsgWrapper).removeClass("hidden");
                }, function () {
                    $(errorMsg).text("An unexpected error occurred.");
                    $(errorMsgWrapper).removeClass("hidden");
                }
            );
        }
    });

    /**
     * Following click function would execute
     * when a user clicks on "Save" button
     * on General tenant configuration page in WSO2 EMM Console.
     */
    $("button#save-general-btn").click(function() {
        var notifierFrequency = $("input#monitoring-config-frequency").val();
        var emailHost = $("input#email-config-host").val();
        var emailPort = $("input#email-config-port").val();
        var emailUsername = $("input#email-config-username").val();
        var emailPassword = $("input#email-config-password").val();
        var emailSenderAddress = $("input#email-config-sender-email").val();
        var emailTemplate = $("input#email-config-template").val();

        var errorMsgWrapper = "#email-config-error-msg";
        var errorMsg = "#email-config-error-msg span";
        if (!emailHost) {
            $(errorMsg).text("Email Host is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!notifierFrequency) {
            $(errorMsg).text("Monitoring frequency is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!$.isNumeric(notifierFrequency)) {
            $(errorMsg).text("Provided monitoring frequency is invalid. It must be a number.");
            $(errorMsgWrapper).removeClass("hidden");
        }else if (!emailPort) {
            $(errorMsg).text("Email Port is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!emailUsername) {
            $(errorMsg).text("Username is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!emailPassword) {
            $(errorMsg).text("Password is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!emailSenderAddress) {
            $(errorMsg).text("Sender Email Address is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!emailIsValid(emailSenderAddress)) {
            $(errorMsg).text("Provided sender email is invalid. Please check.");
            $(errorMsgWrapper).removeClass("hidden");
        } else {

            var addConfigFormData = {};
            var configList = new Array();

            var monitorFrequency = {
                "name": configParams["NOTIFIER_FREQUENCY"],
                "value": notifierFrequency,
                "contentType": "text"
            };

            var host = {
                "name": configParams["GENERAL_EMAIL_HOST"],
                "value": emailHost,
                "contentType": "text"
            };

            var port = {
                "name": configParams["GENERAL_EMAIL_PORT"],
                "value": emailPort,
                "contentType": "text"
            };

            var username = {
                "name": configParams["GENERAL_EMAIL_USERNAME"],
                "value": emailUsername,
                "contentType": "text"
            };

            var password = {
                "name": configParams["GENERAL_EMAIL_PASSWORD"],
                "value": emailPassword,
                "contentType": "text"
            };

            var sender = {
                "name": configParams["GENERAL_EMAIL_SENDER_ADDRESS"],
                "value": emailSenderAddress,
                "contentType": "text"
            };

            var template = {
                "name": configParams["GENERAL_EMAIL_TEMPLATE"],
                "value": emailTemplate,
                "contentType": "text"
            };

            configList.push(monitorFrequency);
            configList.push(host);
            configList.push(port);
            configList.push(username);
            configList.push(password);
            configList.push(sender);
            configList.push(template);

            addConfigFormData.configuration = configList;

            var addConfigAPI = "/mdm-admin/configuration";

            invokerUtil.post(
                addConfigAPI,
                addConfigFormData,
                function (data) {
                    if (data.statusCode == responseCodes["SUCCESS"]) {
                        $("#config-save-form").addClass("hidden");
                        $("#record-created-msg").removeClass("hidden");
                    } else if (data == 500) {
                        $(errorMsg).text("Exception occurred at backend.");
                    } else if (data == 403) {
                        $(errorMsg).text("Action was not permitted.");
                    } else {
                        $(errorMsg).text("An unexpected error occurred.");
                    }<commit_msg>General config UI fix<commit_after>/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/**
 * Checks if provided input is valid against RegEx input.
 *
 * @param regExp Regular expression
 * @param inputString Input string to check
 * @returns {boolean} Returns true if input matches RegEx
 */
function inputIsValid(regExp, inputString) {
    return regExp.test(inputString);
}

/**
 * Checks if an email address has the valid format or not.
 *
 * @param email Email address
 * @returns {boolean} true if email has the valid format, otherwise false.
 */
function emailIsValid(email) {
    var regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
    return regExp.test(email);
}

var notifierTypeConstants = {
    "LOCAL": "1",
    "GCM": "2"
};
// Constants to define platform types available
var platformTypeConstants = {
    "ANDROID": "android",
    "IOS": "ios",
    "WINDOWS": "windows"
};

var responseCodes = {
    "CREATED": "Created",
    "SUCCESS": "201",
    "INTERNAL_SERVER_ERROR": "Internal Server Error"
};

var configParams = {
    "NOTIFIER_TYPE": "notifierType",
    "NOTIFIER_FREQUENCY": "notifierFrequency",
    "GCM_API_KEY": "gcmAPIKey",
    "GCM_SENDER_ID": "gcmSenderId",
    "ANDROID_EULA": "androidEula",
    "IOS_EULA": "iosEula",
    "CONFIG_COUNTRY": "configCountry",
    "CONFIG_STATE": "configState",
    "CONFIG_LOCALITY": "configLocality",
    "CONFIG_ORGANIZATION": "configOrganization",
    "CONFIG_ORGANIZATION_UNIT": "configOrganizationUnit",
    "MDM_CERT_PASSWORD": "<PASSWORD>",
    "MDM_CERT_TOPIC_ID": "MDMCertTopicID",
    "APNS_CERT_PASSWORD": "<PASSWORD>",
    "MDM_CERT": "MDMCert",
    "MDM_CERT_NAME": "MDMCertName",
    "APNS_CERT": "APNSCert",
    "APNS_CERT_NAME": "APNSCertName",
    "ORG_DISPLAY_NAME": "organizationDisplayName",
    "GENERAL_EMAIL_HOST": "emailHost",
    "GENERAL_EMAIL_PORT": "emailPort",
    "GENERAL_EMAIL_USERNAME": "emailUsername",
    "GENERAL_EMAIL_PASSWORD": "<PASSWORD>",
    "GENERAL_EMAIL_SENDER_ADDRESS": "emailSender",
    "GENERAL_EMAIL_TEMPLATE": "emailTemplate",
    "COMMON_NAME": "commonName",
    "KEYSTORE_PASSWORD": "<PASSWORD>",
    "PRIVATE_KEY_PASSWORD": "<PASSWORD>",
    "BEFORE_EXPIRE": "beforeExpire",
    "AFTER_EXPIRE": "afterExpire",
    "WINDOWS_EULA": "windowsLicense"
};

$(document).ready(function () {
    $("#gcm-inputs").hide();
    tinymce.init({
        selector: "textarea",
        theme: "modern",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime image table contextmenu paste"
        ],
        toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });

    var getAndroidConfigAPI = "/mdm-android-agent/configuration";
    var getGeneralConfigAPI = "/mdm-admin/configuration";
    var getIosConfigAPI = "/ios/configuration";
    var getWindowsConfigAPI = "/mdm-windows-agent/services/configuration";

    /**
     * Following requests would execute
     * on page load event of tenant configuration page in WSO2 EMM Console.
     * Upon receiving the response, the parameters will be set to the fields,
     * in case those configurations are already set.
     */
    invokerUtil.get(
        getAndroidConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["NOTIFIER_TYPE"]){
                        $("#android-config-notifier").val(config.value);
                        if(config.value != notifierTypeConstants["GCM"] ) {
                            $("#gcm-inputs").hide();
                        }else{
                            $("#gcm-inputs").show();
                        }
                    } else if(config.name == configParams["NOTIFIER_FREQUENCY"]){
                        $("input#android-config-notifier-frequency").val(config.value);
                    } else if(config.name == configParams["GCM_API_KEY"]){
                        $("input#android-config-gcm-api-key").val(config.value);
                    } else if(config.name == configParams["GCM_SENDER_ID"]){
                        $("input#android-config-gcm-sender-id").val(config.value);
                    } else if(config.name == configParams["ANDROID_EULA"]){
                        $("#android-eula").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );

    invokerUtil.get(
        getGeneralConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["NOTIFIER_FREQUENCY"]){
                        $("input#monitoring-config-frequency").val(config.value);
                    }
                    /*if(config.name == configParams["GENERAL_EMAIL_HOST"]){
                        $("input#email-config-host").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_PORT"]){
                        $("input#email-config-port").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_USERNAME"]){
                        $("input#email-config-username").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_PASSWORD"]){
                        $("input#email-config-password").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_SENDER_ADDRESS"]){
                        $("input#email-config-sender-email").val(config.value);
                    } else if(config.name == configParams["GENERAL_EMAIL_TEMPLATE"]){
                        $("input#email-config-template").val(config.value);
                    }*/
                }
            }

        }, function () {

        }
    );

    invokerUtil.get(
        getIosConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["CONFIG_COUNTRY"]){
                        $("input#ios-config-country").val(config.value);
                    } else if(config.name == configParams["CONFIG_STATE"]){
                        $("input#ios-config-state").val(config.value);
                    } else if(config.name == configParams["CONFIG_LOCALITY"]){
                        $("input#ios-config-locality").val(config.value);
                    } else if(config.name == configParams["CONFIG_ORGANIZATION"]){
                        $("input#ios-config-organization").val(config.value);
                    } else if(config.name == configParams["CONFIG_ORGANIZATION_UNIT"]){
                        $("input#ios-config-organization-unit").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_PASSWORD"]){
                        $("input#ios-config-mdm-certificate-password").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_TOPIC_ID"]){
                        $("input#ios-config-mdm-certificate-topic-id").val(config.value);
                    } else if(config.name == configParams["APNS_CERT_PASSWORD"]){
                        $("input#ios-config-apns-certificate-password").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_NAME"]){
                        $("#mdm-cert-file-name").html(config.value);
                    } else if(config.name == configParams["APNS_CERT_NAME"]){
                        $("#apns-cert-file-name").html(config.value);
                    } else if(config.name == configParams["ORG_DISPLAY_NAME"]){
                        $("input#ios-org-display-name").val(config.value);
                    } else if(config.name == configParams["IOS_EULA"]){
                        $("#ios-eula").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );

    invokerUtil.get(
        getWindowsConfigAPI,

        function (data) {

            if (data != null && data.configuration != null) {
                for (var i = 0; i < data.configuration.length; i++) {
                    var config = data.configuration[i];
                    if(config.name == configParams["NOTIFIER_FREQUENCY"]){
                        $("input#windows-config-notifier-frequency").val(config.value);
                    } else if(config.name == configParams["COMMON_NAME"]){
                        $("input#windows-config-mdm-cn").val(config.value);
                    } else if(config.name == configParams["KEYSTORE_PASSWORD"]){
                        $("input#windows-config-mdm-keystore-password").val(config.value);
                    } else if(config.name == configParams["PRIVATE_KEY_PASSWORD"]){
                        $("input#windows-config-mdm-pk-password").val(config.value);
                    } else if(config.name == configParams["BEFORE_EXPIRE"]){
                        $("input#windows-config-before-expire").val(config.value);
                    } else if(config.name == configParams["MDM_CERT_NAME"]){
                        $("#windows-mdm-cert-file-name").html(config.value);
                    } else if(config.name == configParams["AFTER_EXPIRE"]){
                        $("input#windows-config-after-expire").val(config.value);
                    } else if(config.name == configParams["WINDOWS_EULA"]){
                        $("#windows-eula").val(config.value);
                    }
                }
            }

        }, function () {

        }
    );


    $("select.select2[multiple=multiple]").select2({
        tags : true
    });

    $("#android-config-notifier").change(function() {
        var notifierType = $("#android-config-notifier").find("option:selected").attr("value");
        if(notifierType  != notifierTypeConstants["GCM"] ) {
            $("#gcm-inputs").hide();
            $("#local-inputs").show();
        }else{
            $("#local-inputs").hide();
            $("#gcm-inputs").show();
        }
    });
    /**
     * Following click function would execute
     * when a user clicks on "Save" button
     * on Android tenant configuration page in WSO2 EMM Console.
     */
    $("button#save-android-btn").click(function() {
        var notifierType = $("#android-config-notifier").find("option:selected").attr("value");
        var notifierFrequency = $("input#android-config-notifier-frequency").val();
        var gcmAPIKey = $("input#android-config-gcm-api-key").val();
        var gcmSenderId = $("input#android-config-gcm-sender-id").val();
        var androidLicense = tinymce.get('android-eula').getContent();

        var errorMsgWrapper = "#android-config-error-msg";
        var errorMsg = "#android-config-error-msg span";
        if (!notifierFrequency) {
            $(errorMsg).text("Notifier frequency is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!$.isNumeric(notifierFrequency)) {
            $(errorMsg).text("Provided notifier frequency is invalid. Please check.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (notifierType == notifierTypeConstants["GCM"] && !gcmAPIKey) {
            $(errorMsg).text("GCM API Key is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (notifierType == notifierTypeConstants["GCM"] && !gcmSenderId) {
            $(errorMsg).text("GCM Sender ID is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else {

            var addConfigFormData = {};
            var configList = new Array();

            var type = {
                "name": configParams["NOTIFIER_TYPE"],
                "value": notifierType,
                "contentType": "text"
            };

            var frequency = {
                "name": configParams["NOTIFIER_FREQUENCY"],
                "value": notifierFrequency,
                "contentType": "text"
            };

            var gcmKey = {
                "name": configParams["GCM_API_KEY"],
                "value": gcmAPIKey,
                "contentType": "text"
            };

            var gcmId = {
                "name": configParams["GCM_SENDER_ID"],
                "value": gcmSenderId,
                "contentType": "text"
            };

            var androidEula = {
                "name": configParams["ANDROID_EULA"],
                "value": androidLicense,
                "contentType": "text"
            };

            configList.push(type);
            configList.push(frequency);
            configList.push(androidEula);
            if (notifierType == notifierTypeConstants["GCM"]) {
                configList.push(gcmKey);
                configList.push(gcmId);
            }

            addConfigFormData.type = platformTypeConstants["ANDROID"];
            addConfigFormData.configuration = configList;

            var addConfigAPI = "/mdm-android-agent/configuration";

            invokerUtil.post(
                addConfigAPI,
                addConfigFormData,
                function (data) {
                    if (data.responseCode == responseCodes["CREATED"]) {
                        $("#config-save-form").addClass("hidden");
                        $("#record-created-msg").removeClass("hidden");
                    } else if (data == 500) {
                        $(errorMsg).text("Exception occurred at backend.");
                    } else if (data == 403) {
                        $(errorMsg).text("Action was not permitted.");
                    } else {
                        $(errorMsg).text("An unexpected error occurred.");
                    }

                    $(errorMsgWrapper).removeClass("hidden");
                }, function () {
                    $(errorMsg).text("An unexpected error occurred.");
                    $(errorMsgWrapper).removeClass("hidden");
                }
            );
        }
    });

    /**
     * Following click function would execute
     * when a user clicks on "Save" button
     * on General tenant configuration page in WSO2 EMM Console.
     */
    $("button#save-general-btn").click(function() {
        var notifierFrequency = $("input#monitoring-config-frequency").val();
        /*var emailHost = $("input#email-config-host").val();
        var emailPort = $("input#email-config-port").val();
        var emailUsername = $("input#email-config-username").val();
        var emailPassword = $("input#email-config-password").val();
        var emailSenderAddress = $("input#email-config-sender-email").val();
        var emailTemplate = $("input#email-config-template").val();*/

        var errorMsgWrapper = "#email-config-error-msg";
        var errorMsg = "#email-config-error-msg span";

        if (!notifierFrequency) {
            $(errorMsg).text("Monitoring frequency is a required field. It cannot be empty.");
            $(errorMsgWrapper).removeClass("hidden");
        } else if (!$.isNumeric(notifierFrequency)) {
            $(errorMsg).text("Provided monitoring frequency is invalid. It must be a number.");
            $(errorMsgWrapper).removeClass("hidden");
        } else {

            var addConfigFormData = {};
            var configList = new Array();

            var monitorFrequency = {
                "name": configParams["NOTIFIER_FREQUENCY"],
                "value": notifierFrequency,
                "contentType": "text"
            };

            /*if (!emailHost) {
             $(errorMsg).text("Email Host is a required field. It cannot be empty.");
             //$(errorMsgWrapper).removeClass("hidden");
             } else if (!notifierFrequency) {
             $(errorMsg).text("Monitoring frequency is a required field. It cannot be empty.");
             $(errorMsgWrapper).removeClass("hidden");
             } else if (!$.isNumeric(notifierFrequency)) {
             $(errorMsg).text("Provided monitoring frequency is invalid. It must be a number.");
             $(errorMsgWrapper).removeClass("hidden");
             }else if (!emailPort) {
             $(errorMsg).text("Email Port is a required field. It cannot be empty.");
             //$(errorMsgWrapper).removeClass("hidden");
             } else if (!emailUsername) {
             $(errorMsg).text("Username is a required field. It cannot be empty.");
             //$(errorMsgWrapper).removeClass("hidden");
             } else if (!emailPassword) {
             $(errorMsg).text("Password is a required field. It cannot be empty.");
             //$(errorMsgWrapper).removeClass("hidden");
             } else if (!emailSenderAddress) {
             $(errorMsg).text("Sender Email Address is a required field. It cannot be empty.");
             //$(errorMsgWrapper).removeClass("hidden");
             } else if (!emailIsValid(emailSenderAddress)) {
             $(errorMsg).text("Provided sender email is invalid. Please check.");
             //$(errorMsgWrapper).removeClass("hidden");
             } */

            /*var host = {
             "name": configParams["GENERAL_EMAIL_HOST"],
             "value": emailHost,
             "contentType": "text"
             };

             var port = {
             "name": configParams["GENERAL_EMAIL_PORT"],
             "value": emailPort,
             "contentType": "text"
             };

             var username = {
             "name": configParams["GENERAL_EMAIL_USERNAME"],
             "value": emailUsername,
             "contentType": "text"
             };

             var password = {
             "name": configParams["GENERAL_EMAIL_PASSWORD"],
             "value": emailPassword,
             "contentType": "text"
             };

             var sender = {
             "name": configParams["GENERAL_EMAIL_SENDER_ADDRESS"],
             "value": emailSenderAddress,
             "contentType": "text"
             };

             var template = {
             "name": configParams["GENERAL_EMAIL_TEMPLATE"],
             "value": emailTemplate,
             "contentType": "text"
             };*/

            configList.push(monitorFrequency);
            /*configList.push(host);
             configList.push(port);
             configList.push(username);
             configList.push(password);
             configList.push(sender);
             configList.push(template);*/

            addConfigFormData.configuration = configList;

            var addConfigAPI = "/mdm-admin/configuration";

            invokerUtil.post(
                addConfigAPI,
                addConfigFormData,
                function (data) {
                    if (data.statusCode == responseCodes["SUCCESS"]) {
                        $("#config-save-form").addClass("hidden");
                        $("#record-created-msg").removeClass("hidden");
                    } else if (data == 500) {
                        $(errorMsg).text("Exception occurred at backend.");
                    } else if (data == 403) {
                        $(errorMsg).text("Action was not permitted.");
                    } else {
                        $(errorMsg).text("An unexpected error occurred.");
                    }
{'fraction_non_alphanumeric': 0.13907301209006728, 'fraction_numerical': 0.0019363968123929395, 'mean_word_length': 1.9130749204512583, 'pattern_counts': {'":': 150, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6277284', 'n_tokens_mistral': 10974, 'n_tokens_neox': 10557, 'n_words': 2108}