<commit_before>const BulkModel = require('./profileImport.entity');
const logger = require('./../../../../applogger');
const analysisFeeder = require('./../analysisFeeder/index');
const profileConstant = require('./../../../../config/profileAnalysisConfig');
const ProfileModel = require('./../profile/profile.entity');


const addProfileImport = function(bulkData, fileName, remarks, username) {

    var data = {
        importData: bulkData,
        remarks: remarks,
        importFile: fileName,
        requestedOn: Date.now(),
        requestedBy: username

    };
    let bulk = new BulkModel(data);

    // insert the data into db using promise
    return new Promise((resolve, reject) => {
        bulk.save(function(err, data) {
            if (err) {
                logger.error('userData not added sucessfully' + err);
                reject(err);
            } else {
                analysisFeeder.publishForProfileAnalysis("none", data['_id'],
                    // resolve({ msg: 'Profile data Added successfully' });
                    'POST', profileConstant.SECTION_TO_TOPIC_MAP.PROFILE_IMPORT,
                    function(err, result) {
                        if (err) {
                            reject({ msg: 'Profile data Not Added successfully' });
                        } else {
                            resolve({ msg: 'Profile data Added successfully' });
                        }
                    });
            }
        });
    });
}

const getImportHistory = function() {

    return new Promise((resolve, reject) => {
        BulkModel.find({}, {
            "importFile": 1,
            "remarks": 1,
            "importResult": 1,
            "requestedOn": 1
        }, function(err, data) {
            if (err) {
                reject(err);
            } else {
                resolve(data);
            }
        });
    });
};

const getFailureImportHistory = function(documentId) {
    return new Promise((resolve, reject) => {
        BulkModel.find({
            "_id": documentId
        }, {
            _id: 0,
            importData: {
                $elemMatch: {
                    importStatus: "failure"
                }
            }
        }, function(err, datas) {
            if (err) {
                reject(err);
            } else {
                resolve({ data: datas[0].importData });
            }
        });
    });
};
const createFullProfile = function(username, profileObj) {
    //create full profile from bulkImport
    let profileData = new ProfileModel(profileObj);
    console.log("About to create the full profile ", profileData);
    return new Promise((resolve, reject) => {
        profileData.save(function(err, data) {
            if (err) {
                logger.error('profile Import data not added successfully, error: ', err);
                reject(err);
            } else {
                logger.info('profile Import data added successfully');
                logger.info('Graph Model Creation started')<commit_msg>added logs to track the flow in profileImport Controller<commit_after>const BulkModel = require('./profileImport.entity');
const logger = require('./../../../../applogger');
const analysisFeeder = require('./../analysisFeeder/index');
const profileConstant = require('./../../../../config/profileAnalysisConfig');
const ProfileModel = require('./../profile/profile.entity');


const addProfileImport = function(bulkData, fileName, remarks, username) {

    var data = {
        importData: bulkData,
        remarks: remarks,
        importFile: fileName,
        requestedOn: Date.now(),
        requestedBy: username

    };
    let bulk = new BulkModel(data);

    // insert the data into db using promise
    return new Promise((resolve, reject) => {
        bulk.save(function(err, data) {
            if (err) {
                logger.error('userData not added sucessfully' + err);
                reject(err);
            } else {
                analysisFeeder.publishForProfileAnalysis("none", data['_id'],
                    // resolve({ msg: 'Profile data Added successfully' });
                    'POST', profileConstant.SECTION_TO_TOPIC_MAP.PROFILE_IMPORT,
                    function(err, result) {
                        if (err) {
                            reject({ msg: 'Profile data Not Added successfully' });
                        } else {
                            resolve({ msg: 'Profile data Added successfully' });
                        }
                    });
            }
        });
    });
}

const getImportHistory = function() {

    return new Promise((resolve, reject) => {
        BulkModel.find({}, {
            "importFile": 1,
            "remarks": 1,
            "importResult": 1,
            "requestedOn": 1
        }, function(err, data) {
            if (err) {
                reject(err);
            } else {
                resolve(data);
            }
        });
    });
};

const getFailureImportHistory = function(documentId) {
    return new Promise((resolve, reject) => {
        BulkModel.find({
            "_id": documentId
        }, {
            _id: 0,
            importData: {
                $elemMatch: {
                    importStatus: "failure"
                }
            }
        }, function(err, datas) {
            if (err) {
                reject(err);
            } else {
                resolve({ data: datas[0].importData });
            }
        });
    });
};
const createFullProfile = function(username, profileObj) {
    //create full profile from bulkImport
    logger.info('Inside createFullProfile in profileImportcontrollerfile');
    let profileData = new ProfileModel(profileObj);
    console.log("About to create the full profile ", profileData);
    return new Promise((resolve, reject) => {
        profileData.save(function(err, data) {
            if (err) {
                logger.error('profile Import data not added successfully, error: ', err);
                reject(err);
            } else {
                logger.info('Inside promise of createFullProfile in profileImportcontrollerfile');
                logger.info('profile Import data added successfully');
                logger.info('Graph Model Creation started');
{'fraction_non_alphanumeric': 0.12298612218854682, 'fraction_numerical': 0.001914180890094114, 'mean_word_length': 1.628930817610063, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 11, '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': '4736586', 'n_tokens_mistral': 1565, 'n_tokens_neox': 1499, 'n_words': 381}