<commit_before>package services.languageProcessor;

import com.fasterxml.jackson.databind.JsonNode;
import play.Configuration;
import play.api.Play;
import play.libs.Json;

import scala.util.parsing.json.JSONArray;
import services.IntentEntity;
import services.Response;
import services.queryHandler.Extractor;
import services.Utils;

import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.List;

public class TaskMap {
  private Configuration configuration = Play.current().injector().instanceOf(Configuration.class);

  /**
   * This method calls appropriate method on run time based on the
   * parameters (methodName and argName) passed and returns a value
   * returned by that method.
   * @param methodName
   * @param issueKey
   * @return
   */
  public static JsonNode questionMapping(String methodName, String issueKey, JsonNode responseBody) {

    TaskMap taskMap = new TaskMap();

    try {

      //call the method at runtime according to the argument "methodName"
      Method method = TaskMap.class.getMethod(methodName, String.class, JsonNode.class);

      JsonNode returnVal = (JsonNode) method.invoke(taskMap, issueKey, responseBody);
      return returnVal;

    } catch (NoSuchMethodException e) {
      return parseToJson("fail", e.getMessage());
    } catch (InvocationTargetException e) {
      return parseToJson("fail", e.getMessage());
    } catch (IllegalAccessException e) {
      return parseToJson("fail", e.getMessage());
    } catch (NullPointerException e) {
      return parseToJson("fail", e.getMessage());
    }
  }


  /**
   * This method requests issue info and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
  public JsonNode IssueDescription(String issueKey, JsonNode responseBody) {
    if (Extractor.getIssueDscription(responseBody, "description").equals("[\"Issue Does Not Exist\"]")) {
      return parseToJson("fail", "Cannot find issue");
    } else {

      String IssueId = responseBody.get("key").toString().replaceAll("\"", "");
      String IssueUrl = "http://jira.agiledigital.com.au/browse/" + IssueId;
      String Hyperlink = "<" + IssueUrl+ "|" + IssueId + ">";

      String answer = "Description of " + Hyperlink + " is as follows: \n" +
        Extractor.extractString(responseBody, "description");

      return parseToJson("success", answer);
    }

  }

  /**
   * This method requests assignee of issue and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
  public JsonNode IssueAssignee(String issueKey, JsonNode responseBody) {
    if (Extractor.getIssueAssignee(responseBody, "assignee").equals("[\"Issue Does Not Exist\"]")) {
      return parseToJson("fail", "Cannot find issue");
    } else {
      String answer = Extractor.getIssueAssignee(responseBody, "assignee") + " is working on " + issueKey + ".";
      System.out.println(answer);
      return parseToJson("success", answer);
    }
  }

  /** This method requests brief description of issue and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
  public JsonNode IssueBrief(String issueKey, JsonNode responseBody) {
    if (Extractor.getIssueBrief(responseBody, "assignee").equals("[\"Issue Does Not Exist\"]")) {
      return parseToJson("fail", "Cannot find issue");
    } else {
      String IssueId = responseBody.get("key").toString().replaceAll("\"", "");
      String IssueUrl = "http://jira.agiledigital.com.au/browse/" + IssueId;
      String Hyperlink = "<" + IssueUrl+ "|" + IssueId + ">";

      String answer = Extractor.extractString(responseBody, "assignee") + " is working on " + Hyperlink + ".";

      System.out.println(answer);
      return parseToJson("success", answer);
    }
  }

  /** This method requests status of an issue and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */<commit_msg>BugFix after resolving conflict.<commit_after>package services.languageProcessor;

import com.fasterxml.jackson.databind.JsonNode;
import play.Configuration;
import play.api.Play;
import play.libs.Json;

import scala.util.parsing.json.JSONArray;
import services.IntentEntity;
import services.Response;
import services.queryHandler.Extractor;
import services.Utils;

import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.List;

public class TaskMap {
  private Configuration configuration = Play.current().injector().instanceOf(Configuration.class);

  /**
   * This method calls appropriate method on run time based on the
   * parameters (methodName and argName) passed and returns a value
   * returned by that method.
   * @param methodName
   * @param issueKey
   * @return
   */
  public static JsonNode questionMapping(String methodName, String issueKey, JsonNode responseBody) {

    TaskMap taskMap = new TaskMap();

    try {

      //call the method at runtime according to the argument "methodName"
      Method method = TaskMap.class.getMethod(methodName, String.class, JsonNode.class);

      JsonNode returnVal = (JsonNode) method.invoke(taskMap, issueKey, responseBody);
      return returnVal;

    } catch (NoSuchMethodException e) {
      return parseToJson("fail", e.getMessage());
    } catch (InvocationTargetException e) {
      return parseToJson("fail", e.getMessage());
    } catch (IllegalAccessException e) {
      return parseToJson("fail", e.getMessage());
    } catch (NullPointerException e) {
      return parseToJson("fail", e.getMessage());
    }
  }


  /**
   * This method requests issue info and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
  public JsonNode IssueDescription(String issueKey, JsonNode responseBody) {
    if (Extractor.getIssueDscription(responseBody, "description").equals("[\"Issue Does Not Exist\"]")) {
      return parseToJson("fail", "Cannot find issue");
    } else {

      String IssueId = responseBody.get("key").toString().replaceAll("\"", "");
      String IssueUrl = "http://jira.agiledigital.com.au/browse/" + IssueId;
      String Hyperlink = "<" + IssueUrl+ "|" + IssueId + ">";

      String answer = "Description of " + Hyperlink + " is as follows: \n" +
        Extractor.getIssueDscription(responseBody, "description");

      return parseToJson("success", answer);
    }

  }

  /**
   * This method requests assignee of issue and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
  public JsonNode IssueAssignee(String issueKey, JsonNode responseBody) {
    if (Extractor.getIssueAssignee(responseBody, "assignee").equals("[\"Issue Does Not Exist\"]")) {
      return parseToJson("fail", "Cannot find issue");
    } else {
      String answer = Extractor.getIssueAssignee(responseBody, "assignee") + " is working on " + issueKey + ".";
      System.out.println(answer);
      return parseToJson("success", answer);
    }
  }

  /** This method requests brief description of issue and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
  public JsonNode IssueBrief(String issueKey, JsonNode responseBody) {
    if (Extractor.getIssueDscription(responseBody, "description").equals("[\"Issue Does Not Exist\"]")) {
      return parseToJson("fail", "Cannot find issue");
    } else {

      String IssueId = responseBody.get("key").toString().replaceAll("\"", "");
      String IssueUrl = "http://jira.agiledigital.com.au/browse/" + IssueId;
      String Hyperlink = "<" + IssueUrl+ "|" + IssueId + ">";

      String answer = "Description of " + Hyperlink + " is as follows: \n" +
        Extractor.getIssueDscription(responseBody, "description");

      return parseToJson("success", answer);
    }
  }

  /** This method requests status of an issue and returns it to the calling method
   * @param issueKey is the IssueID of type string which was mentioned in the query by the user.
   * @param responseBody is the JSON object received from JIRA Rest API.
   * @return reply to the user in JSON format.
   */
{'fraction_non_alphanumeric': 0.1081579518333695, 'fraction_numerical': 0.0, 'mean_word_length': 3.6210526315789475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1364627', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2513, 'n_words': 879}