<commit_before>package controllers;

import play.libs.ws.WSAuthScheme;
import play.libs.ws.WSClient;
import play.libs.ws.WSRequest;
import play.libs.ws.WSResponse;
import play.mvc.*;
import com.fasterxml.jackson.databind.JsonNode;
import play.libs.Json;

import services.JiraInfo;
import services.Utils;
import services.languageProcessor.Processor;

import javax.inject.Inject;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CompletionStage;

public class Application extends Controller {

  @Inject
  WSClient ws;

  private JiraInfo jiraInfo = Utils.getJiraInfo();

  public Result index() {
    return ok("Hi!");
  }

  public CompletionStage<Result> QA(String question) throws IOException,
    ClassNotFoundException, NoSuchMethodException,
    InvocationTargetException, IllegalAccessException {

    String question_mapping = Processor.processQuestion(question)[0];
    String ticket_id = Processor.processQuestion(question)[1];

    CompletionStage<WSResponse> responsePromise = null;

    if( question_mapping.startsWith("description") || question_mapping.startsWith("assignee")){
        responsePromise =  getTicketInfo(ticket_id);
    } else if (false){}
    else {}

    CompletionStage<Result> promiseOfResult = responsePromise.thenApply(response -> {
        try {
          return ok(processResponse(response.getBody(), question_mapping, ticket_id));
        } catch (Exception e) { e.printStackTrace();}
      return null;
      }
    );

    return promiseOfResult;
  }

  public CompletionStage<WSResponse> getTicketInfo(String ticket_id) {

    WSRequest request = ws.url("https://jira.agiledigital.com.au/rest/api/latest/issue/" + ticket_id);
    WSRequest complexRequest = request.setAuth(jiraInfo.account, jiraInfo.pwd, WSAuthScheme.BASIC);

    return complexRequest.get();
  }

  private JsonNode processResponse(String responseBody, String question_mapping, String ticket_id) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    String answer = services.languageProcessor.TaskMap.questionMapping(question_mapping, ticket_id);

    // parse the JSON as a JsonNode
    JsonNode json = Json.parse("{\"answer\":\"" +answer+ "\"}");

    return Json.parse(responseBody);
  }
}<commit_msg>change the return value type of requeset to JSON.<commit_after>package controllers;

import play.libs.ws.WSAuthScheme;
import play.libs.ws.WSClient;
import play.libs.ws.WSRequest;
import play.libs.ws.WSResponse;
import play.mvc.*;
import com.fasterxml.jackson.databind.JsonNode;
import play.libs.Json;

import services.JiraInfo;
import services.Utils;
import services.languageProcessor.Processor;

import javax.inject.Inject;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CompletionStage;

public class Application extends Controller {

  @Inject
  WSClient ws;

  private JiraInfo jiraInfo = Utils.getJiraInfo();

  public Result index() {
    return ok("Hi!");
  }

  public CompletionStage<Result> QA(String question) throws IOException,
    ClassNotFoundException, NoSuchMethodException,
    InvocationTargetException, IllegalAccessException {

    String[] nlpResult = Processor.processQuestion(question);
    String question_mapping = nlpResult[0];
    String ticket_id = nlpResult[1];

    CompletionStage<JsonNode> responsePromise = null;

    if( question_mapping.startsWith("description") || question_mapping.startsWith("assignee")){
        responsePromise =  getTicketInfo(ticket_id);
    } else if (false){}
    else {}

    CompletionStage<Result> promiseOfResult = responsePromise.thenApply(response -> {
        try {
          return ok(processResponse(response, question_mapping, ticket_id));
        } catch (Exception e) { e.printStackTrace();}
      return null;
      }
    );

    return promiseOfResult;
  }

  public CompletionStage<JsonNode> getTicketInfo(String ticket_id) {

    WSRequest request = ws.url("https://jira.agiledigital.com.au/rest/api/latest/issue/" + ticket_id);
    WSRequest complexRequest = request.setAuth(jiraInfo.account, jiraInfo.pwd, WSAuthScheme.BASIC);

    return complexRequest.get().thenApply(WSResponse :: asJson);
  }

  private JsonNode processResponse(JsonNode responseBody, String question_mapping, String ticket_id) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {

    String answer = services.languageProcessor.TaskMap.questionMapping(question_mapping, ticket_id);

    // parse the JSON as a JsonNode
    JsonNode json = Json.parse("{\"answer\":\"" +answer+ "\"}");

    return responseBody;
  }
}
{'fraction_non_alphanumeric': 0.10407725321888411, 'fraction_numerical': 0.0008583690987124463, 'mean_word_length': 4.684146341463415, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '397800', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1296, 'n_words': 280}