<commit_before>//Import Depedencies
const auth = require('./../auth.js');
const query = require('./../../database/query');
const update = require('./../../database/update');
const lazyLoad = require('./../../lazyload');

function getLayoutFallback(pc_id, release_id, connection) {
  return lazyLoad.queryMetadata(pc_id)
    .catch(() => {
      return lazyLoad.queryPC(pc_id);
    }).then(result => {
      let output = { graph: result, layout: null };

      if (connection && result.pathwayMetadata) {
        update.updateGraph(pc_id, release_id, result, connection);
      }

      return JSON.stringify(output);
    }).catch(() => {
      return `ERROR: Layout for ${pc_id} could not be retrieved from database or PC2`;
    });
}

function getLayout(pc_id, release_id) {
  return query.connect().then((connection) => {
    return query.getGraphAndLayout(pc_id, release_id, connection)
      .then((layout) => {
        return JSON.stringify(layout);
      }).catch(() => {
        return getLayoutFallback(pc_id, release_id, connection);
      });
  }).catch(() => {
    // Error.
    return 'ERROR: Connection to database failed';
  });
}

function submitLayout(pcID, releaseID, layout, key) {
  //Get the requested layout
  return query.connect().then((connection) => {
    if (hasRightKey(pcID, releaseID, key)) {
      update.saveLayout(pcID, layout, releaseID, connection);
      return 'Layout was updated.';
    }
    else {
      return 'ERROR: Incorrect Edit key';
    }
  }).catch(() => {
    return 'ERROR: Something went wrong in submitting the layout';
  });<commit_msg>Renamed variables to match javaScript camelCase conventions<commit_after>//Import Depedencies
const auth = require('./../auth.js');
const query = require('./../../database/query');
const update = require('./../../database/update');
const lazyLoad = require('./../../lazyload');
const logger = require('./../../logger');

function getLayoutFallback(pcID, releaseID, connection) {
  return lazyLoad.queryMetadata(pcID)
    .catch(() => {
      return lazyLoad.queryPC(pcID);
    }).then(result => {
      let output = { graph: result, layout: null };

      if (connection && result.pathwayMetadata) {
        update.updateGraph(pcID, releaseID, result, connection);
      }

      return JSON.stringify(output);
    }).catch(() => {
      return `ERROR: Layout for ${pcID} could not be retrieved from database or PC2`;
    });
}

function getLayout(pcID, releaseID) {
  return query.connect().then((connection) => {
    return query.getGraphAndLayout(pcID, releaseID, connection)
      .then((layout) => {
        return JSON.stringify(layout);
      }).catch(() => {
        return getLayoutFallback(pcID, releaseID, connection);
      });
  }).catch((e) => {
    // Error.
    logger.error(e);
    return 'ERROR: Connection to database failed';
  });
}

function submitLayout(pcID, releaseID, layout, key) {
  //Get the requested layout
  return query.connect().then((connection) => {
    if (hasRightKey(pcID, releaseID, key)) {
      update.saveLayout(pcID, layout, releaseID, connection);
      return 'Layout was updated.';
    }
    else {
      return 'ERROR: Incorrect Edit key';
    }
  }).catch(() => {
    return 'ERROR: Something went wrong in submitting the layout';
  });
{'fraction_non_alphanumeric': 0.16315307057745188, 'fraction_numerical': 0.0006110601894286587, 'mean_word_length': 3.1495564005069707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4324438', 'n_tokens_mistral': 945, 'n_tokens_neox': 937, 'n_words': 244}