package services;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import play.Configuration;
import play.api.Play;

import java.io.*;

public class Utils {
  public static JiraInfo getJiraInfo(Configuration configuration){
   return new JiraInfo(configuration.getString("jira.username"), configuration.getString("jira.password"));
  }

  public static void writeMissedQuery(String missedQuestion){
    try {
      BufferedWriter out = new BufferedWriter
        (new FileWriter("logs/missedQuery.log", true));
      out.write(missedQuestion+"\n");
      out.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static String hyperlinkTicketNo(String issueDescription){
    Configuration configuration = Play.current().injector().instanceOf(Configuration.class);

    String jiraIssueName = configuration.getString("jira.issueName");
    String pattern = "(" + jiraIssueName + "-\\d+)";
    String issueUrl = configuration.getString("jira.baseUrl") + "/browse/";
    String hyperlink = "<" + issueUrl + "$1|$1>";

    issueDescription = issueDescription.replaceAll(pattern, hyperlink);

    return issueDescription;
  }
}


@@ -405,37 +405,40 @@
 tic 
-void writeMissedQuery
+String hyperlinkTicketNo
 (String 
 miss
@@ -433,26 +433,28 @@
 (String 
-m
 iss
-edQues
+ueDescrip
 tion)%7B%0A 
@@ -460,374 +460,742 @@
     
-try %7B
+/**
 %0A     
- BufferedWriter out = new BufferedWriter%0A        (new FileWriter(%22logs/missedQuery.log%22, true));%0A      out.write(missedQuestion+%22%5Cn%22);%0A      out.close();%0A    %7D catch (FileNotFoundException e) %7B%0A      e.printStackTrace();%0A    %7D catch (IOException e) %7B%0A      e.printStackTrace();%0A    %7D%0A  %7D%0A%0A  public static String hyperlinkTicketNo(String issueDescription)%7B
+* The methods hyperlinks the ticket number appearing in the%0A     * description, or actually, any string fed into. This is implemented%0A     * by first checking the project name configured in the application.conf%0A     * and then use the slack formatting to wrap around the ticket number.%0A     *%0A     * @Reference: https://api.slack.com/docs/message-formatting%0A     *%0A     * @param issueDescription the description of the ticket queried.%0A     *                         This can also be applied to any other strings.%0A     * @return                 the issue description after formatting. This%0A     *                         should hyperlink the ticket numbers appearing in%0A     *                         the input string.%0A     */
 %0A   

comment the hyperlink method. remove a deprecated method for storing question in file(now in DB).