lib/impl/dataSources/index.js
function validateDataSource(connections, dataSource, cb) {
  var dataSourceToValidate = _.clone(dataSource);
  var DataSource = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_SOURCE);

  //Expect The Data Source To Have Data
  var failure = validate(dataSourceToValidate).has(CONSTANTS.DATA_SOURCE_DATA);

  if (failure) {
    return cb(buildErrorResponse({
      error: new Error("No Data Passed To Validate"),
      code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
    }));
  }

  //Generate A Hash
  var hash = misc.generateHash(dataSourceToValidate.data);

  //Populate A Cache Object
  //LastRefreshed is populated just for the cache mongoose schema
  var cache = {
    dataHash: hash,
    currentStatus: {
      status: "ok"
    },
    data: dataSourceToValidate.data,
    lastRefreshed: new Date().getTime(),
    updateTimestamp: new Date().getTime()
  };

  dataSourceToValidate.cache = [cache];

  //Create A New Mongoose. Note that this document is never saved. It is useful for consistent validation
  var testDataSource = new DataSource(dataSourceToValidate);
  //Validating Without Saving
  testDataSource.validate(function(err) {
    var valid = err ? false : true;
    var dataSourceJSON = testDataSource.toJSON();

    dataSourceJSON = processDataSourceResponse(dataSourceJSON);

    dataSourceJSON = _.omit(dataSourceJSON, "lastRefreshed", "currentStatus", "updateTimestamp", CONSTANTS.DATA_SOURCE_ID);

    dataSourceJSON.validationResult = {
      valid: valid,
      message: valid ? "Data Source Is Valid" : "Invalid Data Source Update Data."
    };

    return cb(undefined, dataSourceJSON);
  });
}
function validateDataSource(connections, dataSource, cb) {
  var dataSourceToValidate = _.clone(dataSource);
  var DataSource = models.get(connections.mongooseConnection, models.MODELNAMES.DATA_SOURCE);

  //Expect The Data Source To Have Data
  var failure = validate(dataSourceToValidate).has(CONSTANTS.DATA_SOURCE_DATA);

  if (failure) {
    return cb(buildErrorResponse({
      error: new Error("No Data Passed To Validate"),
      code: ERROR_CODES.FH_FORMS_INVALID_PARAMETERS
    }));
  }

  //Generate A Hash
  var hash = misc.generateHash(dataSourceToValidate.data);

  //Populate A Cache Object
  //LastRefreshed is populated just for the cache mongoose schema
  var cache = {
    dataHash: hash,
    currentStatus: {
      status: "ok"
    },
    data: dataSourceToValidate.data,
    lastRefreshed: new Date().getTime(),
    updateTimestamp: new Date().getTime()
  };

  dataSourceToValidate.cache = [cache];

  //Create A New Mongoose. Note that this document is never saved. It is useful for consistent validation
  var testDataSource = new DataSource(dataSourceToValidate);
  //Validating Without Saving
  testDataSource.validate(function(err) {
    var valid = err ? false : true;
    var dataSourceJSON = testDataSource.toJSON();

    dataSourceJSON = processDataSourceResponse(dataSourceJSON);

    dataSourceJSON = _.omit(dataSourceJSON, "lastRefreshed", "currentStatus", "updateTimestamp", CONSTANTS.DATA_SOURCE_ID);

    dataSourceJSON.validationResult = {
      valid: valid,
      message: valid ? "Data Source Is Valid" : "Invalid Data Source Update Data."
    };

    return cb(undefined, dataSourceJSON);
  });
}
function validateDataSource ( connections , dataSource , cb ) { var dataSourceToValidate = _ . clone ( dataSource ) ; var DataSource = models . get ( connections . mongooseConnection , models . MODELNAMES . DATA_SOURCE ) ; //Expect The Data Source To Have Data var failure = validate ( dataSourceToValidate ) . has ( CONSTANTS . DATA_SOURCE_DATA ) ; if ( failure ) { return cb ( buildErrorResponse ( { error : new Error ( "No Data Passed To Validate" ) , code : ERROR_CODES . FH_FORMS_INVALID_PARAMETERS } ) ) ; } //Generate A Hash var hash = misc . generateHash ( dataSourceToValidate . data ) ; //Populate A Cache Object //LastRefreshed is populated just for the cache mongoose schema var cache = { dataHash : hash , currentStatus : { status : "ok" } , data : dataSourceToValidate . data , lastRefreshed : new Date ( ) . getTime ( ) , updateTimestamp : new Date ( ) . getTime ( ) } ; dataSourceToValidate . cache = [ cache ] ; //Create A New Mongoose. Note that this document is never saved. It is useful for consistent validation var testDataSource = new DataSource ( dataSourceToValidate ) ; //Validating Without Saving testDataSource . validate ( function ( err ) { var valid = err ? false : true ; var dataSourceJSON = testDataSource . toJSON ( ) ; dataSourceJSON = processDataSourceResponse ( dataSourceJSON ) ; dataSourceJSON = _ . omit ( dataSourceJSON , "lastRefreshed" , "currentStatus" , "updateTimestamp" , CONSTANTS . DATA_SOURCE_ID ) ; dataSourceJSON . validationResult = { valid : valid , message : valid ? "Data Source Is Valid" : "Invalid Data Source Update Data." } ; return cb ( undefined , dataSourceJSON ) ; } ) ; }
Validating A Data Source Object.
@param connections
@param dataSource
@param cb
Validating A Data Source Object .