lib/impl/importForms/index.js
function importForms(connections, params, callback) {
  params = params || {};

  logger.debug("Importing Forms ", params);

  //Validating
  var paramsValidator = validate(params);
  var failed = paramsValidator.has(ZIP_FILE_PATH, WORKING_DIR);

  if (failed) {
    return callback("Validation Failed " + (failed[ZIP_FILE_PATH] || failed[WORKING_DIR]));
  }

  //Random directory name.
  var newDirectoryName = (new mongoose.Types.ObjectId()).toString();
  var unzipDirectoryPath = path.join(params.workingDir, "/", newDirectoryName);

  async.waterfall([
    function checkFiles(cb) {
      async.parallel([
        async.apply(checkWorkingDir, params.workingDir),
        async.apply(checkZipFile, params.zipFilePath)
      ], function(err) {
        //Not interested in passing any of the results from the aync.parallel to the waterfall callback
        cb(err);
      });
    },
    function createUniqueDirToUnzipTo(cb) {
      //Need to create a new directory
      mkdirp(unzipDirectoryPath, function(err) {
        return cb(err);
      });
    },
    async.apply(unzipFile, {
      zipFilePath: params.zipFilePath,
      workingDir: unzipDirectoryPath,
      queueConcurrency: 5
    }),
    function validateInput(cb) {
      inputValidator(unzipDirectoryPath, true, cb);
    },
    async.apply(importFromDir, connections, unzipDirectoryPath)
  ], function(err, importedForms) {
    if (err) {
      logger.error("Error Importing Forms ", err);
    }

    //we always need to cleanup
    cleanupFiles(unzipDirectoryPath, params.zipFilePath);
    return callback(err, importedForms);
  });
}
function importForms(connections, params, callback) {
  params = params || {};

  logger.debug("Importing Forms ", params);

  //Validating
  var paramsValidator = validate(params);
  var failed = paramsValidator.has(ZIP_FILE_PATH, WORKING_DIR);

  if (failed) {
    return callback("Validation Failed " + (failed[ZIP_FILE_PATH] || failed[WORKING_DIR]));
  }

  //Random directory name.
  var newDirectoryName = (new mongoose.Types.ObjectId()).toString();
  var unzipDirectoryPath = path.join(params.workingDir, "/", newDirectoryName);

  async.waterfall([
    function checkFiles(cb) {
      async.parallel([
        async.apply(checkWorkingDir, params.workingDir),
        async.apply(checkZipFile, params.zipFilePath)
      ], function(err) {
        //Not interested in passing any of the results from the aync.parallel to the waterfall callback
        cb(err);
      });
    },
    function createUniqueDirToUnzipTo(cb) {
      //Need to create a new directory
      mkdirp(unzipDirectoryPath, function(err) {
        return cb(err);
      });
    },
    async.apply(unzipFile, {
      zipFilePath: params.zipFilePath,
      workingDir: unzipDirectoryPath,
      queueConcurrency: 5
    }),
    function validateInput(cb) {
      inputValidator(unzipDirectoryPath, true, cb);
    },
    async.apply(importFromDir, connections, unzipDirectoryPath)
  ], function(err, importedForms) {
    if (err) {
      logger.error("Error Importing Forms ", err);
    }

    //we always need to cleanup
    cleanupFiles(unzipDirectoryPath, params.zipFilePath);
    return callback(err, importedForms);
  });
}
function importForms ( connections , params , callback ) { params = params || { } ; logger . debug ( "Importing Forms " , params ) ; //Validating var paramsValidator = validate ( params ) ; var failed = paramsValidator . has ( ZIP_FILE_PATH , WORKING_DIR ) ; if ( failed ) { return callback ( "Validation Failed " + ( failed [ ZIP_FILE_PATH ] || failed [ WORKING_DIR ] ) ) ; } //Random directory name. var newDirectoryName = ( new mongoose . Types . ObjectId ( ) ) . toString ( ) ; var unzipDirectoryPath = path . join ( params . workingDir , "/" , newDirectoryName ) ; async . waterfall ( [ function checkFiles ( cb ) { async . parallel ( [ async . apply ( checkWorkingDir , params . workingDir ) , async . apply ( checkZipFile , params . zipFilePath ) ] , function ( err ) { //Not interested in passing any of the results from the aync.parallel to the waterfall callback cb ( err ) ; } ) ; } , function createUniqueDirToUnzipTo ( cb ) { //Need to create a new directory mkdirp ( unzipDirectoryPath , function ( err ) { return cb ( err ) ; } ) ; } , async . apply ( unzipFile , { zipFilePath : params . zipFilePath , workingDir : unzipDirectoryPath , queueConcurrency : 5 } ) , function validateInput ( cb ) { inputValidator ( unzipDirectoryPath , true , cb ) ; } , async . apply ( importFromDir , connections , unzipDirectoryPath ) ] , function ( err , importedForms ) { if ( err ) { logger . error ( "Error Importing Forms " , err ) ; } //we always need to cleanup cleanupFiles ( unzipDirectoryPath , params . zipFilePath ) ; return callback ( err , importedForms ) ; } ) ; }
importForms - Importing Form Definitions From A ZIP File.

The ZIP file will be unzipped to a working directory where the forms will be imported from.

@param  {object} connections
@param  {object} connections.mongooseConnection The Mongoose Connection
@param  {object} params
@param  {string} params.zipFilePath  A Path to a ZIP file on the file system.
@param  {string} params.workingDir A Path to a directory where the zip file can be unzipped to.
@param  {function} callback
@return {type}
importForms - Importing Form Definitions From A ZIP File .