Function to list forms that are deployed.

The request should contain an array of deployed forms.

@param req
@param res
@param next
176094
function search(req, res, next) {
  var projectForms = req.appformsResultPayload.data || [];
  //Only Want The Project Ids
  projectForms = _.map(projectForms, function(form) {
    if (_.isObject(form)) {
      return form._id;
    } else {
      return form;
    }
  });

  var formsToFind = req.body || [];

  formsToFind = _.filter(projectForms, function(projFormId) {
    return formsToFind.indexOf(projFormId) > -1;
  });

  logger.debug("Middleware: search forms: ", {connection: req.connectionOptions, projectForms: projectForms});

  forms.findForms(req.connectionOptions, formsToFind, function(err, formsList) {
    if (err) {
      return next(err);
    }

    async.map(formsList, function(foundForm, cb) {
      var getParams = {
        "_id": foundForm._id,
        "showAdminFields": false
      };
      forms.getForm(_.extend(_.clone(req.connectionOptions), getParams), cb);
    }, formsResultHandlers(constants.resultTypes.forms, req, next));
  });
}
505308
function create(req, res, next) {
  var options = req.connectionOptions;
  req.user = req.user || {};
  var params = {
    userEmail: req.user.email || req.body.updatedBy
  };

  options = _.extend(options, params);

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

  forms.updateForm(options, req.body, formsResultHandlers(constants.resultTypes.forms, req, next));
}
277907
function undeploy(req, res, next) {
  var removeParams = {
    _id: req.params.id
  };

  logger.debug("Middleware: undeploy form: ", {params: removeParams});

  forms.deleteForm(_.extend(req.connectionOptions, removeParams), formsResultHandlers(constants.resultTypes.forms, req, next));
}
88574
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;
        }
    }
265860
function parseFormDataParams (req, res, next) {
  getParams(req).forEach((param) => {
    if (param.in === "formData") {
      util.debug('    Parsing the "%s" form-data parameter', param.name);

      if (param.type === "file") {
        // Validate the file (min/max size, etc.)
        req.files[param.name] = parseParameter(param, req.files[param.name], param);
      }
      else {
        // Parse the body parameter
        req.body[param.name] = parseParameter(param, req.body[param.name], param);
      }
    }
  });

  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));
}
239264
function importForm(req, res, next) {
  req.appformsResultPayload = req.appformsResultPayload || {};
  var formData = (req.appformsResultPayload.data && req.appformsResultPayload.type === constants.resultTypes.formTemplate) ? req.appformsResultPayload.data : undefined ;

  var importFormParams = {
    form: formData,
    name: req.body.name,
    description: req.body.description,
    userEmail: req.user.email
  };

  logger.debug("Middleware: importForm form: ", {params: importFormParams});

  forms.cloneForm(_.extend(req.connectionOptions, importFormParams), formsResultHandlers(constants.resultTypes.forms, req, next));
}
369002
function list(req, res) {
  var s = '';
  this.state.connections.forEach(function(conn) {
    s += conn.toString();
  })
  res.send(null, s);
}
696561
function importProjects(req, res, next) {
  var options = req.connectionOptions;

  var appFormsToImport = req.body || [];

  if (!_.isArray(appFormsToImport)) {
    return next("Expected An Array Of App Form Entries");
  }

  forms.importAppForms(options, appFormsToImport, formsResultHandlers(constants.resultTypes.formProjects, req, 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);
}
1249777
function list(params, cb) {
  var resourcePath = config.addURIParams(constants.FORMS_BASE_PATH + "/submissions", params);
  var method = "GET";
  var data = {};

  params.resourcePath = resourcePath;
  params.method = method;
  params.data = data;

  mbaasRequest.admin(params, cb);
}
1028805
function getRequestFileParameters(req, res, next) {
  //A valid getForms request must have an appId parameter set
  var submitFileParams = {};
  submitFileParams.fileDetails = {};

  //Get the content body for normal parameter
  var filesInRequest = req.files;

  if (_.size(filesInRequest) === 0) {
    logger.error("Middleware: getRequestFileParameters, Expected A File To Have Been Sent ", {params: req.params});
    return next(new Error("Expected A File To Have Been Submitted"));
  }

  var fileDetails = _.map(filesInRequest, function(fileValue) {
    return fileValue;
  });

  fileDetails = _.first(fileDetails);

  logger.debug("Middleware: getRequestFileParameters ", {fileDetails: fileDetails, body: req.body});

  submitFileParams.fileDetails = {
    fileStream: fileDetails.path,
    fileName: fileDetails.originalname || fileDetails.name,
    fileType: fileDetails.mimetype,
    fileSize: fileDetails.size
  };

  req.appformsResultPayload = {
    data: submitFileParams,
    type: constants.resultTypes.submissions
  };

  logger.debug("Middleware: getRequestFileParameters ", {params: req.appformsResultPayload});

  return next();
}
549961
function notifySubmissionComplete(req, res, next){
  req.appformsResultPayload = req.appformsResultPayload || {};
  var completeStatus = req.appformsResultPayload.data;
  var submission = completeStatus.formSubmission;

  //The Submission Is Not Complete, No need to send a notification.
  if("complete" !== completeStatus.status){
    return next();
  }

  var resourcePath = "/api/v2/appforms/domain/:domain/projects/:projectid/apps/:guid/forms/" + submission.formId + "/submissions/" + req.params.id + "/complete";

  var params = _createRequestParams(_.extend({
    resourcePath: resourcePath,
    method: "POST",
    apiKey: req.get('x-fh-auth-app'),
    appMbaasModel: req.appMbaasModel,
    data: completeStatus
  }, req.params));

  log.logger.debug("notifySubmissionComplete ", {params: params});

  request(params, _createResponseHandler(req, next, true));
}
1154201
function pages(req, res, next) {

    generator.getPage(req.url, function(err, page) {

      if (err || !page || !checkMethod(req, page)) return next();

      if (!isPageAuthorized(req, page)) {
        if (!server.login || page.nologin) return next();
        return server.login(req, res);
      }

      debug('page %s', page._href);

      // make req and res available to dynamic pages
      generator.req = req;
      generator.res = res;

      resHeaders(res, page);
      res.send(generator.renderDoc(page));

    });
  }
469838
function(req, res, next) {
        var initialTime = req.query.time,
            receivedReqTime = new Date().getTime(),
            filename = req.params.filename,
            absolutePathToFile = ontoDir + '/' + filename,
            extension = path.extname(absolutePathToFile),
            contentType = mime.contentType(extension);

        if(contentType) {
            req.mimeType = contentType.replace(/;.*/g, '');
        } else {
            req.mimeType = contentType;
        }

        req.requestDelay =  receivedReqTime - initialTime;

        fs.readFile(absolutePathToFile, function(err, data) {
            if(err) {
                res.status(500).send(err.toString());
            } else {
                req.rawOntology = data.toString().replace(/(&)([a-z0-9]+)(;)/gi, '$2:');
                next();
            };
        });
    }
204286
function(req, res) {
    var params = URL.parse(req.url, true).query;
    var oauth2_server_id = params.provider || this.config.default_server;
    var next_url = this.nexturl_query(req, params);
    this.redirects_for_login(oauth2_server_id, res, next_url);
  }
214310
function show(req, res, next) {
  db.users.find(req.params.user, function(err, user) {
    if(err) { return next(err); }
    res.json(user);
  });
}