<commit_before>import * as _ from 'underscore';
import * as inquirer from 'inquirer';
import { RequestResponse } from 'request';
import { Question } from 'inquirer';
import { Answers } from 'inquirer';
import { Utils } from '../commons/utils/Utils';
import { GraduateCommand } from '../commands/GraduateCommand';
import { DiffCommand } from '../commands/DiffCommand';
import { FieldController } from '../controllers/FieldController';
import { ExtensionController } from '../controllers/ExtensionController';
import { FieldAPI } from '../commons/rest/FieldAPI';

export class InteractiveMode {
  static ORIGIN_ORG_ID: string = 'originOrganizationId';
  static ORIGIN_ORG_KEY: string = 'originOrganizationKey';
  static DESTINATION_ORG_ID: string = 'destinationOrganizationId';
  static DESTINATION_ORG_KEY: string = 'destinationOrganizationKey';
  static COMMAND: string = 'command';
  static GRADUATE_FIELDS_OPERATION: string = 'graduateFieldsOperation';
  static GRADUATE_SOURCES_OPERATION: string = 'graduateSourceOperation';
  static GRADUATE_EXTENSIONS_OPERATION: string = 'graduateExtensionsOperation';
  static CONTENT_TO_GRADUATE: string = 'contentToGraduate';
  static SOURCE_CONTENT_TO_GRADUATE: string = 'sourceContentToGraduate';
  static SETTING_FILENAME: string = 'settingFilename';
  static LOG_FILENAME: string = 'logFilename';
  static FORCE_GRADUATION: string = 'force';
  static LOG_LEVEL: string = 'logLevel';
  static KEY_TO_IGNORE: string = 'keyToIgnore';

  public start(): Promise<Answers> {
    const prompt = inquirer.createPromptModule();
    return this.loadFieldModel()
      .then((model: {}) => {
        return prompt(this.getQuestions({ fieldModel: model }));
      })
      .catch((err: any) => {
        console.error('Unable to load Field model.');
        return prompt(this.getQuestions({}));
      });
  }

  public loadFieldModel() {
    // tslint:disable-next-line:typedef
    return new Promise((resolve, reject) => {
      FieldAPI.getFieldModel().then((resp: RequestResponse) => {
        if (resp.body.definitions && resp.body.definitions.FieldModel && resp.body.definitions.FieldModel.properties) {
          resolve(_.keys(resp.body.definitions.FieldModel.properties));
        } else {
          reject('Unable to fetch field model');
        }
      });
    });
  }

  public getOriginOrganizationId(): Question {
    return {
      type: 'input',
      name: InteractiveMode.ORIGIN_ORG_ID,
      message: 'Origin Organization ID: ',
      validate: this.inputValidator('You need to provide the ID of the Organization')
    };
  }

  public getOriginOrganizationKey(): Question {
    return {
      type: 'input',
      name: InteractiveMode.ORIGIN_ORG_KEY,
      message: 'Origin Organization API Key: ',
      validate: this.inputValidator('You need to provide the API Key of the Organization')
    };
  }

  public getDestinationOrganizationId(): Question {
    return {
      type: 'input',
      name: InteractiveMode.DESTINATION_ORG_ID,
      message: 'Destination Organization ID: ',
      validate: this.inputValidator('You need to provide the ID of the Organization')
    };<commit_msg>adding a catch to fieldModel method<commit_after>import * as _ from 'underscore';
import * as inquirer from 'inquirer';
import { RequestResponse } from 'request';
import { Question } from 'inquirer';
import { Answers } from 'inquirer';
import { Utils } from '../commons/utils/Utils';
import { GraduateCommand } from '../commands/GraduateCommand';
import { DiffCommand } from '../commands/DiffCommand';
import { FieldController } from '../controllers/FieldController';
import { ExtensionController } from '../controllers/ExtensionController';
import { FieldAPI } from '../commons/rest/FieldAPI';

export class InteractiveMode {
  static ORIGIN_ORG_ID: string = 'originOrganizationId';
  static ORIGIN_ORG_KEY: string = 'originOrganizationKey';
  static DESTINATION_ORG_ID: string = 'destinationOrganizationId';
  static DESTINATION_ORG_KEY: string = 'destinationOrganizationKey';
  static COMMAND: string = 'command';
  static GRADUATE_FIELDS_OPERATION: string = 'graduateFieldsOperation';
  static GRADUATE_SOURCES_OPERATION: string = 'graduateSourceOperation';
  static GRADUATE_EXTENSIONS_OPERATION: string = 'graduateExtensionsOperation';
  static CONTENT_TO_GRADUATE: string = 'contentToGraduate';
  static SOURCE_CONTENT_TO_GRADUATE: string = 'sourceContentToGraduate';
  static SETTING_FILENAME: string = 'settingFilename';
  static LOG_FILENAME: string = 'logFilename';
  static FORCE_GRADUATION: string = 'force';
  static LOG_LEVEL: string = 'logLevel';
  static KEY_TO_IGNORE: string = 'keyToIgnore';

  public start(): Promise<Answers> {
    const prompt = inquirer.createPromptModule();
    return this.loadFieldModel()
      .then((model: {}) => {
        return prompt(this.getQuestions({ fieldModel: model }));
      })
      .catch((err: any) => {
        console.error('Unable to load Field model.');
        return prompt(this.getQuestions({}));
      });
  }

  public loadFieldModel() {
    // tslint:disable-next-line:typedef
    return new Promise((resolve, reject) => {
      FieldAPI.getFieldModel()
        .then((resp: RequestResponse) => {
          if (resp.body.definitions && resp.body.definitions.FieldModel && resp.body.definitions.FieldModel.properties) {
            resolve(_.keys(resp.body.definitions.FieldModel.properties));
          } else {
            reject('Unexpected response when trying to load field model');
          }
        })
        .catch((err: any) => {
          reject('Unable to fetch field model');
        });
    });
  }

  public getOriginOrganizationId(): Question {
    return {
      type: 'input',
      name: InteractiveMode.ORIGIN_ORG_ID,
      message: 'Origin Organization ID: ',
      validate: this.inputValidator('You need to provide the ID of the Organization')
    };
  }

  public getOriginOrganizationKey(): Question {
    return {
      type: 'input',
      name: InteractiveMode.ORIGIN_ORG_KEY,
      message: 'Origin Organization API Key: ',
      validate: this.inputValidator('You need to provide the API Key of the Organization')
    };
  }

  public getDestinationOrganizationId(): Question {
    return {
      type: 'input',
      name: InteractiveMode.DESTINATION_ORG_ID,
      message: 'Destination Organization ID: ',
      validate: this.inputValidator('You need to provide the ID of the Organization')
    };
{'fraction_non_alphanumeric': 0.11561142147734327, 'fraction_numerical': 0.0, 'mean_word_length': 3.871504157218443, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, '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': '1660906', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1814, 'n_words': 452}