lib/routesHandler/lib/preconditionsCheck.js
function (req, res, next) {
        var hostId = req.miajs.route.hostId;
        var url = req.miajs.route.url;
        var prefix = req.miajs.route.prefix;
        var method = req.miajs.route.method;
        var group = req.miajs.route.group;
        var version = req.miajs.route.version;
        var registeredServices = Shared.registeredServices();
        var errors = [];
        var routeFound = false;
        req.miajs = req.miajs || {};

        //console.log('checkPreconditions: url: ' + url + ', method: ' + method + ', body: ' + JSON.stringify(req.body));

        for (var index in registeredServices) {

            if (registeredServices[index].group == group
                && registeredServices[index].hostId == hostId
                && registeredServices[index].version == version
                && registeredServices[index].prefix == prefix
                && registeredServices[index].method == method
                && registeredServices[index].url == url
            ) {
                routeFound = true;
                if (registeredServices[index].preconditions) {
                    var service = registeredServices[index];
                    var preconditionsList = service.preconditions;
                    var qfunctions = [];

                    for (var cIndex in preconditionsList) {
                        qfunctions.push(_checkControllerConditions(req, preconditionsList[cIndex]));
                    }

                    Q.all(qfunctions).then(function (results) {

                        req.miajs.commonValidatedParameters = [];

                        results.forEach(function (result) {
                            if (result) {
                                if (result.validatedData) {
                                    req.miajs.commonValidatedParameters.push(result.validatedData);
                                }

                                var controllerErrors = result.errors;
                                controllerErrors.forEach(function (error) {

                                    var inList = false;
                                    // Check for error duplicates
                                    for (var eIndex in errors) {
                                        if (errors[eIndex].code == error.code && errors[eIndex].id == error.id && errors[eIndex].in == error.in) {
                                            inList = true;
                                        }
                                    }

                                    if (inList == false) {
                                        errors.push(error);
                                    }
                                });
                            }
                        });

                    }).then(function () {
                        if (!_.isEmpty(errors)) {
                            next({'status': 400, err: errors})
                            return;
                        }
                        else {
                            next();
                            return;
                        }
                    }).catch(function (err) {
                        next({'status': 400, err: err});
                        return;
                    });
                }
                else {
                    next();
                    return;
                }
            }
        }

        if (routeFound == false) {
            Logger.error('Can not find controller file in preconditionsCheck to perform parameter validation. Request canceled due to security reasons');
            next({status: 500});
            return;
        }
    }
function (req, res, next) {
        var hostId = req.miajs.route.hostId;
        var url = req.miajs.route.url;
        var prefix = req.miajs.route.prefix;
        var method = req.miajs.route.method;
        var group = req.miajs.route.group;
        var version = req.miajs.route.version;
        var registeredServices = Shared.registeredServices();
        var errors = [];
        var routeFound = false;
        req.miajs = req.miajs || {};

        //console.log('checkPreconditions: url: ' + url + ', method: ' + method + ', body: ' + JSON.stringify(req.body));

        for (var index in registeredServices) {

            if (registeredServices[index].group == group
                && registeredServices[index].hostId == hostId
                && registeredServices[index].version == version
                && registeredServices[index].prefix == prefix
                && registeredServices[index].method == method
                && registeredServices[index].url == url
            ) {
                routeFound = true;
                if (registeredServices[index].preconditions) {
                    var service = registeredServices[index];
                    var preconditionsList = service.preconditions;
                    var qfunctions = [];

                    for (var cIndex in preconditionsList) {
                        qfunctions.push(_checkControllerConditions(req, preconditionsList[cIndex]));
                    }

                    Q.all(qfunctions).then(function (results) {

                        req.miajs.commonValidatedParameters = [];

                        results.forEach(function (result) {
                            if (result) {
                                if (result.validatedData) {
                                    req.miajs.commonValidatedParameters.push(result.validatedData);
                                }

                                var controllerErrors = result.errors;
                                controllerErrors.forEach(function (error) {

                                    var inList = false;
                                    // Check for error duplicates
                                    for (var eIndex in errors) {
                                        if (errors[eIndex].code == error.code && errors[eIndex].id == error.id && errors[eIndex].in == error.in) {
                                            inList = true;
                                        }
                                    }

                                    if (inList == false) {
                                        errors.push(error);
                                    }
                                });
                            }
                        });

                    }).then(function () {
                        if (!_.isEmpty(errors)) {
                            next({'status': 400, err: errors})
                            return;
                        }
                        else {
                            next();
                            return;
                        }
                    }).catch(function (err) {
                        next({'status': 400, err: err});
                        return;
                    });
                }
                else {
                    next();
                    return;
                }
            }
        }

        if (routeFound == false) {
            Logger.error('Can not find controller file in preconditionsCheck to perform parameter validation. Request canceled due to security reasons');
            next({status: 500});
            return;
        }
    }
function ( req , res , next ) { var hostId = req . miajs . route . hostId ; var url = req . miajs . route . url ; var prefix = req . miajs . route . prefix ; var method = req . miajs . route . method ; var group = req . miajs . route . group ; var version = req . miajs . route . version ; var registeredServices = Shared . registeredServices ( ) ; var errors = [ ] ; var routeFound = false ; req . miajs = req . miajs || { } ; //console.log('checkPreconditions: url: ' + url + ', method: ' + method + ', body: ' + JSON.stringify(req.body)); for ( var index in registeredServices ) { if ( registeredServices [ index ] . group == group && registeredServices [ index ] . hostId == hostId && registeredServices [ index ] . version == version && registeredServices [ index ] . prefix == prefix && registeredServices [ index ] . method == method && registeredServices [ index ] . url == url ) { routeFound = true ; if ( registeredServices [ index ] . preconditions ) { var service = registeredServices [ index ] ; var preconditionsList = service . preconditions ; var qfunctions = [ ] ; for ( var cIndex in preconditionsList ) { qfunctions . push ( _checkControllerConditions ( req , preconditionsList [ cIndex ] ) ) ; } Q . all ( qfunctions ) . then ( function ( results ) { req . miajs . commonValidatedParameters = [ ] ; results . forEach ( function ( result ) { if ( result ) { if ( result . validatedData ) { req . miajs . commonValidatedParameters . push ( result . validatedData ) ; } var controllerErrors = result . errors ; controllerErrors . forEach ( function ( error ) { var inList = false ; // Check for error duplicates for ( var eIndex in errors ) { if ( errors [ eIndex ] . code == error . code && errors [ eIndex ] . id == error . id && errors [ eIndex ] . in == error . in ) { inList = true ; } } if ( inList == false ) { errors . push ( error ) ; } } ) ; } } ) ; } ) . then ( function ( ) { if ( ! _ . isEmpty ( errors ) ) { next ( { 'status' : 400 , err : errors } ) return ; } else { next ( ) ; return ; } } ) . catch ( function ( err ) { next ( { 'status' : 400 , err : err } ) ; return ; } ) ; } else { next ( ) ; return ; } } } if ( routeFound == false ) { Logger . error ( 'Can not find controller file in preconditionsCheck to perform parameter validation. Request canceled due to security reasons' ) ; next ( { status : 500 } ) ; return ; } }
Apply all preconditions defined in all controllers of this route.
Try to find preconditions in registeredServices matching url, prefix, method, group and version
@param req
@param res
@param next
Apply all preconditions defined in all controllers of this route . Try to find preconditions in registeredServices matching url prefix method group and version