<commit_before>'use strict;'

var mongoose = require('mongoose'),
    Group = mongoose.model('Group'),

    fs = require('fs'),
    config = require('../../config/config'),

    rest = require('../others/restware'),
    _ = require('lodash'),

    path = require('path'),
    async = require('async');

var serverMain = require('./server-main'),
    licenses = require('./licenses');

var installation;

licenses.getSettingsModel(function(err,settings){
    installation = settings.installation || "local"
})



exports.newGroup = function (group, cb) {

    var object;
    Group.findOne({name:group.name}, function(err,data) {
        if (err || !data) {
            object = new Group(group);
        } else {
            object = _.extend(data, group);
        }
        //create a sync folder under sync_folder
        fs.mkdir(path.join(config.syncDir,group.installation, object.name),function(err){
            if (err && (err.code != 'EEXIST'))
                return cb('Unable to create a group folder in server: '+err);
            else {
                object.save(function (err, data) {
                    cb(err,data);
                })
            }
        });
    })
}

//Load a object
exports.loadObject = function (req, res, next, id) {

    Group.load(id, function (err, object) {
        if (err)
            return next(err)
        if (!object)
            return next(new Error('not found'))
        req.object = object;
        next();
    })
}

//list of objects
exports.index = function (req, res) {

    var criteria = {};<commit_msg>unable to create new group error - fixed<commit_after>'use strict;'

var mongoose = require('mongoose'),
    Group = mongoose.model('Group'),

    fs = require('fs'),
    config = require('../../config/config'),

    rest = require('../others/restware'),
    _ = require('lodash'),

    path = require('path'),
    async = require('async');

var serverMain = require('./server-main'),
    licenses = require('./licenses');

var installation;

licenses.getSettingsModel(function(err,settings){
    installation = settings.installation || "local"
})



exports.newGroup = function (group, cb) {

    var object;
    Group.findOne({name:group.name}, function(err,data) {
        if (err || !data) {
            object = new Group(group);
        } else {
            object = _.extend(data, group);
        }
        //create a sync folder under sync_folder
        fs.mkdir(path.join(config.syncDir,installation, object.name),function(err){
            if (err && (err.code != 'EEXIST'))
                return cb('Unable to create a group folder in server: '+err);
            else {
                object.save(function (err, data) {
                    cb(err,data);
                })
            }
        });
    })
}

//Load a object
exports.loadObject = function (req, res, next, id) {

    Group.load(id, function (err, object) {
        if (err)
            return next(err)
        if (!object)
            return next(new Error('not found'))
        req.object = object;
        next();
    })
}

//list of objects
exports.index = function (req, res) {

    var criteria = {};
{'fraction_non_alphanumeric': 0.15233259282767375, 'fraction_numerical': 0.0, 'mean_word_length': 2.139442231075697, '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': '483363', 'n_tokens_mistral': 917, 'n_tokens_neox': 894, 'n_words': 224}