Populating mongo connection options for forms operations.
@param req
@param res
@param next
@returns {*}
336980
function parseMongoConnectionOptions(req, res, next) {
  var options = {};
  options.uri = req.mongoUrl;

  req.connectionOptions = options;

  return next();
}
804801
function importProjectConfig(req, res, next) {
  var options = req.connectionOptions;

  var projectConfigToImport = req.body || [];

  if (!_.isArray(projectConfigToImport)) {
    return next("Expected An Array Of Project Config Values");
  }

  forms.importAppConfig(options, projectConfigToImport, formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
638903
function updateConfig(req, res, next) {
  var params = {
    appId: req.params.id
  };

  forms.updateAppConfig(req.connectionOptions, _.extend(req.body, params), formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
657632
function(req, res, next) {
    Check
    .find({ _id: req.params.id })
    .select({qos: 0})
    .findOne(function(err, check) {
      if (err) return next(err);
      if (!check) return res.json(404, { error: 'failed to load check ' + req.params.id });
      req.check = check;
      next();
    });
  }
369002
function list(req, res) {
  var s = '';
  this.state.connections.forEach(function(conn) {
    s += conn.toString();
  })
  res.send(null, s);
}
294496
function execute(req, res) {
  var scanner = new Scanner(
    req.db.getKeys(), req.info.cursor, req.info.pattern, req.info.count);
  scanner.scan(req, res);
}
386051
function getPosts(req, res, next) {
  db.tags.find(req.params.tag, function(err, tag) {
    if(err) { return next(err); }

    db.posts_tags.tagGetPosts(tag.id, function(err, posts) {
      if(err) { return next(err); }
      res.format({
        'text/html': function() {
          res.render('tags/show', {posts: posts, tag: tag});
        },
        'application/json': function() {
          res.json(posts);
        }
      });
    });
  });
}
1112453
function deploy(req, res, next) {
  var options = req.connectionOptions;
  var form = req.body;
  req.user = req.user || {};

  if (req.appformsResultPayload && _.isObject(req.appformsResultPayload.data)) {
    form = req.appformsResultPayload.data;
  }

  //Expect A Data Source Data Set To Be Available If Deploying A Form.
  var params = {
    userEmail: req.user.email || req.body.updatedBy,
    expectDataSourceCache: true
  };

  options = _.extend(options, params);

  logger.debug("Middleware: Deploy form: ", {options: options});

  forms.updateOrCreateForm(options, form, formsResultHandlers(constants.resultTypes.forms, req, next));
}
631951
function filterSubmissions(req, res, next) {
  var filterParams = {
    formId: req.body.formId,
    appId: req.body.appId
  };

  logger.debug("Middleware filterSubmissions ", {params: filterParams});

  forms.getSubmissions(req.connectionOptions, filterParams, _getSubmissionsResultHandler(req, next));
}
516671
function queryParser( req, res, next ) {
	if ( !req.query ) {
		var val = parseUrl( req ).query;
		req.query = queryparse( val );
	}
	next();
}
1124001
function exportProjects(req, res, next) {
  var options = req.connectionOptions;

  forms.exportAppForms(options, formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
1305157
function(req, res, next) {
			req.controller = controllerName;
			req.action = actionName || 'index';
			next();
		}
1041759
function requestHandler(req, res, next) {
  const params = req && req.params;
  const start = Date.now();
  let source;
  let opts;

  return Promise.try(() => {
    source = core.getPublicSource(params.src);

    if (!_.contains(source.formats, params.format)) {
      throw new Err('Format %s is not known', params.format).metrics('err.req.format');
    }

    params.z = core.validateZoom(params.z, source);
    params.scale = core.validateScale(params.scale, source);

    params.x = checkType.strToInt(params.x);
    params.y = checkType.strToInt(params.y);
    if (
      !qidx.isValidCoordinate(params.x, params.z) || !qidx.isValidCoordinate(params.y, params.z)
    ) {
      throw new Err('x,y coordinates are not valid, or not allowed for this zoom').metrics('err.req.coords');
    }

    opts = {
      z: params.z,
      x: params.x,
      y: params.y,
    };
    if (params.format !== 'pbf') {
      // Ensure that PNGs are not 32bit
      // TODO: this should be source-configurable
      opts.format = params.format === 'png' ? 'png8:m=h' : params.format;
      if (params.scale) {
        opts.scale = params.scale;
      }
    }
    if (req.query && req.query.lang) {
      if (!langCodeRe.test(req.query.lang)) {
        throw new Err('lang param is not valid').metrics('err.req.lang');
      }
      opts.lang = req.query.lang;
    }

    // fixme: Force all tiles to be treated as vector
    opts.treatAsVector = true;

    return source.getHandler().getAsync(opts);
  }).then((result) => {
    let mx;

    core.setResponseHeaders(res, source, result.headers);

    if (params.format === 'json') {
      // Allow JSON to be shortened to simplify debugging
      res.json(filterJson(req.query, result.data));
    } else {
      res.send(result.data);
    }

    mx = util.format('req.%s.%s.%s', params.src, params.z, params.format);
    if (params.scale) {
      // replace '.' with ',' -- otherwise grafana treats it as a divider
      mx += `.${params.scale.toString().replace('.', ',')}`;
    }
    core.metrics.endTiming(mx, start);
  }).catch(err => core.reportRequestError(err, res)).catch(next);
}
1206358
function get(req, res) {
  var ptn = '' + req.args[0]
    , keys = this.pattern.filter(ptn, this.conf.getKeys())
    , list = []
    , i
    , k;
  for(i = 0;i < keys.length;i++) {
    k = keys[i];
    list.push(k, '' + this.conf.get(k));
  }
  res.send(null, list);
}
1079457
function(req, res, next) {
    Tag.findOne({ name: req.params.name }, function(err, tag) {
      if (err) return next(err);
      if (!tag) return res.json(404, { error: 'failed to load tag ' + req.params.name });
      req.tag = tag;
      next();
    });
  }
17210
function getConfig(req, res, next) {
  var params = {
    appId: req.params.projectid || req.params.id
  };

  forms.getAppConfig(req.connectionOptions, params, formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
253349
function (req, res) {

            //To avoid errors, escape table
            req.params.table = escape(req.params.table);

            //Get all fields from table
            lastQry = connection.query('SHOW COLUMNS FROM ??', req.params.table, function (err, rows) {
                if (err) return sendError(res, err.code);


                var fields, limit, order, where;


                //All general Settings


                //Select only certain columns?
                if (typeof req.query[settings.paramPrefix + "fields"] !== "undefined" && typeof req.query[settings.paramPrefix + "fields"] == "string" && req.query[settings.paramPrefix + "fields"] !== "") {
                    var req_fields = escape(req.query[settings.paramPrefix + "fields"]);
                    if (checkIfFieldsExist(req_fields, rows)) {
                        fields = req_fields;
                    } else {
                        return sendError(res, "Failed to fetch all fields specified in _fields");
                    }
                } else {
                    fields = '*';
                }

                //Parse order by and order direction
                if (typeof req.query[settings.paramPrefix + "order"] !== "undefined" && typeof req.query[settings.paramPrefix + "order"] === "object") {
                    var orderObj = req.query[settings.paramPrefix + "order"];
                    var orderArr = [];
                    for (var order_field in orderObj) {
                        if (orderObj.hasOwnProperty(order_field)) {
                            if (checkIfFieldsExist(order_field, rows)) {
                                if (orderObj[order_field].toUpperCase() == "ASC" || orderObj[order_field].toUpperCase() == "DESC") {
                                    orderArr.push(req.params.table + ".`" + order_field + "` " + orderObj[order_field].toUpperCase());
                                } else {
                                    return sendError(res, "Order option for " + order_field + " in _order is invalid. Please use either ASC or DESC");
                                }
                            } else {
                                return sendError(res, "Failed to fetch " + order_field + " specified in _order");
                            }
                        }
                    }
                    order = orderArr.join(',');
                }

                //Parse limit
                if (typeof req.query[settings.paramPrefix + "limit"] !== "undefined" && typeof req.query[settings.paramPrefix + "limit"] === "string" && req.query[settings.paramPrefix + "limit"] !== "") {

                    var limitStr = req.query[settings.paramPrefix + "limit"];


                    var limitArr = limitStr.split(',');
                    if (limitArr.length > 2) {
                        return sendError(res, "Limit specificed in _limit is invalid. Limit does not allow more than 2 comma separated values");
                    }
                    for (var i = 0; i < limitArr.length; i++) {
                        var lim = parseInt(limitArr[i]);
                        if (isNaN(lim)) {
                            return sendError(res, "Limit specificed in _limit is invalid. Please use a comma to separate start and amount");
                        }
                        limitArr[i] = lim;
                    }

                    limit = limitArr.join(',');

                }


                //Parse all other get params as selector
                var whereArr = [];

                for (var q in req.query) {
                    if (req.query.hasOwnProperty(q)) {
                        if (q.substr(0, 1) !== settings.paramPrefix) {
                            if (checkIfFieldsExist(q, rows)) {

                                if (typeof req.query[q] === "string") {
                                    //If it is a simple string, the api assumes = as the operator
                                    whereArr.push(mysql.format('?? = ?', [q, escape(req.query[q])]));

                                } else if (typeof req.query[q] === "object") {

                                    for (var selector in req.query[q]) {
                                        if (req.query[q].hasOwnProperty(selector)) {
                                            var op, val = connection.escape(escape(req.query[q][selector]));
                                            //MYSQLify the operator
                                            switch (selector.toUpperCase()) {
                                                case 'GREAT':
                                                    op = "> ";
                                                    break;
                                                case 'SMALL':
                                                    op = "< ";
                                                    break;
                                                case 'EQGREAT':
                                                    op = '>= ';
                                                    break;
                                                case 'EQSMALL':
                                                    op = '<= ';
                                                    break;
                                                case 'IN':
                                                    op = 'IN (';
                                                    val = escape(req.query[q][selector]).split(',').map(function (item) {
                                                        return connection.escape(item);
                                                    }).join(',') + ')';
                                                    break;
                                                case 'LIKE':
                                                    op = 'LIKE ';                                            
                                                    break;
                                                case 'EQ':
                                                    op = '= ';
                                                    break;
                                                default:
                                                    op = '= ';
                                                    break;
                                            }
                                            whereArr.push(mysql.format('?? ' + op + val, [q]));
                                        }
                                    }

                                } else {
                                    return sendError(res, "Can't read parameter specified for the field " + q + " in the table " + req.params.table);
                                }


                            } else {
                                return sendError(res, "Can't find the field" + q + " in the table " + req.params.table);
                            }
                        }
                    }
                }

                if (whereArr.length > 0) {
                    where = whereArr.join(' AND ')
                }

                //Bring in MYSQL syntax
                fields = fields ? fields : '*';
                order = order ? 'ORDER BY ' + order : '';
                limit = limit ? 'LIMIT ' + limit : '';
                where = where ? 'WHERE ' + where : '';

                //Fire query
                lastQry = connection.query("SELECT " + fields + " FROM ?? " + where + " " + order + " " + limit, [req.params.table], function (err, rows) {
                    if (err) return sendError(res, err.code);
                    res.send({
                        result: 'success',
                        json: rows,
                        table: req.params.table,
                        length: rows.length
                    });
                });
            });
        }