main.MainClass.java Source code

Java tutorial

Introduction

Here is the source code for main.MainClass.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import JSONParser.JSONOperations;
import apimanager.ZohoReportsAPIManager;
import loggerapi.CustomLogger;
import fileoperations.FileOperations;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import mailutil.MailOperations;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import apimanager.ZohoSupportAPIManager;
import java.io.FileInputStream;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.json.simple.parser.ParseException;
import xmlparser.SAXParser;

/**
 *
 * @author harsha-1916
 */
public class MainClass {

    /**
     * @param args the command line arguments
     */
    private static final CustomLogger loggerProperties = new CustomLogger();
    private static Logger loggerObj;
    private static final String URLPARAMS = "urlparams";
    private static final String SEARCHPARAMS = "searchparams";
    private static final String COLUMNS = "columns";
    private static final String AUTHTOKEN = "authtoken";
    private static final String PORTAL = "portal";
    private static final String DEPARTMENT = "department";

    static {
        initializeLoggerParams();
    }

    private static void initializeLoggerParams() {

        boolean isValidLogger = loggerProperties.setLoggerProperties("weeklyMailSender",
                "./Logs/Mainclass.%u.%g.txt");
        if (isValidLogger) {
            loggerObj = loggerProperties.getLogger();
            //loggerObj.setUseParentHandlers(false);
        }

    }

    public JSONObject sortJSONWithModuleCount(JSONObject moduleSummary) {

        //Set<String> ModuleNames = ModVsCountVsOwner.keySet();
        LinkedList ModvsCountOwnerList = new LinkedList();

        Set<String> moduleKeys = moduleSummary.keySet();
        for (Iterator indiModuleItr = moduleKeys.iterator(); indiModuleItr.hasNext();) {
            String moduleName = (String) indiModuleItr.next();
            JSONObject indiModuleJO = (JSONObject) moduleSummary.get(moduleName);

            int count = (Integer) indiModuleJO.get("Count");
            String moduleOwner = (String) indiModuleJO.get("Owner");
            JSONObject sortedelement = new JSONObject();
            sortedelement.put("moduleName", moduleName);
            sortedelement.put("moduleCount", count);
            sortedelement.put("moduleOwner", moduleOwner);

            if (ModvsCountOwnerList.isEmpty()) {
                ModvsCountOwnerList.add(sortedelement);
            } else {
                Iterator listIterator = ModvsCountOwnerList.iterator();
                JSONObject smallElement;
                int index = 0;
                boolean isLoopBreak = false;

                while (listIterator.hasNext()) {
                    smallElement = (JSONObject) listIterator.next();
                    int smallCount = (Integer) smallElement.get("moduleCount");
                    if (smallCount <= count) {
                        isLoopBreak = true;
                        break;
                    }
                    index++;
                }
                if (listIterator.hasNext()) {
                    ModvsCountOwnerList.add(index, sortedelement);

                } else if (isLoopBreak) {
                    ModvsCountOwnerList.add(index, sortedelement);
                } else {
                    ModvsCountOwnerList.add(sortedelement);
                }

            }
        }
        //System.out.println("LinkedList: " + ModvsCountOwnerList.toString());
        JSONObject sortedModuleSummary = new JSONObject();
        sortedModuleSummary.put("moduleSummary", ModvsCountOwnerList);
        return sortedModuleSummary;
    }

    public String MEMDM_Mod_Count_OwnerJSONToHTML(JSONObject moduleSummary) {
        String result = "";

        JSONObject SortedMod_Count_Owner = sortJSONWithModuleCount(moduleSummary);
        LinkedList SortedList = (LinkedList) SortedMod_Count_Owner.get("moduleSummary");
        Iterator listIterator = SortedList.iterator();

        while (listIterator.hasNext()) {

            JSONObject resultJSONObject = (JSONObject) listIterator.next();
            String moduleName = resultJSONObject.get("moduleName").toString();
            String moduleCount = resultJSONObject.get("moduleCount").toString();
            String moduleOwner = resultJSONObject.get("moduleOwner").toString();

            result += "<tr>\n"
                    + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(255, 255, 255);\" rowspan=\"1\"><br style=\"text-align: left; vertical-align: top; background-color: rgb(255, 255, 255);\">"
                    + moduleName + "</td>\n"
                    + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(255, 255, 255);\" rowspan=\"1\"><br style=\"text-align: left; vertical-align: top; background-color: rgb(255, 255, 255);\">"
                    + moduleCount + "</td>\n"
                    + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(255, 255, 255);\" rowspan=\"1\"><br style=\"text-align: left; vertical-align: top; background-color: rgb(255, 255, 255);\">"
                    + moduleOwner + "</td>\n" + "      </tr>\n";

        }
        return result;

    }

    public String[] WOETicketsJSONArrToHTML(JSONArray WOETicketsJSONArray, String status) {
        String result = "";
        Integer count = 0;
        if (WOETicketsJSONArray == null) {
            return null;
        }

        Iterator itr = WOETicketsJSONArray.iterator();
        while (itr.hasNext()) {
            JSONObject WOERow = (JSONObject) itr.next();
            if (WOERow.get("Status").toString().equals(status)) {
                /*result += "<tr>\n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Created Time").toString() + "</td> \n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + "<a href= \"" + "https://support.zoho.com" + WOERow.get("URI") + "\" +>" + WOERow.get("Ticket Id").toString() + "</a>" + "</td> \n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Email").toString() + "</td>\n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Subject").toString() + "</td>\n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Developers").toString() + "</td>\n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Ticket Owner").toString() + "</td>\n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Modules").toString() + "</td>\n"
                 + "            <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Due Date").toString() + "</td>\n"
                 + "                             <td valign=\"top\" style=\"width: 11.111%;\" rowspan=\"1\">" + WOERow.get("Problem Description").toString() + "</td>\n"
                 + "         </tr>";
                 }*/

                result += "<tr>\n" + "            <td valign=\"top\" >" + WOERow.get("Created Time").toString()
                        + "</td> \n" + "            <td valign=\"top\" >" + "<a href= \""
                        + "https://support.zoho.com" + WOERow.get("URI") + "\" +>"
                        + WOERow.get("Ticket Id").toString() + "</a>" + "</td> \n"
                        + "            <td valign=\"top\" >" + WOERow.get("Email").toString() + "</td>\n"
                        + "            <td valign=\"top\" >" + WOERow.get("Problem Description").toString()
                        + "</td>\n" + "            <td valign=\"top\" >" + WOERow.get("Issue Type").toString()
                        + "</td>\n" + "            <td valign=\"top\" >" + WOERow.get("Modules").toString()
                        + "</td>\n" + "            <td valign=\"top\" >" + WOERow.get("Developers").toString()
                        + "</td>\n" + "            <td valign=\"top\" >" + WOERow.get("Ticket Owner").toString()
                        + "</td>\n" + "                             <td valign=\"top\" >"
                        + WOERow.get("Due Date").toString() + "</td>\n"
                        + "                             <td valign=\"top\" >"
                        + WOERow.get("Last Updated At").toString() + "</td>\n" + "         </tr>";
                count++;
            }
        }

        if (result.equals("")) {
            result += "<tr >\n" + "<td colspan=\"9\"><center style=\"color: rgb(255, 0, 0);\">"
                    + "No pending tickets available" + "</center></td></tr> \n";
        }

        return new String[] { result, count.toString() };
    }

    private String[] parseCommandLineArgs(String[] args) {
        String mode = null;
        String mailId = null;
        if (args != null) {
            for (int i = 0; i < args.length; i++) {
                if (args[i].toLowerCase().contains("mode")) {
                    mode = args[i].split("=")[1].toLowerCase();
                }

                if (args[i].toLowerCase().contains(("mailid"))) {
                    mailId = args[i].split("=")[1];
                }
            }

        }
        if (mode == null) {
            mode = "internal";
        }

        if (mailId == null) {
            mailId = "harshavardhan.r@zohocorp.com";
        }

        return new String[] { mode, mailId };
    }

    /**
     *
     * @param args The args is an String array parameter which must be used to
     * give two inputs to the method. They are mode and the maild. They must be
     * specified in the specified format like: mode=<paramvalue>
     * mailId=<paramvalue>
     *
     * for mode paramvalue there are two values: internal and external. mailId
     * paramvalue should be given to specify to which mail ID the mail generated
     * by this application must be sent to.
     *
     */
    public static void main(String[] args) {
        // TODO code application logic here
        loggerObj.log(Level.INFO, "Inside main");
        MainClass objForParsingArgs = new MainClass();
        String commandLineArgs[] = objForParsingArgs.parseCommandLineArgs(args);

        String mode = commandLineArgs[0];
        String mailId = commandLineArgs[1];
        loggerObj.log(Level.INFO, "Picked up values: mode=" + mode + " mail=" + mailId);

        objForParsingArgs.deferenceObjects(new Object[] { objForParsingArgs, commandLineArgs, args });

        //Don't Delete : Used to generate open and closed summary issues in MEMDM Support portal
        //MainClass MDMIssMgrMailSender = new MainClass();
        //MDMIssMgrMailSender.IssueMgrStatusSummGen(mode, mailId);
        //Don't Delete : MEDC Support WOE Ticket generator
        //MainClass MEDCSupportMailSender = new MainClass();
        //MEDCSupportMailSender.MEDCSup_WOE_SummGen(mode, mailId);
        //Don't Delete :Issue manager sync from support tickets api:
        //MainClass issueMgrSupport = new MainClass();
        //issueMgrSupport.SupportToReportsSyncer(mode);
        //Don't Delete : AutoMail forwarder:

        //MainClass AutoMailForward = new MainClass();
        //AutoMailForward.autoMailForward(mode, mailId);
    }

    private String SupportToReportsSyncer(String mode) {

        loggerObj.log(Level.INFO, "Inside SupportToReportsSyncer method");

        String masterConfigFile = "./conf/SupportToReportsSyncer/masterconfig.props";
        ArrayList<String> fileLocation = FileOperations.getFilesLocForSupToRepSync(masterConfigFile);

        if (fileLocation == null || fileLocation.size() == 0) {
            loggerObj.log(Level.INFO, "Cannot get conf file Locations from master config file " + masterConfigFile);
            return null;
        }

        loggerObj.log(Level.INFO, "The conf files obtained from master config file is " + fileLocation.toString());

        for (Iterator indiFileItr = fileLocation.iterator(); indiFileItr.hasNext();) {

            String indiFileLoc = (String) indiFileItr.next();

            JSONObject supportToreportsDetails = initializeSupportToReportsDetails(indiFileLoc);

            if (supportToreportsDetails == null) {
                System.out.println("The config file is empty or does not contain proper data");
                return "JSON OBJECT READ FROM FILE IS NULL";
            }
            try {
                loggerObj.log(Level.INFO, "Received supportToreports details json object after parsing the file is "
                        + supportToreportsDetails.toJSONString());

                JSONObject supDetails = (JSONObject) supportToreportsDetails.get("supDetails");
                JSONObject repDetails = (JSONObject) supportToreportsDetails.get("repDetails");

                loggerObj.log(Level.INFO,
                        "Going to parse Config file to get support details and query support data from support.zoho.com");
                System.out.println(
                        "Going to parse Config file to get support details and query support data from support.zoho.com");
                String folderToWriteResponse = "./fromServer/SupportToReportsSyncer";
                String[] responseString = getSupportDataWithConfigDetails(supDetails, mode, folderToWriteResponse,
                        false, "SupportToReportSyncer");

                if (responseString == null) {
                    System.out
                            .println("The config file does not contain essential support configuration data data");
                    loggerObj.log(Level.SEVERE,
                            "The config file does not contain essential support configuration data data");
                    return "REPORT DETAILS IN JSON OBJECT READ FROM FILE IS NULL";
                }

                //https://support.zoho.com/api/json/requests/getrecords?authtoken=8ecc8d0229b00b83d4c398b19a4282bc&portal=memdmissuemgr&department=MDM%20Issue%20Mgr&selectfields=requests(Ticket%20Id,Created%20At,Module,Functionality,Immediate%20priority,Status,Issue%20Source,Issue%20Type,Priority,OS%20Platform,Customer%20Email,Request%20Tag,Ticket%20Owner,Modified%20Time,Modified%20By,Ticket%20Closed%20Time,Old%20Issue%20ID,To%20Address,Email,Subject,Developer%20Comments,Customer%20Description)//
                String folderToReadFrom = responseString[0];
                int numOfSupFiles = Integer.parseInt(responseString[1]);
                loggerObj.log(Level.INFO,
                        "Response String received from Support api/Internal files is: folderToReadFrom"
                                + folderToReadFrom + " Number of files is " + numOfSupFiles);
                System.out.println("support data is fetched from support.zoho.com");

                //This is used to write the ResponseJSONArray to file system so that it can be used for future parsing
                loggerObj.log(Level.INFO,
                        "Going to parse the data from supportToReport config file to get ExtraColumns data");
                System.out.println(
                        "Going to parse the data from supportToReport config file to get ExtraColumns data");
                JSONObject extraColumnsJSONObj = getExtraColumnsForReports(repDetails);

                loggerObj.log(Level.INFO,
                        "Going to parse the data from supportToReport config file to get column names that need change in reports");
                JSONObject SupToRepHdrChgJSONObj = getSupToRepNameChngeCol(repDetails);

                loggerObj.log(Level.INFO,
                        "Going to parse the data from supportToReport config file to change column names that need change in reports");
                JSONObject SupToRepHdrObj = getFinalSupToRepColName(SupToRepHdrChgJSONObj, extraColumnsJSONObj,
                        supDetails);

                loggerObj.log(Level.INFO,
                        "Going to parse the data downloaded from support to change to a format to upload tp reports");
                Integer reportsFileNum = 1;
                String currTime = getCurrTimeInDD_MM_YY_HH_MM_SS();
                String folderToWriteParsedResponse = "./parsed_output/SupportToReportsSyncer/" + currTime;

                boolean createFolderToWriteResponse = new File(folderToWriteParsedResponse).mkdirs();

                if (!createFolderToWriteResponse) {
                    loggerObj.log(Level.INFO,
                            "Cannot create a folder" + folderToWriteParsedResponse + " to write response");
                    return null;
                }
                JSONOperations parserObj = new JSONOperations();
                for (int i = 1; i <= numOfSupFiles; i++) {
                    String fileToReadFrom = folderToReadFrom + i + ".json";
                    JSONObject responseFromSup = (JSONObject) FileOperations.readFromJSONFile(fileToReadFrom);
                    JSONArray issueMgrJSONArray = parserObj.SupJOToReportsJA(responseFromSup, extraColumnsJSONObj,
                            SupToRepHdrChgJSONObj, "row");

                    if (issueMgrJSONArray == null) {
                        loggerObj.log(Level.INFO,
                                "Processed JSON from zoho support to delver to reports is null while reading file "
                                        + fileToReadFrom);
                        System.out.println("Processed JSON from zoho support to delver to reports is null");
                        return "PROCESSED JSON FOR REPORTS IS NULL";
                    }

                    String fileToWriteParsedResponse = folderToWriteParsedResponse + "/ParsedJSON_" + reportsFileNum
                            + ".json";
                    loggerObj.log(Level.INFO,
                            "Processed JSON from zoho support. GOing to write it to a file to import to zoho reports"
                                    + fileToWriteParsedResponse);
                    boolean isFileWriteSuccess = FileOperations.writeObjectToFile(issueMgrJSONArray,
                            fileToWriteParsedResponse);
                    //System.out.println("Processed JSON from zoho support. GOing to write it to a file to import to zoho reports"); 
                    if (!isFileWriteSuccess) {
                        loggerObj.log(Level.INFO,
                                "Error occurred while writing Processed JSON from zoho support to delver to reports to the file located in"
                                        + fileToWriteParsedResponse);
                        return "ERROR IN WRITING PROCESSED JSON TO FILE " + fileToWriteParsedResponse;
                    }
                    loggerObj.log(Level.INFO,
                            "Processed JSON from zoho support is writtrn to a file to import to zoho reports"
                                    + fileToWriteParsedResponse);
                    reportsFileNum++;
                }

                //Need to have invalid jsonarray check also//
                JSONArray repConnectionParams = getRepDetailsFromConfigFile(repDetails);

                //Handling null check if any required field is not present;
                if (repConnectionParams.size() == 1) {
                    JSONObject errorJSON = (JSONObject) repConnectionParams.get(0);
                    ArrayList<String> nullFields = (ArrayList<String>) errorJSON.get("nullFields");
                    loggerObj.log(Level.INFO,
                            "The following fields required to make connection to reports is not present"
                                    + nullFields.toString());
                    System.out.println("The following fields required to make connection to reports is not present"
                            + nullFields.toString());
                    return null;
                }

                // Handling error case to check if the Matching columns are not present in Reports column
                if (repDetails.get("ZOHO_MATCHING_COLUMNS") != null) {
                    String[] matchingColumns = repDetails.get("ZOHO_MATCHING_COLUMNS").toString().split(",");
                    boolean isPresent = false;
                    ArrayList<String> matchingColNotInRepColn = null;

                    for (String i : matchingColumns) {

                        Set<String> repColns = SupToRepHdrObj.keySet();
                        for (Iterator it = repColns.iterator(); it.hasNext();) {
                            String repColnHdr = it.next().toString();
                            if (repColnHdr.equals(i)) {
                                isPresent = true;
                            }
                        }
                        if (isPresent != true) {
                            if (matchingColNotInRepColn == null) {
                                matchingColNotInRepColn = new ArrayList<>();
                            }
                            matchingColNotInRepColn.add(i);
                        }
                        isPresent = false;
                    }
                    if (matchingColNotInRepColn != null) {
                        loggerObj.log(Level.INFO,
                                "The following fields are present in Matching columns but not in Report columns"
                                        + matchingColNotInRepColn.toString());
                        System.out.println(
                                "The following fields required to make connection to reports is not present"
                                        + matchingColNotInRepColn.toString());
                        return null;
                    }
                } else {
                    if (repDetails.get("ZOHO_IMPORT_TYPE").equals("UPDATEADD")) {
                        loggerObj.log(Level.SEVERE,
                                "Please provide the matching columns as it is mandatory for UPDATEADD import type in config file.");
                        System.out.println(
                                "Please provide the matching columns as it is mandatory for UPDATEADD import type in config file.");
                        return null;
                    }
                }

                JSONObject urlParams = (JSONObject) repConnectionParams.get(0);
                JSONObject postParams = (JSONObject) repConnectionParams.get(1);
                repConnectionParams = null;

                loggerObj.log(Level.INFO, "urlParams is " + urlParams.toJSONString());
                loggerObj.log(Level.INFO, "postParams is " + postParams.toJSONString());

                loggerObj.log(Level.INFO, "Going to bulk import the json file in the folder "
                        + folderToWriteParsedResponse + " to the reports");

                System.out.println("Going to bulk import in to the reports:");
                for (int i = 1; i <= reportsFileNum - 1; i++) {

                    String fileToUploadToReports = folderToWriteParsedResponse + "/ParsedJSON_" + i + ".json";
                    loggerObj.log(Level.INFO, "Going to upload " + fileToUploadToReports + "to reports");
                    postParams.put("jsonFileName", fileToUploadToReports);

                    ZohoReportsAPIManager reportsClient = new ZohoReportsAPIManager();
                    boolean isSuccessfullImport = false;
                    try {
                        isSuccessfullImport = reportsClient.postBulkJSONImport(urlParams, postParams);
                    } catch (IOException ex) {
                        loggerObj.log(Level.INFO, "Problem in bulk importing the json file " + fileToUploadToReports
                                + " to the reports");
                        System.out.println("Problem in bulk importing the json file to the reports");
                    }

                    if (isSuccessfullImport) {
                        loggerObj.log(Level.INFO, "Successfully bulk imported the json file  "
                                + fileToUploadToReports + " to the reports");
                        System.out.println("Successfully bulk imported the json file  " + fileToUploadToReports
                                + " to the reports");
                    } else {
                        loggerObj.log(Level.INFO, "Probelem in bulk importing the json file  "
                                + fileToUploadToReports + " to the reports");
                        System.out.println("Probelem in bulk importing the json file  " + fileToUploadToReports
                                + " to the reports");
                    }

                }

            } catch (Exception e) {
                loggerObj.log(Level.SEVERE, "Some problem in Syncing support with reports. Exception is");
                loggerObj.log(Level.SEVERE, e.getMessage(), e);
                System.out.println("Exception is " + e.toString());
                return null;
            }

        }

        return null;
    }

    private boolean deferenceObjects(Object[] objectArr) {
        for (int i = objectArr.length; i < objectArr.length; i++) {
            objectArr[i] = null;
        }
        return true;
    }

    private String[] getTicketIdsFromMEMDM(String mode) {
        String MEMDMconfigFile = "./conf/AutoMailForward/memdm/connectionconfig.props";
        JSONObject MEMDMsupDetails = initializeSupportDetails(MEMDMconfigFile);
        if (MEMDMsupDetails == null) {
            loggerObj.log(Level.SEVERE,
                    "Problem in parsing " + MEMDMconfigFile + "to get support.zoho.com details");
            return null;
        }

        String[] responseString = null;
        String folderwriteResponse = null;
        if (mode.equals("external")) {
            folderwriteResponse = "./fromServer/AutoMailForward";
        }
        if (mode.equals("internal")) {

            folderwriteResponse = "./TestFiles/fromServer/AutoMailForward/memdm/26_02_16_04_33_57_old";
        }
        responseString = getSupportDataWithConfigDetails(MEMDMsupDetails, mode, folderwriteResponse, false,
                "AutoMailForward_TicketIds");
        deferenceObjects(new Object[] { MEMDMconfigFile, MEMDMsupDetails });

        if (responseString == null) {
            loggerObj.log(Level.SEVERE,
                    "Response data from MEMDM support.zoho.com while retrieving ticket id is empty/null");
            return null;
        }

        String folderToReadFrom = responseString[0];
        Integer index = Integer.parseInt(responseString[1]);

        loggerObj.log(Level.INFO,
                "The details obtained from support is: index: " + index + " folderToreadFrom: " + folderToReadFrom);

        JSONOperations parserObj = new JSONOperations();

        int folderIndex = folderToReadFrom.lastIndexOf("/");

        String fileStrucToWriteTickets = folderToReadFrom.substring(0, folderIndex) + "/ticketsIds_";
        for (int i = 1; i <= index; i++) {
            String fileToReadFrom = folderToReadFrom + i + ".json";
            JSONObject responseFromSup = (JSONObject) FileOperations.readFromJSONFile(fileToReadFrom);
            ArrayList<String> ticetIds = parserObj.parseTicketIdFromSub(responseFromSup, "row");
            if (ticetIds == null) {

                loggerObj.log(Level.SEVERE, "No ticket ids are found in MEMDM support to forward");
                return null;
            }
            String fileToWriteTickets = fileStrucToWriteTickets + i + ".csv";
            boolean isFileWriteSuccess = FileOperations.writeCollectionToFile(ticetIds, ",", fileToWriteTickets);
            if (!isFileWriteSuccess) {
                loggerObj.log(Level.INFO, "Issue writting ticket ids to the file " + fileToWriteTickets);
                return null;
            }
        }

        loggerObj.log(Level.INFO, "Successfully got ticket ids from support to the folder" + fileStrucToWriteTickets
                + "and index is" + index);
        return new String[] { fileStrucToWriteTickets, index.toString() };

    }

    private boolean autoMailForward(String mode, String mailid) {
        loggerObj.log(Level.INFO, "Inside Automail Forward");
        //Need to check properly with external for this getTicketIdsFromMEMDM alone. Because it gives all the ticketids and we need to 
        //use it properly because it will involve lot of requests to the support.zoho.com if we get threadIds and threadContents for all the 
        //ticketIds returned by this method.

        //Don't Delete this line as this is needed for external
        //String[] TicketIdsFileDtls = getTicketIdsFromMEMDM(mode);

        //This is used for test purpose
        String[] TicketIdsFileDtls = new String[] { "./TestFiles/fromServer/AutoMailForward/memdm", "1" };

        if (TicketIdsFileDtls == null) {
            System.out.println("The ticketIds file received from MEDC portal is empy");
            return false;
        }

        String folderToReadTicketIds = TicketIdsFileDtls[0];
        int tickedIdFileCount = Integer.parseInt(TicketIdsFileDtls[1]);

        String configFile = "./conf/AutoMailForward/medcs/connectionConfig.props";
        JSONObject supDetails = initializeSupportDetails(configFile);

        loggerObj.log(Level.INFO,
                "connection config details obtained form " + configFile + "is: " + supDetails.toJSONString());
        if (supDetails == null) {
            loggerObj.log(Level.SEVERE, "Problem in parsing " + configFile + "to get support.zoho.com details");
            return false;
        }

        for (int fileCount = 1; fileCount <= tickedIdFileCount; fileCount++) {
            String fileToReadTicketIdsFrom = folderToReadTicketIds + "/ticketsIds_" + fileCount + ".csv";
            List<String> ticketIds = FileOperations.readStringArrFromCSVFile(fileToReadTicketIdsFrom);
            loggerObj.log(Level.INFO, "Ticket Ids obtained from " + fileToReadTicketIdsFrom + ticketIds.toString());

            for (Iterator ticketIdItr = ticketIds.iterator(); ticketIdItr.hasNext();) {
                String[] searchParams = (String[]) supDetails.get("searchparams");

                if (searchParams == null) {
                    searchParams = new String[] { "Request Id", ticketIdItr.next().toString() };
                }

                supDetails.put(SEARCHPARAMS, searchParams);
                String rootFolder = null;
                String[] dataFromSupport = null;
                if (mode.equals("external")) {
                    rootFolder = "./fromServer/AutoMailForward/caseIds";
                }
                if (mode.equals("internal")) {
                    // Dont know whether this is the correct internal file. If it is not working , then proeprly change it after testing.
                    rootFolder = "./TestFiles/fromServer/AutoMailForward/caseIds/medcs/27_02_16_21_03_39";
                }
                dataFromSupport = getSupportDataWithConfigDetails(supDetails, mode, rootFolder, false,
                        "AutoMailForward_CaseIds");
                supDetails = null;

                if (dataFromSupport == null) {
                    loggerObj.log(Level.SEVERE, "Problem in getting details from support.zoho.com");
                    return false;
                }

                int index = Integer.parseInt(dataFromSupport[1]);
                String folderToReadFrom = dataFromSupport[0];

                loggerObj.log(Level.INFO, "The details obtained from support is: index: " + index
                        + " folderToreadFrom: " + folderToReadFrom);

                JSONOperations parserObj = new JSONOperations();
                String[] caseId = new String[index];
                for (int i = 1; i <= index; i++) {
                    String fileToReadFrom = folderToReadFrom + i + ".json";
                    JSONObject responseFromSup = (JSONObject) FileOperations.readFromJSONFile(fileToReadFrom);
                    ArrayList<String> caseIdObj = parserObj.parseWithColumnHeaderCri(responseFromSup, "CASEID",
                            "row");
                    if (caseIdObj != null && caseIdObj.size() == 1) {
                        caseId[i - 1] = caseIdObj.get(0);
                        loggerObj.log(Level.INFO, "Case Id obtained from support is " + caseId[i - 1]
                                + "by reading file " + fileToReadFrom);
                    } else {
                        loggerObj.log(Level.SEVERE, "Problem in retrieving Case ID from given Tickt Id");
                        return false;
                    }
                }

                folderToReadFrom = null;
                parserObj = null;

                supDetails = initializeSupportDetails("./conf/AutoMailForward/medcs/connectionConfig.props");

                Object[] threadIdList = new Object[index];

                for (int i = 0; i < index; i++) {
                    // need to change the internal implementation with getThreadIDsFromSupportApi method itself.
                    if (mode.equals("external")) {
                        rootFolder = "./fromServer/AutoMailForward/threadIds/" + getCurrTimeInDD_MM_YY_HH_MM_SS();
                        dataFromSupport = getThreadIDsFromSupportApi(supDetails, new String[] { caseId[i], "true" },
                                rootFolder);
                    } else if (mode.equals("internal")) {
                        String testrootFolder = "./TestFiles/fromServer/AutoMailForward/threadIds/255000005096068/JSONResponse_";
                        dataFromSupport = readFromInternalAutoForward(testrootFolder);
                        loggerObj.log(Level.INFO, "running in internal mode reading from " + testrootFolder);
                    }
                    if (dataFromSupport == null) {
                        loggerObj.log(Level.SEVERE,
                                "Issue is getting ThreadIds from support for caseId" + caseId[i]);
                        return false;
                    }
                    loggerObj.log(Level.SEVERE, "Received ThreadId details from support for caseId " + caseId[i]
                            + " is " + "folderToRead " + dataFromSupport[0] + " index " + dataFromSupport[1]);
                    threadIdList[i] = dataFromSupport;
                }

                JSONObject caseIds = new JSONObject();
                for (int i = 0; i < index; i++) {
                    dataFromSupport = (String[]) threadIdList[i];

                    int threadIdIndex = Integer.parseInt(dataFromSupport[1]);
                    folderToReadFrom = dataFromSupport[0];

                    loggerObj.log(Level.INFO, "Going to read from file " + folderToReadFrom + "1 to "
                            + folderToReadFrom + threadIdIndex);
                    parserObj = new JSONOperations();
                    ArrayList<String> threadIds = new ArrayList<>();
                    for (int j = 1; j <= threadIdIndex; j++) {
                        String fileToReadFrom = folderToReadFrom + j + ".json";
                        loggerObj.log(Level.INFO, "Reading from " + fileToReadFrom);
                        JSONObject responseFromSup = (JSONObject) FileOperations.readFromJSONFile(fileToReadFrom);
                        Object threadIdsObj = parserObj.parseWithColumnHeaderCri(responseFromSup, "Thread Id",
                                "threadinfo");
                        if (threadIdsObj == null) {
                            loggerObj.log(Level.SEVERE,
                                    "Problem in retrieving Ticket ID from given Case ID" + caseId[i]);
                            return false;
                        }
                        threadIds.addAll((ArrayList<String>) threadIdsObj);
                    }
                    caseIds.put(caseId[i], threadIds);
                    loggerObj.log(Level.INFO,
                            "ThreadIds for caseId " + caseId[i] + " is " + caseIds.toJSONString());
                }

                JSONObject caseIDsToFiles = new JSONObject();
                Set<String> CaseIdSet = caseIds.keySet();

                if (mode.equals("external")) {
                    for (Iterator caseIdItr = CaseIdSet.iterator(); caseIdItr.hasNext();) {
                        String caseIdStr = (String) caseIdItr.next();
                        String folderRootForThreadContent = "./fromServer/AutoMailForward/ThreadContents/"
                                + getCurrTimeInDD_MM_YY_HH_MM_SS() + "/" + caseIdStr;
                        boolean createFolderToWriteResponse = new File(folderRootForThreadContent).mkdirs();

                        if (!createFolderToWriteResponse) {
                            loggerObj.log(Level.INFO, "Cannot create a folder" + folderRootForThreadContent
                                    + " to write threadcontent");
                            return false;
                        }
                        ArrayList<String> threadIds = (ArrayList<String>) caseIds.get(caseIdStr);

                        String[] fileNames = new String[threadIds.size()];
                        int i = 0;
                        for (Iterator threadItr = threadIds.iterator(); threadItr.hasNext();) {
                            String threadId = (String) threadItr.next();

                            String fileForThreadContent = folderRootForThreadContent + "/" + threadId + ".xml";
                            loggerObj.log(Level.INFO, "The file to write the thread content for threadId "
                                    + threadId + "is " + fileForThreadContent);
                            fileNames[i] = getThreadContentFromSupportApi(fileForThreadContent, supDetails,
                                    threadId, caseIdStr);

                            if (fileNames[i] == null) {
                                loggerObj.log(Level.SEVERE, "Problem in reading thread content for thread id "
                                        + threadId + "for case id" + caseIdStr);
                            }
                            loggerObj.log(Level.INFO, "Thread content for thread Id" + threadId
                                    + "is written to the file" + fileNames[i]);
                            i++;
                        }
                        caseIDsToFiles.put(caseIdStr, fileNames);
                        loggerObj.log(Level.INFO,
                                "CaseIds along with file names consisting their thread ID is as follows "
                                        + caseIDsToFiles.toJSONString());
                    }

                } else if (mode.equals("internal")) {
                    String rootTestFolder = "./TestFiles/fromServer/AutoMailForward/ThreadContents/27_02_16_21_03_41/255000005096068";
                    String testFile1 = rootTestFolder + "/" + "255000005078234.xml";
                    String testfile2 = rootTestFolder + "/" + "255000005096070.xml";
                    caseIDsToFiles.put("255000004261482", new String[] { testFile1, testfile2 });
                    loggerObj.log(Level.INFO,
                            "running in Test mode with reading from files" + testFile1 + testfile2);
                }
                String folderToWriteToStr = "";
                Set<String> caseIDsToFilesSet = caseIDsToFiles.keySet();
                for (Iterator fileNameItr = caseIDsToFilesSet.iterator(); fileNameItr.hasNext();) {
                    String caseIDstr = (String) fileNameItr.next();
                    loggerObj.log(Level.INFO, "case ID found is " + caseIDstr);
                    String[] fileNames = (String[]) caseIDsToFiles.get(caseIDstr);
                    if (fileNames == null) {
                        loggerObj.log(Level.INFO,
                                "Error in getting file name which contains the thread content for the caseId "
                                        + caseIDstr);
                    }

                    String[] folderToWriteTo = fileNames[0].split("/");
                    for (int i = 0; i < folderToWriteTo.length - 1; i++) {
                        folderToWriteToStr += folderToWriteTo[i] + "/";
                    }
                    folderToWriteToStr += "output.html";
                    loggerObj.log(Level.INFO, "Going to convert xml files " + getStringFromStringArray(fileNames)
                            + "html files for case Id" + caseIDstr);
                    SAXParser xmlParser = new SAXParser();
                    for (String fileToReadFrom : fileNames) {
                        xmlParser.xmlFileToHTMLConverter(fileToReadFrom, folderToWriteToStr);
                    }
                }

                loggerObj.log(Level.INFO, "Going to send auto forward mail using the file" + folderToWriteToStr);
                StringWriter writer = new StringWriter();
                try {
                    IOUtils.copy(new FileInputStream(new File(folderToWriteToStr)), writer);
                } catch (IOException ex) {
                    loggerObj.log(Level.SEVERE, "Issue in prsing the file" + folderToWriteToStr + "to send mail");
                    return false;
                }
                String[] content = new String[2];
                content[0] = writer.toString();
                content[1] = "text/html";
                MailOperations.sendMail(mailid, content, "Testing purpose");
                loggerObj.log(Level.INFO, "Successfully sent the mail using" + folderToWriteToStr);
            }
        }
        return false;
    }

    private String getThreadContentFromSupportApi(String fileToWriteResponse, JSONObject supDetails,
            String threadId, String caseId) {
        ZohoSupportAPIManager supportObj = new ZohoSupportAPIManager();

        JSONObject urlParams = (JSONObject) supDetails.get(URLPARAMS);

        boolean result = supportObj.getThreadContent(urlParams, threadId, fileToWriteResponse);

        if (!result) {
            return null;
        }

        return new String(fileToWriteResponse);
    }

    private String[] getThreadIDsFromSupportApi(JSONObject supDetails, String[] requestParams, String rootFolder) {
        ZohoSupportAPIManager supportObj = new ZohoSupportAPIManager();

        JSONObject urlParams = (JSONObject) supDetails.get(URLPARAMS);

        if (urlParams == null || requestParams == null) {
            loggerObj.log(Level.INFO, "Received details from support config file is not proper");
        }

        String folderToWriteResponse = rootFolder + "/" + requestParams[0];

        boolean createFolderToWriteResponse = new File(folderToWriteResponse).mkdirs();

        if (!createFolderToWriteResponse) {
            loggerObj.log(Level.INFO, "Cannot create a folder" + folderToWriteResponse + " to write response");
            return null;
        }

        String fileToWriteResponse = folderToWriteResponse + "/JSONResponse_";

        loggerObj.log(Level.INFO,
                "Going to contact support with details " + "urlParams: " + urlParams.toJSONString()
                        + "requestParams: " + getStringFromStringArray(requestParams) + "fileToWriteResponse "
                        + fileToWriteResponse);

        Integer result = supportObj.getCompleteThreadIds(urlParams, requestParams, fileToWriteResponse, 1);

        return new String[] { fileToWriteResponse, result.toString() };
    }

    private String[] getSupportDatausingSearchApi(JSONObject urlParams, String[] searchCriteria, String[] columnSet,
            String rootFolder) {

        ZohoSupportAPIManager supportObj = new ZohoSupportAPIManager();

        //String portal = (String)urlParams.get(PORTAL);
        String fileToWriteResponse = rootFolder + "/JSONResponse_";

        loggerObj.log(Level.INFO,
                "Going to contact support with following parmas ::::> urlParams is: " + urlParams.toJSONString()
                        + "searchCriteria is " + getStringFromStringArray(searchCriteria) + "columns: "
                        + getStringFromStringArray(columnSet) + "folderToWriteResponse" + rootFolder);

        Integer index = supportObj.getCompletesearchTicketsbyCriteria(urlParams, searchCriteria, columnSet,
                fileToWriteResponse, 1);

        if (index == null) {
            loggerObj.log(Level.SEVERE,
                    "Problem in getting deatils from zoho support using getSupportDatausingSearchApi() method");
            return null;
        }

        return new String[] { fileToWriteResponse, index.toString() };
    }

    private String getStringFromStringArray(String[] columnSet) {

        if (columnSet == null) {
            return "";
        }
        String columns = "";

        for (String i : columnSet) {
            columns += i + ",";
        }
        return columns;
    }

    private JSONObject initializeSupportDetails(String fileName) {
        loggerObj.log(Level.INFO, "Inside initializeSupportDetails method");
        loggerObj.log(Level.INFO, "Going to parse " + fileName + "to get support.zoho.com details");
        JSONObject congigParams = FileOperations.supPropsToJSONObj(fileName);
        if (congigParams == null) {
            loggerObj.log(Level.SEVERE, "Problem in parsing " + fileName + "to get support.zoho.com details");
        }
        loggerObj.log(Level.INFO,
                "Received Support details from config file " + fileName + "is: urlParams: "
                        + congigParams.get(URLPARAMS) + " searchparams: "
                        + getStringFromStringArray((String[]) congigParams.get(SEARCHPARAMS)) + " columnSet is: "
                        + getStringFromStringArray((String[]) congigParams.get(COLUMNS)));
        return congigParams;

    }

    private JSONObject initializeSupportToReportsDetails(String fileName) {
        loggerObj.log(Level.INFO, "Inside initializeSupportToReportsDetails method");
        loggerObj.log(Level.INFO,
                "Going to parse " + fileName + "to get support.zoho.com and report.zoho.com details");
        JSONObject congigParams = FileOperations.SupToReportsPropsToJSObj(fileName);
        System.out.println(congigParams.toJSONString());
        return congigParams;
    }

    private String[] getSupportDataWithConfigDetails(JSONObject supDetails, String mode,
            String folderToWriteResponse, boolean isAbsolutePath, String module) {
        loggerObj.log(Level.INFO, "Inside getSupportDataWithConfigDetails method");
        if (supDetails == null) {
            return null;
        }

        JSONObject urlParams = (JSONObject) supDetails.get(URLPARAMS);
        String[] columns = (String[]) supDetails.get(COLUMNS);
        Object searchParams = supDetails.get(SEARCHPARAMS);
        String portal = (String) (String) urlParams.get(PORTAL);
        if (portal == null) {
            return null;
        }

        portal = portal.substring(0, 5);
        if (!isAbsolutePath && mode.equals("external")) {
            folderToWriteResponse = folderToWriteResponse + "/" + portal + "/" + getCurrTimeInDD_MM_YY_HH_MM_SS();
        }
        //This line needed to creaete file folderToWriteResponse
        new File(folderToWriteResponse).mkdirs();
        if (!(new File(folderToWriteResponse).exists())) {
            loggerObj.log(Level.SEVERE, "Error: Cannot create  the file " + folderToWriteResponse);
            return null;
        }
        loggerObj.log(Level.INFO,
                "Successfully parsed support data" + "authToken is " + (String) urlParams.get(AUTHTOKEN)
                        + "portal is" + (String) urlParams.get(PORTAL) + "dept is "
                        + (String) urlParams.get(DEPARTMENT) + "folder to write to" + folderToWriteResponse);

        //System.out.println("Successfully parsed support data" + "authToken is " + authtoken + "portal is" + portal + "dept is " + dept);
        String[] responseString = null;
        if (mode.equals("external")) {
            if (searchParams == null) {
                System.out.println("Going to connect to Support using getrecords api to fetch data");
                loggerObj.log(Level.INFO, "Going to connect to  Support using getrecords api to fetch data");
                responseString = getSupportTickets(urlParams, columns, folderToWriteResponse);
            } else {
                String[] searchParamsArr = (String[]) searchParams;

                System.out.println("Going to connect to Support using searchRecords api to fetch data");
                loggerObj.log(Level.INFO, "Going to connect to  Support using searchRecords api to fetch data");
                responseString = getSupportDatausingSearchApi(urlParams, searchParamsArr, columns,
                        folderToWriteResponse);
            }

        }

        if (mode.equals("internal")) {
            System.out.println("Going to connect to Internal files to fetch data");
            loggerObj.log(Level.INFO, "Going to connect to Internal files to fetch data");
            // Need to change depending upon the module that calls it
            if (module.equals("IssueMgrReports")) {
                responseString = InternalFilesForIssMgrRprts(folderToWriteResponse);
            }
            if (module.equals("MEDCWOETickets")) {
                responseString = readFrmIntrnalFilesForMEDCSup(folderToWriteResponse);
            }
            if (module.equals("AutoMailForward_TicketIds")) {
                responseString = new String[] { folderToWriteResponse + "/JSONResponse_", "1" };
            }
            if (module.equals("AutoMailForward_CaseIds")) {

                String testRootFolder = folderToWriteResponse + "/JSONResponse_";
                responseString = readFromInternalAutoForward(testRootFolder);
            }
            loggerObj.log(Level.INFO, "Running in test mode.. reading folder " + responseString);
        }

        if (responseString == null) {
            System.out.println(
                    "The response data from support api is empty or problem is contacting the support api");
            loggerObj.log(Level.INFO,
                    "The response data from support api is empty or problem is contacting the support api");
            return new String[] { "RESPONSE ARRAY FROM SUPPORT IS NULL" };
        }

        return responseString;
    }

    private JSONObject getExtraColumnsForReports(JSONObject repDetails) {

        Object extraColumObj = repDetails.get("newColumnHeader");
        JSONObject extraColumnsJSONObj = new JSONObject();
        if (extraColumObj != null) {
            String extraColumnsStr = (String) extraColumObj;
            String[] extraColumns = extraColumnsStr.split(",");

            for (String i : extraColumns) {
                String[] HeaderToValue = i.split("=");
                extraColumnsJSONObj.put(HeaderToValue[0], HeaderToValue[1]);
            }
            loggerObj.log(Level.INFO, "Extracolumns from config file is: " + extraColumnsJSONObj.toJSONString());
            System.out.println("Extracolumns from config file is: " + extraColumnsJSONObj.toJSONString());
        } else {
            extraColumnsJSONObj = null;
            loggerObj.log(Level.INFO, "No extra columns are found in config file");
        }

        return extraColumnsJSONObj;
    }

    private JSONObject getSupToRepNameChngeCol(JSONObject repDetails) {
        Object SupToRepHdrChangeObj = repDetails.get("supTorepColumnHeader");
        JSONObject SupToRepHdrChgJSONObj = new JSONObject();
        if (SupToRepHdrChangeObj != null) {
            String SupToRepHdrChangeStr = SupToRepHdrChangeObj.toString();
            String[] supToRepHdrChangeArr = SupToRepHdrChangeStr.split(",");

            for (String i : supToRepHdrChangeArr) {
                String[] HeaderToValue = i.split("=");
                SupToRepHdrChgJSONObj.put(HeaderToValue[0], HeaderToValue[1]);
            }
            loggerObj.log(Level.INFO, "Column name that need to change and their name change is "
                    + SupToRepHdrChgJSONObj.toJSONString());
            System.out.println("Column name that need to change and their name change is "
                    + SupToRepHdrChgJSONObj.toJSONString());
        } else {
            SupToRepHdrChgJSONObj = null;
            loggerObj.log(Level.INFO, "No Column name change is found from the config file");
            System.out.println("No Column name change is found from the config file");
        }
        return SupToRepHdrChgJSONObj;
    }

    private JSONObject getFinalSupToRepColName(JSONObject SupToRepHdrChgJSONObj, JSONObject extraColumnHdr,
            JSONObject supDetails) {
        Set<String> SupHdrToChange = null;
        if (SupToRepHdrChgJSONObj != null) {
            SupHdrToChange = SupToRepHdrChgJSONObj.keySet();
        }
        String[] supHdrArr = (String[]) supDetails.get(COLUMNS);
        JSONObject SupToRepHdrObj = new JSONObject();
        for (String i : supHdrArr) {
            boolean needChange = false;
            Iterator it = null;
            if (SupHdrToChange != null) {
                it = SupHdrToChange.iterator();
            }
            for (; SupHdrToChange != null && it.hasNext();) {
                if (i.equals(it.next().toString())) {
                    needChange = true;
                    SupToRepHdrObj.put(i, SupToRepHdrChgJSONObj.get(i).toString());
                }
            }

            if (!needChange) {
                SupToRepHdrObj.put(i, i);
            }
        }
        if (extraColumnHdr != null) {
            Set<String> extraColumnHdrKeys = extraColumnHdr.keySet();
            for (Iterator it = extraColumnHdrKeys.iterator(); it.hasNext();) {
                String columnHeader = it.next().toString();
                SupToRepHdrObj.put(columnHeader, columnHeader);
            }
        }
        loggerObj.log(Level.INFO, "Final Column name in support to report column name json object is "
                + SupToRepHdrObj.toJSONString());
        System.out.println("Final Column name in support to report column name json object is "
                + SupToRepHdrObj.toJSONString());

        return SupToRepHdrObj;
    }

    private JSONArray getRepDetailsFromConfigFile(JSONObject repDetails) {
        if (repDetails == null) {
            return null;
        }
        String[] requiredURLFields = new String[] { "URLEmail", "DBName", "TableName", AUTHTOKEN };
        JSONObject urlParams = new JSONObject();
        JSONObject errorJSON = null;
        ArrayList<String> errorFields = null;

        for (int i = 0; i < requiredURLFields.length; i++) {
            String requiredField = requiredURLFields[i];
            Object obj = repDetails.get(requiredField);
            if (obj != null) {
                urlParams.put(requiredField, repDetails.get(requiredField).toString());
            } else {
                if (errorFields == null) {
                    errorFields = new ArrayList<>();
                }
                errorFields.add(requiredField);
            }
        }

        String[] requiredpostFields = new String[] { "ZOHO_IMPORT_TYPE", "ZOHO_ON_IMPORT_ERROR",
                "ZOHO_DATE_FORMAT" };
        JSONObject postParams = new JSONObject();

        postParams.put("ZOHO_IMPORT_FILETYPE", "JSON");
        postParams.put("ZOHO_AUTO_IDENTIFY", "true");
        postParams.put("ZOHO_CREATE_TABLE", "false");

        //Need to add constraint that if ZOHO_IMPORT_TYPE = "updateadd", then zoho_matching columns can never be null;
        Object ZOHO_MATCHING_COLUMNS = repDetails.get("ZOHO_MATCHING_COLUMNS");
        if (ZOHO_MATCHING_COLUMNS != null) {

            postParams.put("ZOHO_MATCHING_COLUMNS", ZOHO_MATCHING_COLUMNS.toString());
        }

        Object ZOHO_SELECTED_COLUMNS = repDetails.get("ZOHO_SELECTED_COLUMNS");
        if (ZOHO_SELECTED_COLUMNS != null) {

            postParams.put("ZOHO_SELECTED_COLUMNS", ZOHO_SELECTED_COLUMNS.toString());
        }

        for (int i = 0; i < requiredpostFields.length; i++) {
            String requiredField = requiredpostFields[i];
            Object obj = repDetails.get(requiredField);
            if (obj != null) {
                postParams.put(requiredField, repDetails.get(requiredField).toString());
            } else {
                if (errorFields == null) {
                    errorFields = new ArrayList<>();
                }
                errorFields.add(requiredField);
            }
        }

        if (errorFields == null) {
            JSONArray result = new JSONArray();
            result.add(urlParams);
            result.add(postParams);
            return result;
        } else {
            JSONArray errorArray = new JSONArray();
            errorJSON = new JSONObject();
            errorJSON.put("nullFields", errorFields);
            errorArray.add(errorJSON);
            return errorArray;
        }

    }

    private String[] getSupportTickets(JSONObject connectionParams, String[] columns, String folderTowrite) {
        ZohoSupportAPIManager supportapi = new ZohoSupportAPIManager();

        String[] responseString = supportapi.getCompleteSupportRecordsApi(connectionParams, columns, folderTowrite,
                0);
        return responseString;
    }

    // Wont work as response type is changed to string array rather than jsonarray//
    // need to change line 523 inorder the entire logic to work. //
    private void IssueMgrStatusSummGen(String mode, String mailId) {

        loggerObj.log(Level.INFO, "inside MDMIMR_stat_module_Own_SummGen");

        String MEMDMconfigFile = "./conf/IssueManagerReports/connectionConfig.props";
        JSONObject MEMDMsupDetails = initializeSupportDetails(MEMDMconfigFile);

        if (MEMDMsupDetails == null) {
            loggerObj.log(Level.SEVERE,
                    "Problem in parsing " + MEMDMconfigFile + "to get support.zoho.com details");
            return;
        }

        String[] responseString = null;
        String folderwriteResponse = null;
        if (mode.equals("external")) {
            folderwriteResponse = "./fromServer/IssueManagerReports";
        }
        if (mode.equals("internal")) {
            folderwriteResponse = "./TestFiles/fromServer/IssueManagerReports/memdm/test_input_1";
        }
        responseString = getSupportDataWithConfigDetails(MEMDMsupDetails, mode, folderwriteResponse, false,
                "IssueMgrReports");
        deferenceObjects(new Object[] { MEMDMconfigFile, MEMDMsupDetails });

        if (responseString == null) {
            loggerObj.log(Level.SEVERE,
                    "Response data from MEMDM support.zoho.com while retrieving ticket id is empty/null");
            return;
        }

        String folderToReadFrom = responseString[0];
        Integer index = Integer.parseInt(responseString[1]);

        loggerObj.log(Level.INFO,
                "The details obtained from support is: index: " + index + " folderToreadFrom: " + folderToReadFrom);

        String fileToWriteParsedResponse = "./parsed_output/IssueManagerReports/jsonContent/"
                + getCurrTimeInDD_MM_YY_HH_MM_SS() + ".json";
        String[] statusString = { "Open", "Closed" };
        JSONOperations parserObj = new JSONOperations();

        String currentFileToreadResponse = null;
        boolean isProperResponse = true;
        JSONObject statusModuleSummary = null;

        for (int i = 1; i <= index; i++) {
            System.out.println("index: " + i);
            currentFileToreadResponse = folderToReadFrom + i + ".json";
            loggerObj.log(Level.INFO, "Going to read from the file " + currentFileToreadResponse);
            Object ResponseObjectFromFile = FileOperations.readFromJSONFile(currentFileToreadResponse);

            if (ResponseObjectFromFile instanceof JSONObject) {
                statusModuleSummary = parserObj.ModuleVsStatusSummaryGenerator((JSONObject) ResponseObjectFromFile,
                        statusString, "row", statusModuleSummary);
                loggerObj.log(Level.INFO, "Module summary" + statusModuleSummary.toJSONString());
                System.out.println(statusModuleSummary.toJSONString());
            } else {
                isProperResponse = false;
                break;
            }
        }

        if (!isProperResponse) {
            System.out.println("Error is parsing JSONResponse file from MEDC support");
            loggerObj.log(Level.INFO, "Error is parsing the file " + currentFileToreadResponse);
            return;
        }

        if (statusModuleSummary == null) {
            System.out.println(
                    "Error in converting JSON files in the folder" + folderToReadFrom + " to parsed response");
            loggerObj.log(Level.INFO,
                    "Error in converting JSON files in the folder" + folderToReadFrom + " to parsed response");
        }

        loggerObj.log(Level.INFO,
                "JSON after processed by ModuleVsOpensummaryGenerator is " + statusModuleSummary.toJSONString());

        FileOperations.writeObjectToFile(statusModuleSummary, fileToWriteParsedResponse);
        loggerObj.log(Level.INFO,
                "Module vs status summary generated JSON is stored in the file" + fileToWriteParsedResponse);

        //To get the appropriate owners for the module:
        String ModuleVsOwnersCSVFile = "./conf/IssueManagerReports/ModuleToOwners.csv";
        JSONObject ModuleVsOwners = FileOperations.CSVToJSONObject(ModuleVsOwnersCSVFile);
        loggerObj.log(Level.INFO,
                "The owner to module mapping stored in file " + ModuleVsOwnersCSVFile + " is converted into JSON");
        loggerObj.log(Level.INFO, "The owner mapping JSON is: " + ModuleVsOwners.toJSONString());

        Set<String> statusKeys = statusModuleSummary.keySet();

        for (Iterator statusIterator = statusKeys.iterator(); statusIterator.hasNext();) {
            String status = (String) statusIterator.next();
            parserObj.appendTwoJSONObjectsWithSameKeys((JSONObject) statusModuleSummary.get(status),
                    ModuleVsOwners);

        }

        //System.out.println("moduleSummary: " + ModuleVsStatusVsOwnerSummary.toJSONString());
        //System.out.println(ModVsCountVsOwner.toJSONString());
        String currTime = getCurrTimeInDD_MM_YY_HH_MM_SS();
        String FileWithOwners = "./parsed_output/IssueManagerReports/jsonContent/withowners_" + currTime + ".json";
        FileOperations.writeObjectToFile(statusModuleSummary, FileWithOwners);
        String[] msgMultiPartContent = createMsgContentForMod_Count_Owner(statusModuleSummary);

        String htmlContent = msgMultiPartContent[0];
        String fileWithHTMLContent = "./parsed_output/IssueManagerReports/htmlContent/" + currTime + ".html";
        FileOperations.writeObjectToFile(htmlContent, fileWithHTMLContent);

        String subject = "MDM Issue Manager Reports";
        System.out.println("Tickets processed..Going to send mail. This might take around 2 to 3 mins");

        String mailsettingsConf = "./conf/IssueManagerReports/mailsettings.conf";
        JSONObject mailSettings = FileOperations.mailSettingsToJO(mailsettingsConf);
        loggerObj.log(Level.INFO, "The mailsettings conf received from the file " + mailsettingsConf + " is "
                + mailSettings.toJSONString());

        mailId = (String) mailSettings.get("Senderemailaddress");
        if (mailId == null) {
            loggerObj.log(Level.SEVERE, "The mailId obtained from the conf file " + mailsettingsConf + " empty");
            return;
        }
        String isMailSentProperly = MailOperations.sendMail(mailId, msgMultiPartContent, subject);
        if (isMailSentProperly != null) {
            System.out.println(isMailSentProperly);
            if (isMailSentProperly.contains("Could not connect to SMTP host")
                    || isMailSentProperly.contains("Unknown SMTP host")) {
                System.out.println("Mail server not reachable");
            }
        }
        System.out.println("***********************************************************");
    }

    private void MEDCSup_WOE_SummGen(String mode, String mailId) {
        loggerObj.log(Level.INFO, "Inside MEDCSup_WOE_SummGen method");

        String departmentConfigFile = "./conf/MEDC_WOESummGen/departmentDetails.conf";

        JSONObject deptConfFileDetails = FileOperations.MEDC_WOE_DeptDetails(departmentConfigFile);
        System.out.println(deptConfFileDetails.toJSONString());
        Set<String> deptKeys = deptConfFileDetails.keySet();
        //String departmentName = null;
        for (Iterator deptItr = deptKeys.iterator(); deptItr.hasNext();) {
            String deptName = (String) deptItr.next();
            String confFileName = (String) deptConfFileDetails.get(deptName);
            confFileName = confFileName.replaceAll("\\\\", "");
            System.out.println(deptName + " : " + confFileName);
            loggerObj.log(Level.INFO, "Department: " + deptName + "conffileName: " + confFileName);

            JSONObject supDetails = initializeSupportDetails(confFileName);
            if (supDetails == null) {
                loggerObj.log(Level.SEVERE,
                        "Problem in parsing " + confFileName + "to get support.zoho.com details");
                return;
            }

            String[] responseString = null;

            String folderwriteResponse = null;
            if (mode.equals("external")) {
                folderwriteResponse = "./fromServer/MEDC_WOESummGen";
            }
            if (mode.equals("internal")) {
                folderwriteResponse = "./TestFiles/fromServer/MEDC_WOESummGen/DesktopCentral/test_input_1";
            }
            responseString = getSupportDataWithConfigDetails(supDetails, mode, folderwriteResponse, false,
                    "MEDCWOETickets");

            deferenceObjects(new Object[] { departmentConfigFile, supDetails });

            if (responseString == null) {
                loggerObj.log(Level.SEVERE,
                        "Response data from MEMDM support.zoho.com while retrieving ticket id is empty/null");
                return;
            }

            String folderToReadFrom = responseString[0];
            Integer index = Integer.parseInt(responseString[1]);

            loggerObj.log(Level.INFO, "The details obtained from support is: index: " + index
                    + " folderToreadFrom: " + folderToReadFrom);

            String fileToWriteParsedResponse = "./parsed_output/MEDC_WOESummGen/" + deptName.substring(0, 4) + "_"
                    + getCurrTimeInDD_MM_YY_HH_MM_SS() + ".json";

            JSONOperations parserObj = new JSONOperations();

            String currentFileToreadResponse = null;
            boolean isProperResponse = true;
            JSONArray WOESummary = null;

            for (int i = 1; i <= index; i++) {
                System.out.println("index: " + i);
                currentFileToreadResponse = folderToReadFrom + i + ".json";
                loggerObj.log(Level.INFO, "Goid to read from the file " + currentFileToreadResponse);
                Object ResponseObjectFromFile = FileOperations.readFromJSONFile(currentFileToreadResponse);
                if (ResponseObjectFromFile instanceof JSONObject) {
                    WOESummary = parserObj.WOESummGenForResponseJSONObject((JSONObject) ResponseObjectFromFile,
                            deptName, WOESummary, "row");
                    System.out.println(WOESummary.toJSONString());
                } else {
                    isProperResponse = false;
                    break;
                }
            }

            if (!isProperResponse) {
                System.out.println("Error is parsing JSONResponse file from MEDC support");
                loggerObj.log(Level.INFO, "Error is parsing the file " + currentFileToreadResponse);
                return;
            }

            //JSONArray WOESummary = parserObj.WOESummGenForResponseArray(ResponseJSONArray, departmentName);
            if (WOESummary == null) {
                System.out.println(
                        "Error in converting JSON files in the folder" + folderToReadFrom + " to parsed response");
                loggerObj.log(Level.INFO,
                        "Error in converting JSON files in the folder" + folderToReadFrom + " to parsed response");
            }
            //System.out.println(WOESummary.toJSONString());
            boolean isFileWriteSucess = FileOperations.writeObjectToFile(WOESummary, fileToWriteParsedResponse);
            if (!isFileWriteSucess) {
                loggerObj.log(Level.INFO,
                        "Error in writting the responseJSONArray to the file " + fileToWriteParsedResponse);
            }
            loggerObj.log(Level.INFO, "Parsed response is written to" + fileToWriteParsedResponse);
            String[] status = { "Need to Analyze", "Needs to Call", "Waiting on Engineering" };
            String[] MsgMultiPartContent = createMsgContentForWOE_Tickets(WOESummary, status);
            loggerObj.log(Level.INFO, "Mail content is created for parsed response");
            String subject = deptName + " tickets for developers";
            System.out.println("Tickets processed..Going to send mail. This might take around 2 to 3 mins");

            int indexOFLastSlash = confFileName.lastIndexOf("/");
            String mailsettingsConf = confFileName.substring(0, indexOFLastSlash) + "/mailsettings.conf";
            JSONObject mailSettings = FileOperations.mailSettingsToJO(mailsettingsConf);
            loggerObj.log(Level.INFO, "The mailsettings conf received from the file " + mailsettingsConf + " is "
                    + mailSettings.toJSONString());

            mailId = (String) mailSettings.get("Senderemailaddress");
            if (mailId == null) {
                loggerObj.log(Level.SEVERE,
                        "The mailId obtained from the conf file " + mailsettingsConf + " empty");
                return;
            }

            String isMailSentProperly = MailOperations.sendMail(mailId, MsgMultiPartContent, subject);
            if (isMailSentProperly != null) {
                System.out.println(isMailSentProperly);
                if (isMailSentProperly.contains("Could not connect to SMTP host")
                        || isMailSentProperly.contains("Unknown SMTP host")) {
                    System.out.println("Mail server not reachable");
                    loggerObj.log(Level.INFO, "Mail server not reachable");
                }
                if (isMailSentProperly.equals("Content is null")) {
                    loggerObj.log(Level.INFO,
                            "MsgMultiPartContent generated to give to mail api is empty or not proper");
                }

            }
            System.out.println("***********************************************************");

        }
    }

    private String getCurrTimeInDD_MM_YY_HH_MM_SS() {
        DateFormat dateFormat = new SimpleDateFormat("dd_MM_yy_HH_mm_ss");
        Date date = new Date();
        String currTime = dateFormat.format(date);
        return currTime;
    }

    private static String[] readFrmIntrnalFilesForMEDCSup(String folderName) {
        loggerObj.log(Level.INFO, "Inside InternalFilesForIssMgrRprts method");
        try {

            String fileToParse = folderName + "/JSONResponse_";
            String fileToParseNext = null;
            BufferedReader fileReader = null;

            String line = "";

            //Read the file line by line
            int i = 1;
            Integer index = 134;
            loggerObj.log(Level.INFO, "Going to read internally files(" + fileToParse + 1 + ".json to "
                    + fileToParse + index + ".json" + ") from folder " + folderName + "");
            while (i <= index) {
                String output = "";
                try {
                    fileToParseNext = fileToParse + i + ".json";
                    loggerObj.log(Level.INFO, "Going to read the internal file" + fileToParseNext);
                    fileReader = new BufferedReader(new FileReader(fileToParseNext));
                    while ((line = fileReader.readLine()) != null) {
                        //Get all tokens available in line
                        output += line;
                        // System.out.print(line);
                    }
                    JSONParser parser = new JSONParser();
                    JSONObject json = (JSONObject) parser.parse(output);
                    fileReader.close();

                } catch (Exception ex) {
                    try {
                        loggerObj.log(Level.INFO, "Problem in reading the internal files for MEDCServer from"
                                + fileToParseNext + ex.toString());
                        fileReader.close();
                        return null;
                    } catch (IOException ex1) {
                        loggerObj.log(Level.INFO,
                                "Problem in closing the internal files for MEDCServer after reading "
                                        + fileToParseNext + ex.toString());
                    }

                }
                i++;
            }

            fileReader.close();
            loggerObj.log(Level.INFO, "successfully read the internal files for MEDCServer after reading");
            return new String[] { fileToParse, index.toString() };

        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "Problem in reading the internal files for MEDCServer " + ex.toString());
            return null;
        }
    }

    private static JSONArray readFromInternalFilesForMEMDM() {
        try {
            String fileToParse = "E://Weekly Issue Manager Reports/ResponseText/ResponseFromServer";
            BufferedReader fileReader = null;

            String line = "";

            //Read the file line by line
            int i = 1;
            JSONArray test = new JSONArray();
            while (i <= 1) {
                String output = "";
                try {
                    String fileToParseNew = fileToParse + i + ".txt";
                    fileReader = new BufferedReader(new FileReader(fileToParseNew));
                    while ((line = fileReader.readLine()) != null) {
                        //Get all tokens available in line
                        output += line;
                        //System.out.print(line);
                    }
                    JSONParser parser = new JSONParser();
                    JSONObject json = (JSONObject) parser.parse(output);
                    test.add(json);
                    fileReader.close();

                } catch (Exception ex) {
                    try {
                        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
                        fileReader.close();
                        return null;
                    } catch (IOException ex1) {
                        Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex1);
                    }

                }
                i++;
            }
            fileReader.close();
            return test;
            // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (IOException ex) {
            Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    private static String[] InternalFilesForSupToRepSync() {
        Integer index = 104;
        BufferedReader fileReader = null;
        String fileToParse = "./Files/TestFiles/SupToRepSync/MEDCServer/DC/JSONResponse_";
        String fileToParseNew = fileToParse + 1 + ".json";
        try {

            String line = "";

            //Read the file line by line
            int i = 1;
            JSONArray test = new JSONArray();
            while (i <= index) {
                String output = "";

                fileToParseNew = fileToParse + i + ".json";
                try {
                    fileReader = new BufferedReader(new FileReader(fileToParseNew));
                } catch (FileNotFoundException ex) {
                    loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal file"
                            + fileToParseNew + "Exception is: " + ex.toString());
                }
                while ((line = fileReader.readLine()) != null) {
                    //Get all tokens available in line
                    output += line;
                    //System.out.print(line);
                }
                JSONParser parser = new JSONParser();
                try {
                    JSONObject json = (JSONObject) parser.parse(output);
                    test.add(json);
                } catch (ParseException ex) {
                    loggerObj.log(Level.INFO,
                            "Error in parsing MEMDM server files from internal file" + fileToParseNew);
                }
                i++;
            }

        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal files" + fileToParseNew);
            return null;
        } finally {
            try {
                fileReader.close();
            } catch (IOException ex) {
                loggerObj.log(Level.INFO,
                        "Error in closing the fileReader while closing the file" + fileToParseNew);
            }
        }
        return new String[] { fileToParse, index.toString() };
    }

    private String[] readFromInternalAutoForward(String rootFolder) {
        Integer index = 1;
        BufferedReader fileReader = null;
        String fileToParseNew = rootFolder + 1 + ".json";
        try {

            String line = "";

            //Read the file line by line
            int i = 1;

            while (i <= index) {
                String output = "";

                fileToParseNew = rootFolder + i + ".json";
                try {
                    fileReader = new BufferedReader(new FileReader(fileToParseNew));
                } catch (FileNotFoundException ex) {
                    loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal file"
                            + fileToParseNew + "Exception is: " + ex.toString());
                }
                while ((line = fileReader.readLine()) != null) {
                    //Get all tokens available in line
                    output += line;
                    //System.out.print(line);
                }
                JSONParser parser = new JSONParser();
                try {
                    JSONObject json = (JSONObject) parser.parse(output);

                } catch (ParseException ex) {
                    loggerObj.log(Level.INFO,
                            "Error in parsing MEMDM server files from internal file" + fileToParseNew);
                }
                i++;
            }

        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal files" + fileToParseNew);
            return null;
        } finally {
            try {
                fileReader.close();
            } catch (IOException ex) {
                loggerObj.log(Level.INFO,
                        "Error in closing the fileReader while closing the file" + fileToParseNew);
            }
        }
        return new String[] { rootFolder, index.toString() };
    }

    private static String[] InternalFilesForIssMgrRprts(String folderToReadResponse) {
        loggerObj.log(Level.INFO, "Inside InternalFilesForIssMgrRprts method");

        Integer index = 48;
        BufferedReader fileReader = null;
        String fileToParse = folderToReadResponse + "/JSONResponse_";
        loggerObj.log(Level.INFO, "Going to read internally files(" + fileToParse + 1 + ".json to " + fileToParse
                + index + ".json" + ") from folder " + folderToReadResponse + "");

        String fileToParseNew = fileToParse + 1 + ".json";

        try {

            String line = "";

            //Read the file line by line
            int i = 1;

            while (i <= index) {
                String output = "";

                fileToParseNew = fileToParse + i + ".json";
                try {
                    fileReader = new BufferedReader(new FileReader(fileToParseNew));
                } catch (FileNotFoundException ex) {
                    loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal file"
                            + fileToParseNew + "Exception is: " + ex.toString());
                }
                while ((line = fileReader.readLine()) != null) {
                    //Get all tokens available in line
                    output += line;
                    //System.out.print(line);
                }
                JSONParser parser = new JSONParser();
                try {
                    parser.parse(output);
                } catch (ParseException ex) {
                    loggerObj.log(Level.INFO,
                            "Error in parsing MEMDM server files from internal file" + fileToParseNew);
                }
                i++;
            }

        } catch (IOException ex) {
            loggerObj.log(Level.INFO, "Error in reading MEMDM server files from internal files" + fileToParseNew);
            return null;
        } finally {
            try {
                fileReader.close();
            } catch (IOException ex) {
                loggerObj.log(Level.INFO,
                        "Error in closing the fileReader while closing the file" + fileToParseNew);
            }
        }
        return new String[] { fileToParse, index.toString() };
    }

    private String[] createMsgContentForMod_Count_Owner(JSONObject statusModuleSumm) {
        String[] result = new String[2];
        String content = "<HTML><BODY>";

        Set<String> statusKeys = statusModuleSumm.keySet();

        for (Iterator statusItr = statusKeys.iterator(); statusItr.hasNext();) {
            String status = (String) statusItr.next();
            content += "<h2>" + status + "</h2>";
            JSONObject moduleSummary = (JSONObject) statusModuleSumm.get(status);
            String moduleCountOwners = MEMDM_Mod_Count_OwnerJSONToHTML(moduleSummary);
            if (moduleCountOwners == null || moduleCountOwners.equals("")) {
                moduleCountOwners = "No data available";
            }

            content += "<table border=\"1\" cellpadding=\"7\" rules=\"all\" frame=\"box\" style=\"width: 100%;\">\n"
                    + "   <tbody>\n" + "      <tr>\n"
                    + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(102, 255, 0);\"><b>Module</b></td>\n"
                    + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(102, 255, 0);\"><b>Open Count</b></td>\n"
                    + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(102, 255, 0);\"><b>Owner</b></td>\n"
                    + "      </tr>\n" + moduleCountOwners + "   </tbody>\n" + "</table>\n";
        }

        /*content += "<htmml><body><table border=\"1\" cellpadding=\"7\" rules=\"all\" frame=\"box\" style=\"width: 100%;\">\n"
         + "   <tbody>\n"
         + "      <tr>\n"
         + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(102, 255, 0);\"><b>Module</b></td>\n"
         + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(102, 255, 0);\"><b>Open Count</b></td>\n"
         + "         <td valign=\"top\" style=\"width: 33%; text-align: left; vertical-align: top; background-color: rgb(102, 255, 0);\"><b>Owner</b></td>\n"
         + "      </tr>\n"
         + Module_Count_Owners
         + "   </tbody>\n"
         + "</table>\n"
         + "<br></body></html>";*/
        content += "</BODY></HTML>";
        String type = "text/html";
        //String writeResponseAsHTML = "./Files/MEMDMFiles/email_content" + getCurrTimeInDD_MM_YY_HH_MM_SS() + ".html";
        //FileOperations.writeObjectToFile(content, writeResponseAsHTML);
        result[0] = content;
        result[1] = type;
        return result;
    }

    private String[] createMsgContentForWOE_Tickets(JSONArray WOESummary, String[] status) {
        if (WOESummary == null) {
            return null;
        }

        String[] result = new String[3];
        String count = "0";
        String content = "";
        String[] WOETickets = new String[status.length];
        for (int i = 0; i < WOETickets.length; i++) {
            String[] htmlContent = WOETicketsJSONArrToHTML(WOESummary, status[i]);
            count = htmlContent[1];

            content += "<h2><u>" + status[i]
                    + " Tickets</u><span style=\"color: rgb(255, 0, 0);\" \"font-weight:normal\"> (" + count
                    + ")</span></h2>";

            WOETickets[i] = htmlContent[0];

            if (WOETickets[i].equals("") || WOETickets[i] == null) {

                WOETickets[i] = "<tr >\n" + "<td colspan=\"9\"><center style=\"color: rgb(255, 0, 0);\">"
                        + "No pending tickets available" + "</center></td></tr> \n";
            }
            /*content += "<table border=\"0px\" cellpadding=\"7px\" style=\"width:100%;\" cellspacing=\"0px\">\n"
             + "<tbody>\n"
             + "         <tr style=\"text-align: left; vertical-align: top; background-color: rgb(160, 238, 151);\">\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Ticket Created Time</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Ticket ID</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Email</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Subject</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Developers</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Ticket Owner</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Module</b></td>\n"
             + "            <td valign=\"top\" style=\"width: 11.111%;\"><b>Due Date</b></td>\n"
             + "                          <td valign=\"top\" style=\"width: 11.111%;\"><b>Problem Description</b></td>\n"
             + "         </tr>\n"
             + WOETickets[i]
             + "   </tbody>\n"
             + "</table><hr>\n";*/

            content += "<table border=\"0px\" cellpadding=\"7px\" style=\"width:100%;\" cellspacing=\"0px\">\n"
                    + "<tbody>\n"
                    + "         <tr style=\"text-align: left; vertical-align: top; background-color: rgb(160, 238, 151);\">\n"
                    + "            <td valign=\"top\" ><b>Ticket Created Time</b></td>\n"
                    + "            <td valign=\"top\" ><b>Ticket ID</b></td>\n"
                    + "            <td valign=\"top\" ><b>Email</b></td>\n"
                    + "            <td valign=\"top\" ><b>Issue Description</b></td>\n"
                    + "            <td valign=\"top\" ><b>Issue Type</b></td>\n"
                    + "            <td valign=\"top\" ><b>Module</b></td>\n"
                    + "            <td valign=\"top\" ><b>Developer</b></td>\n"
                    + "            <td valign=\"top\" ><b>Ticket Owner</b></td>\n"
                    + "                         <td valign=\"top\" ><b>Due Date</b></td>\n"
                    + "                         <td valign=\"top\" ><b>Last Updated At</b></td>\n"
                    + "         </tr>\n" + WOETickets[i] + "   </tbody>\n" + "</table><hr>\n";

        }
        String writeResponseAsHTML = "./Files/MEDCFiles/email_gen_" + getCurrTimeInDD_MM_YY_HH_MM_SS() + ".html";
        FileOperations.writeObjectToFile(content, writeResponseAsHTML);
        String type = "text/html";

        result[0] = content;
        result[1] = type;
        result[2] = count;
        return result;
    }

}