Ejemplo n.º 1
0
    _.each( samples, function( sample ) {
        var category, subcategory;

        category = categories[ sample.category ] = categories[ sample.category ] || {
            name: sample.category,
            subcategories: {}
        };

        subcategory = category.subcategories[ sample.subcategory ] = category.subcategories[ sample.subcategory ] || {
            name: sample.subcategory,
            samples: []
        };

        var foundPredefinedCategory = _.find( validCategories, function( category ) {
            return category.name == sample.category;
        } );
        if ( !foundPredefinedCategory )
            throw 'Could not find predefined category "' + sample.category + '" in sample: ' + sample.name;

        var foundPredefinedSubcategory = _.find( foundPredefinedCategory.subcategories, function( subcategory ) {
            return subcategory == sample.subcategory;
        } );
        if ( !foundPredefinedSubcategory )
            throw 'Could not find predefined subcategory "' + sample.subcategory + '" in sample: ' + sample.name;

        subcategory.samples.push( sample );
    } );
Ejemplo n.º 2
0
 }).then(function (responseInfo) {
     expect(responseInfo.statusCode).to.equal(200);
     expect(responseInfo.responseObject.length).to.equal(3); // there should be 3 todos now
     expect(_.find(responseInfo.responseObject, { title: 'abc' })).to.not.exist; // sanity check
     expect(_.find(responseInfo.responseObject, { title: 'go round mums' })).to.exist;
     expect(_.find(responseInfo.responseObject, { title: 'get Liz back' })).to.exist;
     expect(_.find(responseInfo.responseObject, { title: 'sort life out' })).to.exist;
     done()
   }).catch(function(err) {
Ejemplo n.º 3
0
        socket.on('loginChatRoom', function (_message, oppositename) {
                var message = JSON.parse(_message);
                // if this socket is already connected,
                // send a failed login message

                if (_.findIndex(chatrooms, { id: message.consult }) !== -1) {

                        var currentRoom = _.find(chatrooms, { id: message.consult });
                        var cusers = currentRoom.users;

                        if (_.findIndex(cusers, { name: message.name, socket : socket.id }) !== -1) {
                            //socket.emit('login_error', 'You are already connected.');
                            //return;
                        } else if (_.findIndex(cusers, { name: message.name }) !== -1){
                                var currentUser = _.find(cusers, { name: message.name });
                                currentUser.socket = socket.id;
                                return;
                        } else {
                                fuser= _.find(users, { name: message.name });
                                cusers.push(fuser);
                        }

                } else {
                        var cusers = [];
                        fuser= _.find(users, { name: message.name });
                        cusers.push(fuser);
                        chatrooms.push({
                                id: message.consult,
                                users: cusers,
                                vc: true
                        });

                }

                var res= true;
                if(cusers.length < 2) {
                        res = false;
                }

                for(index in cusers){
                        cuser = cusers[index];
                        opplive = false;
                        if (_.findIndex(users, { name: oppositename }) !== -1) {
                                opplive = true;
                        }

                        try{
                                io.to(cuser.socket).emit('chatOpposite', res, opplive) ;
                        } catch(e) {

                        }
                }
                console.log("________________users start_____________________");
                console.log(cusers);
                console.log("________________users end_____________________");
                console.log(message.name + ' logged in to ' + message.consult + " chat room.");
        });
Ejemplo n.º 4
0
  socket.on('sendMessage', function (name, message) {
    var currentUser = _.find(users, { socket: socket.id });
    if (!currentUser) { return; }

    var contact = _.find(users, { name: name });
    if (!contact) { return; }
    
    io.to(contact.socket)
      .emit('messageReceived', currentUser.name, message);
  });
Ejemplo n.º 5
0
        socket.on('loginVideoRoom', function (_message) {

                var message = JSON.parse(_message);
                // if this socket is already connected,
                // send a failed login message

                if (_.findIndex(rooms, { id: message.consult }) !== -1) {

                        var currentRoom = _.find(rooms, { id: message.consult });
                        var cusers = currentRoom.users;

                        if (_.findIndex(cusers, { name: message.name, socket : socket.id }) !== -1) {
                            //socket.emit('login_error', 'You are already connected.');
                            //return;

                        } else if (_.findIndex(cusers, { name: message.name }) !== -1){
                                var currentUser = _.find(cusers, { name: message.name });
                                currentUser.socket = socket.id;
                            //return;
                        } else {
                                fuser= _.find(users, { name: message.name });
                                cusers.push(fuser);
                        }

                } else {
                        var cusers = [];
                        fuser= _.find(users, { name: message.name });
                        cusers.push(fuser);
                        rooms.push({
                                id: message.consult,
                                users: cusers
                        });
                }

                var res= true;
                if(cusers.length < 2)
                        res = false;

                try{
                        socket.emit('login_successful', res);
                } catch(e) {
                        console.log("login-catch");
                }
                console.log("________________users start_____________________");
                console.log(cusers);
                console.log("________________users end_____________________");
                console.log(message.name + ' logged in to ' + message.consult + " room.");
        });
Ejemplo n.º 6
0
            function*(){
                var url = 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='
                    + beaver.config.oath.Facebook.clientId + "&client_secret=" + beaver.config.oath.Facebook.clientSecret;

                var response = yield Q.ninvoke(
                    superagent.get(url)
                        .set('Accept', 'application/json'), 'end');

                var appAccessToken = response.text && response.text.replace("access_token=", "");

                var testUserResponse = yield Q.ninvoke(
                    superagent.get("https://graph.facebook.com/" + beaver.config.oath.Facebook.clientId
                            + "/accounts/test-users?access_token="+appAccessToken)
                        .set('Accept', 'application/json'), 'end');

                var testUser = _.find(testUserResponse.body && testUserResponse.body.data, function(elem){
                    return elem.id == beaver.config.oath.Facebook.testUser.userId;
                });

                expect(testUser).not.toBe(null);

                //validate access token
                var validStatus = yield beaver.modules.User.validateFacebookAccessToken(
                    beaver.config.oath.Facebook.testUser.userId, testUser.access_token
                );
                expect(validStatus).toBe(true);

                done();
            })()
Ejemplo n.º 7
0
    this.get_source_by_query_purpose = function(query_purpose) {
        var source = _.find(config.query_setup, function(q) {
            return (q.purpose == query_purpose);
        });

        return source;
    };
Ejemplo n.º 8
0
    this.get_email_templating_engine = function(engine){
        var engine_info = _.find(config.email_templating_engine, function(template_info) {
            return template_info.name == engine;
        });

        return engine_info;
    };
    zoneModel.findZoneWithin30Meters(data, function (err, result) {
        if (err || !result) {
            deferred.reject(err);
            return;
        }

        if (result.length) {
            var zone = result[0];

            var activityAlreadyExists = _.find(zone.activities, {
                'activity': data.activity
            });

            if (activityAlreadyExists) {
                zoneModel.setActivityActiveInZone(zone._id, data.activity, function (err) {
                    if (err) {
                        deferred.reject(err);
                        return;
                    }
                    deferred.resolve();
                });
            } else {
                var newActivityAndZone = zoneModel.create(data);

                zoneModel.addActivityToZone(zone._id, newActivityAndZone, function (err) {
                    if (err) {
                        deferred.reject(err);
                        return;
                    }
                    deferred.resolve();
                });
            }
        }
    });
Ejemplo n.º 10
0
    this.get_connection_string = function(){
        var e = config.env;
        var mongo_address = _.find(config.mongo_address, function(env) {
            return env.env == e;
        });

        return  "mongodb://" + mongo_address.ip + "/" + config.db + "?poolSize=4";
    };
Ejemplo n.º 11
0
exports.delete = function (req, res) {
    var id = req.param('id');
    _.pull(customers, _.find(customers, {id: id}));
    res.json({
		success: 'OK',
        message: 'A customer is deleted'
    });
};
Ejemplo n.º 12
0
    this.get_mongo_host_db = function (){
        var e = config.env;
        var address = _.find(config.mongo_address, function(env) {
            return env.env == e;
        });

        return address.db;
    };
Ejemplo n.º 13
0
var getTransValueForAddress = function(transaction, btcAddress) {
    var outArray = transaction.x.out;
    var outTx = (_.find(outArray, function(outTx) {
        return outTx.addr === btcAddress;
    }));
    return outTx.value;

}
Ejemplo n.º 14
0
    this.get_connection_string = function(product){
        var e = config.env;
        var connection_string ;
        if (product == "mongo"){
            var address = _.find(config.mongo_address, function(env) {
                return env.env == e;
                 });
            connection_string = "mongodb://" + address.ip + "/" + config.db + "?poolSize=4";
         } else { // for mysql
            var address = _.find(config.mysql.address, function(env) {
                return env.env == e;
            });
            connection_string = address;
        }

        return connection_string;
    };  
Ejemplo n.º 15
0
    this.get_mongo_host_auth_collection = function (){
        var e = config.env;
        var address = _.find(config.mongo_address, function(env) {
            return env.env == e;
        });

        return address.auth_collection;
    };
Ejemplo n.º 16
0
var generateNewId = function () {
    var id,
        limit = customers.length;
    id = 'prod' + limit;
    while (_.find(customers, {id: id})) {
        id = 'prod' + (++limit);
    }
    return id;
};
Ejemplo n.º 17
0
function createUnitClass(app, decl) {
    var members = decl.members;
    var statics = decl.statics;
    var name = members.name;
    var base;
    var baseDecl;
    var UnitClass;
    var BaseUnit;

    if (_.isFunction(decl.__class)) {
        //  Was already created
        return decl.__class;
    }

    base = members.base;

    //  Looking for base
    if (_.isUndefined(base)) {
        base = app.params.implicitBase;
        app.logger.debug('The base for unit "%s" is implicitly defined as "%s"', name, base);
    }

    if (base === app.Unit.prototype.name) {
        BaseUnit = app.Unit;
    } else {
        baseDecl = _.find(app._decls, {members: {name: base}});

        if (!baseDecl) {
            throw new errors.NoSuchUnitError(f('No such base "%s" found for unit "%s"', base, name));
        }

        BaseUnit = createUnitClass(app, baseDecl);
    }

    // Base Class is done. need to compile mixins
    members.mixins = _.map(members.mixins, function (Class) {
        var mixinDecl;

        if (_.isFunction(Class)) {
            return Class;
        }

        mixinDecl = _.find(app._decls, {members: {name: Class}});

        if (!mixinDecl) {
            throw new errors.NoSuchUnitError(f('No such mixin "%s" found for unit "%s"', Class, name));
        }

        return createUnitClass(app, mixinDecl);
    });

    UnitClass = BaseUnit.inherit(members, statics);

    decl.__class = UnitClass;

    return UnitClass;
}
Ejemplo n.º 18
0
        socket.on('notice', function (name, message) {

                var currentUser = _.find(users, { socket: socket.id });
                if (!currentUser) { return; }
                var contact = _.find(users, { name: name });

                if (!contact) {
                        socket.emit('notice_error');
                        return;
                }

                try{
                        io.to(contact.socket)
                            .emit('noticeReceived', currentUser.name , message);
                } catch(e) {

                }
        });
Ejemplo n.º 19
0
function getWordsByLesson(wordsStoredData, selector) {
  var lesson = _.find(lessons.storedData, selector);
  if (lesson) {
    return _.select(wordsStoredData, function(val) {
      return _.contains(lesson.words, val.id);
    });
  }

  return [];
}
Ejemplo n.º 20
0
    query.on("row", function(row) {
      rowCount++;
      var config = JSON.parse(row.config);

      var wfs = _.find(config.plugins, { id: "Oskari.mapframework.bundle.mapwfs.plugin.wfslayer.WfsLayerPlugin" });
      if(wfs) {
        oldWfsCount++;
        wfs.id = "Oskari.mapframework.bundle.mapwfs2.plugin.WfsLayerPlugin";
        wfs.config = { 
           "contextPath" : "/transport-0.0.1",
           "lazy" : true,
           "disconnectTime" : 30000,
           "backoffIncrement": 1000,
           "maxBackoff": 60000,
           "maxNetworkDelay": 10000
        };
      }

      var getInfoPlugin = _.find(config.plugins, { id: "Oskari.mapframework.mapmodule.GetInfoPlugin" });
      if(getInfoPlugin) {
        if(!getInfoPlugin.config) getInfoPlugin.config = {};
        getInfoPlugin.config.ignoredLayerTypes = ["WFS"],
        getInfoPlugin.config.infoBox = false;
      }

      var updatedConfig = JSON.stringify(config);

      var updateQuery = "UPDATE portti_view_bundle_seq SET config='" + updatedConfig + "' " +
        "WHERE bundle_id = (SELECT id FROM portti_bundle WHERE name = 'mapfull') " + 
        "AND view_id=" + row.view_id;

      client.query(updateQuery, function(err, res) {
        if(err) throw err;

        updateCount++;
        if(updateCount === rowCount && finished) {
          console.log('Updated ' + updateCount + ' of ' + rowCount + ' rows.');
          console.log('Old wfs found in ' + oldWfsCount + ' rows');
          client.end();
        }
      });
    });
Ejemplo n.º 21
0
exports.update = function (req, res) {
    var id = req.param('id'),
        customer = _.find(customers, {id: id});

    _.extend(customer, req.body);
	syncProducts(customer);
    res.json({
		success: 'OK',
        message: 'Updated a customer',
		data: customer
    });
};
Ejemplo n.º 22
0
 Promise.all([firstPost, secondPost, thirdPost]).then(function(values) {
   expect(values[0].statusCode).to.equal(201);
   expect(values[1].statusCode).to.equal(201);
   expect(values[2].statusCode).to.equal(201);
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.id === 0; })).to.not.exist; // sanity check
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.id === 1; })).to.exist;
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.id === 2; })).to.exist;
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.id === 3; })).to.exist;
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.id === 4; })).to.not.exist; // sanity check
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.title === 'go round mums'; })).to.exist;
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.title === 'get Liz back'; })).to.exist;
   expect(_.find(values, function (responseInfo) { return responseInfo.responseObject.title === 'sort life out'; })).to.exist;
   done();
 }).catch(function(err) {
Ejemplo n.º 23
0
 User.find({role: 'DOCTOR', 'links.email': user.email}, function (err, doctors) {
   if (err) {
     console.log(err);
   }
   if (doctors) {
     for (var i=0; i<doctors.length; i++) {
       if (!_.find(user.links, {email: doctors[i].email})) {
         user.links.push({email: doctors[i].email});
         user.save();
       }
     }
   }
 });
Ejemplo n.º 24
0
        pipe(through2.obj(function (file, enc, cb) {

            if ( file.eslint ) {
                noErrors = true === noErrors &&
                           !_.find(file.eslint.messages, {
                               severity: 2
                           });
            }

            this.push(file);

            cb();
        })).
	_.each(spec, function(paramSpec){
		if(paramSpec.required && paramSpec.paramType !== 'path'){
			var found = _.find(params, function(param){
				return param === paramSpec.name;
			});
			if(!found){
				errors.push({
					parameter : paramSpec.name,
					message : 'required ' + paramSpec.paramType + ' parameter not provided with the request'
				});
			}
		}
	});
Ejemplo n.º 26
0
exports.get = function (req, res) {
    var id = req.param('id'),
        customer;
    if (id === undefined) {
		for(i = 0; i < customers.length; i++){
			syncProducts(customers[i]);
		}
        res.send(customers);
    } else {
        customer = _.find(customers, {id: id});
		syncProducts(customer);
        res.json(customer);
    }
};
Ejemplo n.º 27
0
        socket.on('sendMessage', function (_user, message) {

                console.log("____________________");
                console.log(_user);
                console.log(message);
                console.log("____________________");

                user = JSON.parse(_user);
                consult = user.consult;

                var currentRoom = _.find(rooms, { id: consult });
                var cusers = currentRoom.users;
                var currentUser = _.find(cusers, { socket: socket.id });

                if (!currentUser) { return; }

                var contact = _.find(cusers, { name: user.name });
                if (!contact) {
                        try{
                                socket.emit('send_error');
                        } catch(e) {

                        }
                        return;
                }

                try{
                        io.to(contact.socket)
                            .emit('messageReceived', { name: currentUser.name, consult: consult } , message);
                } catch(e) {

                }

                console.log("________________users start_____________________");
                console.log(cusers);
                console.log("________________users end_____________________");
        });
Ejemplo n.º 28
0
exports.setCreditsResponse = function(res) {
    if (!utils.isValid(res) || !utils.isValid(res.data)) {
        throw new Error('Invalid response from Pelican: CLDCR');
    }

    var credit = res.data[0];
    var cloudCreditObj = {
        name: credit.name,
        units: credit.amount,
        description: credit.description,
        externalKey: credit.externalKey,
        price: {
            currencyCode: null,
            amount: null,
            taxCode: null,
            taxType: credit.offeringType,
            priceId: null
        }
    };

    // add descriptors
    cloudCreditObj.descriptors = credit.descriptors;

    // get linkages
    if (res.included && credit.links) {
        var linkageList = _ld.chain(credit.links).pluck('linkage').flatten(true).value(),
            included = res.included;

        var l,
        lLen = linkageList.length;

        for (l = 0; l < lLen; l++) {
            var link = _ld.find(included, linkageList[l]);

            if (link.type === 'price') {
                cloudCreditObj.price.priceId = link.id;
            }

            link = _ld.omit(link, _ld.keys(linkageList[l]));
            _ld.extend(cloudCreditObj.price, link);
        }
    }

    if (cloudCreditObj.price.currency) {
        cloudCreditObj.price.currencyCode = cloudCreditObj.price.currency;
    }

    return cloudCreditObj;
};
Ejemplo n.º 29
0
        remove: function( id ) {
            var timer = _.find( timers, { id: id } );

            if ( !timer ) {
                console.log( 'Attempting to remove a timer that does not exist.  id:', id );
                return false;
            }

            if ( timer.isRunning() ) {
                timer.stop();
            }
            _.remove( timers, timer );

            return true;
        },
Ejemplo n.º 30
0
    members.mixins = _.map(members.mixins, function (Class) {
        var mixinDecl;

        if (_.isFunction(Class)) {
            return Class;
        }

        mixinDecl = _.find(app._decls, {members: {name: Class}});

        if (!mixinDecl) {
            throw new errors.NoSuchUnitError(f('No such mixin "%s" found for unit "%s"', Class, name));
        }

        return createUnitClass(app, mixinDecl);
    });