<commit_before>import constants from '../core/constants';

class MetadataApi {

  getData(api) {
    let p = new Promise((resolve, reject) => {
        fetch(api)
        .then(r => r.json())
        .then(data => {
          resolve(data);
        })
        .catch(e => {
            console.log("Failed to get " + api + e);
        });
    });
    return p;
  }

  getNames(components) {
    let names = "";
    components.map(i => {
      names = names === "" ? i.name : names + "," + i.name;
    });
    return names;
  }

  getAvailableBuilds(component) {
    // the user clicked Edit when viewing details of a Recipe component
    // a list of available builds are returned for displaying in the edit form
    let p = new Promise((resolve, reject) => {
      Promise.all([
        this.getData(constants.get_projects_info + component.name),
      ]).then((data) => {
        let builds = data[0].projects[0].builds;
        resolve(builds);
      })
      .catch(e => {
        console.log("Error getting component builds: " + e);
        reject();
      });
    });
    return p;
  }

  getMetadataComponent(component, build) {
    // if the user clicked View Details for an available component
    //    then build = "all" and all available builds are returned
    // if the user clicked Add in the sidebar to add the component to the recipe
    //    of if the user clicked the name of any component not available to add
    //    then build = ""

    // get metadata and dependencies for the component
    // bdcs-api v0.3.0 /modules/info looks like:
    // {"modules":[{"name":NAME, ..., "dependencies":[NEVRA, ...]}, ...]}
    let p = new Promise((resolve, reject) => {
      Promise.all([
        this.getData(constants.get_projects_info + component.name),
        this.getData(constants.get_modules_info + component.name)
      ]).then((data) => {
        let componentData = data[1].modules[0];
        componentData.inRecipe = component.inRecipe;
        componentData.ui_type = component.ui_type;

        // The component's depsolved version may be in .dependencies
        let compNEVRA = componentData.dependencies.filter((obj) => obj.name === component.name);
        if (compNEVRA.length > 0) {
            compNEVRA = compNEVRA[0];
        } else {<commit_msg>Log an error to the console when a component cannot be retrieved<commit_after>import constants from '../core/constants';

class MetadataApi {

  getData(api) {
    let p = new Promise((resolve, reject) => {
        fetch(api)
        .then(r => r.json())
        .then(data => {
          resolve(data);
        })
        .catch(e => {
            console.log("Failed to get " + api + e);
        });
    });
    return p;
  }

  getNames(components) {
    let names = "";
    components.map(i => {
      names = names === "" ? i.name : names + "," + i.name;
    });
    return names;
  }

  getAvailableBuilds(component) {
    // the user clicked Edit when viewing details of a Recipe component
    // a list of available builds are returned for displaying in the edit form
    let p = new Promise((resolve, reject) => {
      Promise.all([
        this.getData(constants.get_projects_info + component.name),
      ]).then((data) => {
        let builds = data[0].projects[0].builds;
        resolve(builds);
      })
      .catch(e => {
        console.log("Error getting component builds: " + e);
        reject();
      });
    });
    return p;
  }

  getMetadataComponent(component, build) {
    // if the user clicked View Details for an available component
    //    then build = "all" and all available builds are returned
    // if the user clicked Add in the sidebar to add the component to the recipe
    //    of if the user clicked the name of any component not available to add
    //    then build = ""

    // get metadata and dependencies for the component
    // bdcs-api v0.3.0 /modules/info looks like:
    // {"modules":[{"name":NAME, ..., "dependencies":[NEVRA, ...]}, ...]}
    let p = new Promise((resolve, reject) => {
      Promise.all([
        this.getData(constants.get_projects_info + component.name),
        this.getData(constants.get_modules_info + component.name)
      ]).then((data) => {
        if ((data[0].projects.length == 0) || (data[1].modules.length == 0)) {
            console.log("Error fetching metadata for " + component.name);
            return;
        }

        let componentData = data[1].modules[0];
        componentData.inRecipe = component.inRecipe;
        componentData.ui_type = component.ui_type;

        // The component's depsolved version may be in .dependencies
        let compNEVRA = componentData.dependencies.filter((obj) => obj.name === component.name);
        if (compNEVRA.length > 0) {
            compNEVRA = compNEVRA[0];
        } else {
{'fraction_non_alphanumeric': 0.13429106808244848, 'fraction_numerical': 0.004580470539246304, 'mean_word_length': 2.2481406355645706, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 27, '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': '6094666', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1370, 'n_words': 395}