function encryptSGContextValues(globalConfigModel, sg, sgt) {
  if (!sg.context || !sgt.contextDefinition) {
    return Promise.resolve(sg);
  }

  return getSGEncryptionKeyAndAlgorithm(globalConfigModel)
  .then((config) => {
    const isKeyAlgoConfigured =
      config && config.secretKey && config.algorithm;
    for (const key in sgt.contextDefinition) {
      if (sgt.contextDefinition.hasOwnProperty(key) &&
        sgt.contextDefinition[key].encrypted && sg.context[key]) {
        if (isKeyAlgoConfigured) {
          sg.context[key] = encrypt(sg.context[key], config.secretKey,
            config.algorithm);
        } else {
          return Promise.reject('Cannot encrypt the text without the ' +
            'secretKey and algorithm');
        }
      }
    }

    return sg;
  });
} // encryptSGContextValues
/**
 * Encrypts the sample generator context values, if the corresponding
 * sample generator template context definition value requires encryption.
 * If the secret key and algorithm are not found in the global config table
 * the encryption is not done.
 * @param  {GlobalConfig} globalConfigModel - The global config model
 * @param  {Object} sg - The sample generator object
 * @param  {Object} sgt - The sample generatot template object.
 * @returns {Objec} - sample generator object with encrypted context values
 */
Encrypts the sample generator context values, if the corresponding
sample generator template context definition value requires encryption.
If the secret key and algorithm are not found in the global config table
the encryption is not done.
@param  {GlobalConfig} globalConfigModel - The global config model
@param  {Object} sg - The sample generator object
@param  {Object} sgt - The sample generatot template object.
@returns {Objec} - sample generator object with encrypted context values
Encrypts the sample generator context values if the corresponding sample generator template context definition value requires encryption . If the secret key and algorithm are not found in the global config table the encryption is not done . @param { GlobalConfig } globalConfigModel - The global config model @param { Object } sg - The sample generator object @param { Object } sgt - The sample generatot template object . @returns { Objec } - sample generator object with encrypted context values
function encryptSGContextValues(globalConfigModel, sg, sgt) {
  if (!sg.context || !sgt.contextDefinition) {
    return Promise.resolve(sg);
  }
  return getSGEncryptionKeyAndAlgorithm(globalConfigModel)
  .then((config) => {
    const isKeyAlgoConfigured =
      config && config.secretKey && config.algorithm;
    for (const key in sgt.contextDefinition) {
      if (sgt.contextDefinition.hasOwnProperty(key) &&
        sgt.contextDefinition[key].encrypted && sg.context[key]) {
        if (isKeyAlgoConfigured) {
          sg.context[key] = encrypt(sg.context[key], config.secretKey,
            config.algorithm);
        } else {
          return Promise.reject('Cannot encrypt the text without the ' +
            'secretKey and algorithm');
        }
      }
    }
    return sg;
  });
} 
function encryptSGContextValues ( globalConfigModel , sg , sgt ) { if ( ! sg . context || ! sgt . contextDefinition ) { return Promise . resolve ( sg ) ; } return getSGEncryptionKeyAndAlgorithm ( globalConfigModel ) . then ( ( config ) => { const isKeyAlgoConfigured = config && config . secretKey && config . algorithm ; for ( const key in sgt . contextDefinition ) { if ( sgt . contextDefinition . hasOwnProperty ( key ) && sgt . contextDefinition [ key ] . encrypted && sg . context [ key ] ) { if ( isKeyAlgoConfigured ) { sg . context [ key ] = encrypt ( sg . context [ key ] , config . secretKey , config . algorithm ) ; } else { return Promise . reject ( 'Cannot encrypt the text without the ' + 'secretKey and algorithm' ) ; } } } return sg ; } ) ; }
Encrypts the sample generator context values, if the corresponding
 sample generator template context definition value requires encryption.
Encrypts the sample generator context values if the corresponding sample generator template context definition value requires encryption .
// encryptSGContextValues