JSONParser.JSONOperations.java Source code

Java tutorial

Introduction

Here is the source code for JSONParser.JSONOperations.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 JSONParser;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.FetchProfile;
import loggerapi.CustomLogger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

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

    private static final CustomLogger loggerProperties = new CustomLogger();
    private static Logger loggerObj;

    static {
        initializeLoggerParams();
    }

    private static void initializeLoggerParams() {

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

    }

    public JSONArray getRowsFromSupportapiJSON(JSONObject responseObject, String rowName) {
        loggerObj.log(Level.INFO, "Inside getRowsFromSupportapiJSON method");
        JSONObject response = (JSONObject) responseObject.get("response");
        JSONObject result = (JSONObject) response.get("result");
        JSONObject cases = (JSONObject) result.get("Cases");
        JSONArray row = new JSONArray();

        Object rowObj = cases.get(rowName);

        if (rowObj instanceof JSONObject) {
            loggerObj.log(Level.INFO, "JSONResponse is JSONObject");
            row.add(rowObj);
        } else if (rowObj instanceof JSONArray) {
            loggerObj.log(Level.INFO, "JSONResponse is JSONArray");
            row = (JSONArray) rowObj;
        }

        loggerObj.log(Level.INFO, "successfully returning row from getRowsFromSupportapiJSON method");
        return row;
    }

    public ArrayList<String> parseWithColumnHeaderCri(JSONObject JSONObjectToParse, String columnHeaderCriteria,
            String rowName) {
        loggerObj.log(Level.INFO, "Inside parseWithColumnHeaderCri method");
        ArrayList<String> caseID = null;
        try {
            JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName);

            Iterator<JSONObject> iterator = row.iterator();
            while (iterator.hasNext()) {

                JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
                Iterator<JSONObject> innerIterator = rowIndex.iterator();
                while (innerIterator.hasNext()) {

                    JSONObject field = innerIterator.next();
                    String columnHeader = (String) field.get("val");

                    if (columnHeader.equals(columnHeaderCriteria)) {
                        if (caseID == null) {
                            caseID = new ArrayList<String>();
                        }
                        caseID.add((String) field.get("content"));
                    }
                }
            }

        } catch (Exception ex) {
            loggerObj.log(Level.SEVERE, "Issue in parsing the support api data to reports api format", ex);
            System.out.println("Issue in parsing the support api data to reports api format" + ex.toString());

        }
        return caseID;
    }

    public static boolean isNumeric(String str) {
        return str.matches("-?\\d+(\\.\\d+)?"); //match a number with optional '-' and decimal.
    }

    public ArrayList<String> parseTicketIdFromSub(JSONObject JSONObjectToParse, String rowName) {
        ArrayList<String> ticketIds = null;

        try {
            JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName);

            Iterator<JSONObject> iterator = row.iterator();
            while (iterator.hasNext()) {

                JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
                Iterator<JSONObject> innerIterator = rowIndex.iterator();
                while (innerIterator.hasNext()) {
                    JSONObject field = innerIterator.next();
                    String columnHeader = (String) field.get("val");

                    if (columnHeader != null && columnHeader.equals("Subject")) {
                        String columnValue = (String) field.get("content");
                        System.out.println("Column header:" + columnHeader + " column value" + columnValue);
                        if (columnValue != null) {
                            String[] splitString = columnValue.split("-");
                            if (splitString.length > 1) {

                                if (ticketIds == null) {
                                    ticketIds = new ArrayList<>();
                                }

                                String ticketId = splitString[0].trim();
                                boolean isNumber = isNumeric(ticketId);
                                if (isNumber) {
                                    ticketIds.add(splitString[0].trim());
                                }
                            }
                        }
                    }
                }
            }

        } catch (Exception ex) {
            loggerObj.log(Level.SEVERE, "Issue in parsing the support api data to reports api format", ex);
            System.out.println("Issue in parsing the support api data to reports api format" + ex.toString());

        }

        return ticketIds;
    }

    public JSONArray SupJOToReportsJA(JSONObject JSONObjectToParse, JSONObject extraColumns,
            JSONObject SupTorepColumnChngHeader, String rowName) {
        try {
            JSONArray issueMgrArray = new JSONArray();

            JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName);

            Iterator<JSONObject> iterator = row.iterator();
            while (iterator.hasNext()) {
                JSONObject issueMgrObj = new JSONObject();
                JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
                Iterator<JSONObject> innerIterator = rowIndex.iterator();

                if (extraColumns != null) {

                    Set<String> extraColumnKeys = extraColumns.keySet();

                    for (Iterator it = extraColumnKeys.iterator(); it.hasNext();) {
                        String key = it.next().toString();
                        issueMgrObj.put(key, extraColumns.get(key));
                    }
                }

                //issueMgrObj.put("Products", "Mobile Device Management (MDM)");
                while (innerIterator.hasNext()) {

                    JSONObject field = innerIterator.next();
                    Object columnHeader = field.get("val");
                    Object columnValue = field.get("content");
                    String setEmptyContent = "Not assigned";
                    if (SupTorepColumnChngHeader != null) {
                        Set<String> suppHeaderChngKeySet = SupTorepColumnChngHeader.keySet();

                        for (Iterator itChange = suppHeaderChngKeySet.iterator(); itChange.hasNext();) {
                            String suppHeaderChngKeys = itChange.next().toString();

                            if (columnHeader.toString().equals(suppHeaderChngKeys)) {
                                if (columnValue != null) {
                                    if (columnValue.equals("null")) {
                                        issueMgrObj.put(SupTorepColumnChngHeader.get(suppHeaderChngKeys),
                                                setEmptyContent);
                                    } else {
                                        issueMgrObj.put(SupTorepColumnChngHeader.get(suppHeaderChngKeys),
                                                columnValue);
                                    }
                                } else {
                                    issueMgrObj.put(SupTorepColumnChngHeader.get(suppHeaderChngKeys),
                                            setEmptyContent);
                                    loggerObj.log(Level.INFO,
                                            "Column value is null for the column header: " + columnHeader);
                                }
                            } else {
                                if (columnValue != null) {
                                    if (columnValue.equals("null")) {
                                        issueMgrObj.put(columnHeader, setEmptyContent);
                                    } else {
                                        issueMgrObj.put(columnHeader, columnValue);
                                    }
                                } else {
                                    issueMgrObj.put(columnHeader, setEmptyContent);
                                }
                            }
                        }
                    } else {
                        if (columnValue != null) {
                            issueMgrObj.put(columnHeader, columnValue);
                        } else {
                            issueMgrObj.put(columnHeader, setEmptyContent);
                        }
                    }

                }
                issueMgrArray.add(issueMgrObj);
            }

            loggerObj.log(Level.INFO, "Successfully parsed the support api data to reports api format");
            //JSONObject result = new JSONObject();
            //result.put("result", issueMgrArray);
            return issueMgrArray;

        } catch (Exception e) {
            loggerObj.log(Level.SEVERE, "Issue in parsing the support api data to reports api format", e);
            System.out.println("Issue in parsing the support api data to reports api format" + e.toString());
            return null;
        }
    }

    //JSONFormat returned by this object is:
    /* {<statusname(String)>:{<moduleName(String)>:{"Count":<modulecount(Integer)>},{<moduleName(String)>:{"Count":<modulecount(Integer)>}},
     <statusname(String)>:{<moduleName(String)>:{"Count":<modulecount(Integer)>},{<moduleName(String)>:{"Count":<modulecount(Integer)>}}
     example:
     {Open:{
     Enrollment:1,
     Profile:2,
     Inventory:3
     },
     Closed:{
     Enrollment:4,
     Inventory:5,
     profile:2
     }
     }
     */
    public JSONObject ModuleVsStatusSummaryGenerator(JSONObject JOToParse, String[] statusString, String rowName,
            JSONObject parsedJO) {

        //JSONObject moduleCount = new JSONObject();
        //JSONArray statusModuleCountArray = new JSONArray();
        JSONArray row = getRowsFromSupportapiJSON(JOToParse, rowName);

        Iterator<JSONObject> rowIterator = row.iterator();
        while (rowIterator.hasNext()) {
            JSONArray rowIndex = (JSONArray) rowIterator.next().get("fl");
            Iterator<JSONObject> fieldIterator = rowIndex.iterator();
            // int count = 0;
            String status = null;
            String moduleName = null;
            while (fieldIterator.hasNext()) {
                JSONObject field = fieldIterator.next();
                String fieldVal = (String) field.get("val");
                String fieldContent = (String) field.get("content");

                if (fieldVal != null && fieldVal.equals("Status")) {
                    for (String indiStringStatus : statusString) {
                        if (fieldContent.equals(indiStringStatus) || fieldContent.equals("null")) {
                            status = fieldContent;
                        }
                    }
                }

                if (fieldVal != null && fieldVal.equals("Module")) {
                    if (fieldContent == null || fieldContent.equals("null")) {
                        fieldContent = "Not Assigned";
                    }
                    moduleName = fieldContent;
                }

            }
            if (status != null) {
                if (parsedJO == null) {
                    parsedJO = new JSONObject();
                }

                JSONObject moduleSummaryJO = (JSONObject) parsedJO.get(status);
                if (moduleSummaryJO == null) {
                    moduleSummaryJO = new JSONObject();

                    JSONObject indiModuleJO = new JSONObject();
                    indiModuleJO.put("Count", 1);
                    moduleSummaryJO.put(moduleName, indiModuleJO);
                    parsedJO.put(status, moduleSummaryJO);
                } else {
                    JSONObject indiModuleJO = (JSONObject) moduleSummaryJO.get(moduleName);
                    if (indiModuleJO != null) {
                        Integer moduleCount = (Integer) indiModuleJO.get("Count");
                        indiModuleJO.put("Count", moduleCount + 1);
                    } else {
                        indiModuleJO = new JSONObject();
                        indiModuleJO.put("Count", 1);
                    }

                    moduleSummaryJO.put(moduleName, indiModuleJO);
                    parsedJO.put(status, moduleSummaryJO);
                }
            }
        }

        //System.out.println(statusModuleCountArray.toJSONString());
        return parsedJO;
    }

    public JSONObject MEMDMStatusWiseTicketGen(JSONArray ResponseFromServer, String rowName) {
        JSONObject statusJson = new JSONObject();
        Iterator<JSONObject> jsonObjectItr = ResponseFromServer.iterator();
        while (jsonObjectItr.hasNext()) {

            JSONArray row = getRowsFromSupportapiJSON((JSONObject) jsonObjectItr.next(), rowName);

            Iterator<JSONObject> iterator = row.iterator();
            while (iterator.hasNext()) {

                JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
                Iterator<JSONObject> innerIterator = rowIndex.iterator();

                JSONObject statusVal = new JSONObject();
                String statusName = null;

                while (innerIterator.hasNext()) {
                    JSONObject field = innerIterator.next();
                    if (field.get("val").toString().equals("Status")) {
                        statusName = field.get("content").toString();

                        //To get all the status data;
                        if (statusJson.get(statusName) == null) {
                            statusJson.put(statusName, null);
                        }

                    }

                    if (field.get("val").toString().equals("Module")) {
                        statusVal.put("moduleName", field.get("content").toString());
                    }

                    if (field.get("val").toString().equals("Functionality")) {
                        statusVal.put("functionalityName", field.get("content").toString());
                    }

                    if (field.get("val").toString().equals("Issue Type")) {
                        statusVal.put("issueType", field.get("content").toString());
                    }

                    if (field.get("val").toString().equals("OS Platform")) {
                        statusVal.put("osPlatform", field.get("content").toString());
                    }

                    if (field.get("val").toString().equals("Created At")) {
                        statusVal.put("createdAt", field.get("content").toString());
                    }

                }

                JSONArray currentStatusValue = (JSONArray) statusJson.get(statusName);
                if (currentStatusValue == null) {
                    JSONArray newVal = new JSONArray();
                    newVal.add(statusVal);
                    statusJson.put(statusName, newVal);
                } else {
                    currentStatusValue.add(statusVal);
                }

            }
        }

        return statusJson;
    }

    public JSONObject statusJSONToModuleCount(JSONArray statusJSONArray) {
        JSONObject moduleWiseCount = new JSONObject();
        for (Iterator<JSONObject> ticketIterator = statusJSONArray.iterator(); ticketIterator.hasNext();) {
            JSONObject ticket = ticketIterator.next();
            String moduleName = ticket.get("moduleName").toString();
            if (!moduleWiseCount.containsKey(moduleName)) {
                moduleWiseCount.put(moduleName, 1);
            } else {
                int existingCount = (Integer) moduleWiseCount.get(moduleName);
                moduleWiseCount.put(moduleName, existingCount + 1);
            }

        }

        return moduleWiseCount;
    }

    public JSONArray ticketsForSpecfiedTime(JSONArray allTickets, String specifiedTime, String[] status,
            String rowName) {
        Date start_date = null;
        Date end_date = null;
        if (specifiedTime.equals("LAST_WEEK")) {
            end_date = new Date();
            Calendar oneWeekBack = Calendar.getInstance();
            oneWeekBack.setTime(end_date);
            oneWeekBack.add(Calendar.DATE, -7);
            start_date = oneWeekBack.getTime();
            return ticketsForSpecificTimeHelper(allTickets, start_date, end_date, status, rowName);
        }
        if (specifiedTime.equals("LAST_MONTH")) {
            end_date = new Date();
            Calendar oneWeekBack = Calendar.getInstance();
            oneWeekBack.setTime(end_date);
            oneWeekBack.add(Calendar.MONTH, -1);
            start_date = oneWeekBack.getTime();
            return ticketsForSpecificTimeHelper(allTickets, start_date, end_date, status, rowName);
        } else {
            return null;
        }

    }

    public JSONArray ticketsForSpecificTimeHelper(JSONArray allTickets, Date start_date, Date end_date,
            String[] status, String rowName) {

        JSONArray moduleCountForTickets = new JSONArray();
        for (int i = 0; i < status.length; i++) {
            JSONObject statusJSON = new JSONObject();
            statusJSON.put("status", status[i]);
            statusJSON.put("moduleSummary", null);
            moduleCountForTickets.add(statusJSON);
        }
        for (Iterator<JSONObject> it = allTickets.iterator(); it.hasNext();) {
            JSONObject twoHundredTickets = (JSONObject) it.next();

            JSONArray row = getRowsFromSupportapiJSON(twoHundredTickets, rowName);

            for (Iterator<JSONObject> it1 = row.iterator(); it1.hasNext();) {
                JSONArray fl = (JSONArray) it1.next().get("fl");

                String tempStatus = null;
                String tempModule = null;
                boolean isSpecifiedTime = false;
                JSONObject moduleToAdd = null;
                for (Iterator<JSONObject> it2 = fl.iterator(); it2.hasNext();) {
                    JSONObject indiFieldVal = it2.next();
                    if (indiFieldVal.get("val").toString().equals("Status")) {
                        for (Iterator<JSONObject> it3 = moduleCountForTickets.iterator(); it3.hasNext();) {
                            moduleToAdd = it3.next();
                            if (indiFieldVal.get("content").toString().equals(moduleToAdd.get("status"))) {
                                tempStatus = indiFieldVal.get("content").toString();
                                //System.out.println(moduleToAdd.get("status"));
                                break;
                            } else {
                                moduleToAdd = null;
                            }

                        }
                    }
                    if (indiFieldVal.get("val").toString().equals("Module")) {

                        tempModule = indiFieldVal.get("content").toString();
                    }
                    if (indiFieldVal.get("val").toString().equals("Created At")) {
                        Date createdDate = null;
                        try {
                            String createdTime = indiFieldVal.get("content").toString();

                            String createdTimeSplit[] = createdTime.split(" ");
                            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                            createdDate = (Date) formatter.parse(createdTimeSplit[0]);

                            /*System.out.println("Current Date" + formatter.format(currDate));
                             System.out.println("Created Date" + formatter.format(createdDate));
                             System.out.println("One week back date" + formatter.format(lastWeekDate));*/
                            //2013-08-12 18:46:00
                        } catch (java.text.ParseException ex) {
                            Logger.getLogger(JSONOperations.class.getName()).log(Level.SEVERE, null, ex);
                        }

                        isSpecifiedTime = createdDate.after(start_date) && createdDate.before(end_date);
                        //System.out.print("\t" + isSpecifiedTime);
                    }
                }
                if (moduleToAdd != null && isSpecifiedTime) {
                    //System.out.print("\t" + tempModule);
                    if (moduleToAdd.get("moduleSummary") == null) {
                        JSONObject indiModuleSummary = new JSONObject();
                        indiModuleSummary.put("moduleName", tempModule);
                        indiModuleSummary.put("moduleCount", 1);
                        JSONArray moduleSummary = new JSONArray();
                        moduleSummary.add(indiModuleSummary);
                        moduleToAdd.put("moduleSummary", moduleSummary);
                    } else {
                        JSONArray moduleSummary = (JSONArray) moduleToAdd.get("moduleSummary");
                        JSONObject indiModuleSummary = null;
                        for (Iterator<JSONObject> it4 = moduleSummary.iterator(); it4.hasNext();) {
                            indiModuleSummary = it4.next();
                            if (indiModuleSummary.get("moduleName").toString().equals(tempModule)) {
                                indiModuleSummary.put("moduleCount",
                                        (Integer) indiModuleSummary.get("moduleCount") + 1);
                            } else {
                                indiModuleSummary = null;
                            }
                        }

                        if (indiModuleSummary == null) {
                            indiModuleSummary = new JSONObject();
                            indiModuleSummary.put("moduleName", tempModule);
                            indiModuleSummary.put("moduleCount", 1);
                            moduleSummary.add(indiModuleSummary);
                        }
                    }
                }

            }

        }

        return moduleCountForTickets;
    }

    public JSONArray WOESummGenForResponseJSONObject(JSONObject JSONObjectToParse, String departName,
            JSONArray WOERows, String rowName) {
        loggerObj.log(Level.INFO, "Inside WOESummGenForResponseJSONObject for parsing JSON data");
        if (WOERows == null) {
            WOERows = new JSONArray();
        }

        try {

            loggerObj.log(Level.INFO, "Going to get row data from the individual response JSON objects");
            JSONArray row = getRowsFromSupportapiJSON(JSONObjectToParse, rowName);
            Iterator<JSONObject> iterator = row.iterator();
            String[] dcMdmModules = new String[] { "MDM-Profile Mgmt", "MDM-App Mgmt", "MDM-Settings",
                    "MDM-Enrollment", "MDM-Asset Mgmt", "App Mgmt", "Enrollment", "MDM Settings", "Geo-Location",
                    "ProfileMgmt" };
            while (iterator.hasNext()) {
                loggerObj.log(Level.INFO,
                        "Going to iterate over individual field data from the row obatianed from parsing individual response json objects");
                JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
                Iterator<JSONObject> innerIterator = rowIndex.iterator();

                JSONObject WOERow = new JSONObject();
                while (innerIterator.hasNext()) {
                    JSONObject field = innerIterator.next();

                    // System.out.println(field.get("content") + "\t" + field.get("val"));
                    if (field.get("val").toString().equals("URI")) {

                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("URI", content);

                    }

                    if (field.get("val").toString().equals("Email")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Email", content);
                    }

                    if (field.get("val").toString().equals("Ticket Classification")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Issue Type", content);
                    }

                    if (field.get("val").toString().equals("Status")) {
                        if (field.get("content") != null) {
                            if (field.get("content").toString().equals("Waiting on Engineering")
                                    || field.get("content").toString().contains("Need")) {
                                if (departName.equals("Desktop Central")) {
                                    loggerObj.log(Level.INFO, "The status object is entered");
                                }
                                WOERow.put("Status", field.get("content").toString());
                            } else {
                                break;
                            }

                        }
                    }
                    if (field.get("val").toString().equals("Ticket Owner")) {

                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Ticket Owner", content);

                    }

                    if (field.get("val").toString().equals("Case Owner")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Case Owner", content);
                    }

                    if (field.get("val").toString().equals("Created Time")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Created Time", content);
                    }
                    if (field.get("val").toString().equals("Ticket Id")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Ticket Id", content);

                    }
                    if (field.get("val").toString().equals("Developers")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Developers", content);
                    }
                    if (field.get("val").toString().equals("Modules")) {
                        if (field.get("content").toString() != null) {
                            loggerObj.log(Level.INFO, "Modules: " + field.get("content").toString());
                            String moduleName = field.get("content").toString();
                            if (departName.equals("Desktop Central")) {
                                for (String i : dcMdmModules) {
                                    if (moduleName.equals(i)) {
                                        WOERow.put("Modules", moduleName);
                                        loggerObj.log(Level.INFO, "Module is " + moduleName);

                                        continue;
                                    }

                                }

                            } else {

                                WOERow.put("Modules", moduleName);
                            }
                        }
                    }
                    if (field.get("val").toString().equals("Department Map")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Department Map", content);
                    }
                    if (field.get("val").toString().equals("Due Date")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Due Date", content);
                    }

                    if (field.get("val").toString().equals("Problem Description")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Problem Description", content);
                    }

                    if (field.get("val").toString().equals("Modified Time")) {
                        String content = (String) field.get("content");
                        if (content == null || content.equals("null")) {
                            content = "--";
                        }

                        WOERow.put("Last Updated At", content);
                    }
                }
                if (WOERow.get("Status") != null && WOERow.get("Modules") != null) {
                    loggerObj.log(Level.INFO, "WOEROw added: status" + WOERow.get("Status").toString() + "Modules"
                            + WOERow.get("Modules").toString());
                    WOERows.add(WOERow);
                }
            }

            loggerObj.log(Level.INFO, "Successfully parsed the data");
            return WOERows;

        } catch (Exception e) {
            loggerObj.log(Level.SEVERE, "Error in parsing the data", e);
            return null;
        }

    }

    public JSONArray WOESummGenForResponseArray(JSONArray JSONArrayToParse, String departName, String rowName) {
        loggerObj.log(Level.INFO, "Insied WOESummGenForResponseArray for parsing data");
        JSONArray WOERows = new JSONArray();

        try {
            loggerObj.log(Level.INFO, "Going to iterate over the responseJSONArray");
            Iterator<JSONObject> jsonObjectItr = JSONArrayToParse.iterator();
            while (jsonObjectItr.hasNext()) {
                loggerObj.log(Level.INFO,
                        "Going to get row data from the individual JSON objects parsed from responseJSONArray");
                JSONArray row = getRowsFromSupportapiJSON((JSONObject) jsonObjectItr.next(), rowName);
                Iterator<JSONObject> iterator = row.iterator();

                while (iterator.hasNext()) {
                    loggerObj.log(Level.INFO,
                            "Going to iterate over individual field data from the row obatianed from parsing individual response json objects");
                    JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
                    Iterator<JSONObject> innerIterator = rowIndex.iterator();

                    JSONObject WOERow = new JSONObject();
                    while (innerIterator.hasNext()) {
                        JSONObject field = innerIterator.next();

                        // System.out.println(field.get("content") + "\t" + field.get("val"));
                        if (field.get("val").toString().equals("URI")) {
                            WOERow.put("URI", field.get("content").toString());
                        }

                        if (field.get("val").toString().equals("Email")) {
                            WOERow.put("Email", field.get("content").toString());
                        }

                        if (field.get("val").toString().equals("Subject")) {
                            WOERow.put("Subject", field.get("content").toString());
                        }

                        if (field.get("val").toString().equals("Status")) {
                            // System.out.println(field.get("content").toString());
                            if (!field.get("content").toString().equals("Waiting on Engineering")
                                    && !field.get("content").toString().contains("Need")) {
                                break;
                            } else {
                                WOERow.put("Status", field.get("content").toString());
                            }

                        }
                        if (field.get("val").toString().equals("Ticket Owner")) {
                            WOERow.put("Ticket Owner", field.get("content").toString());
                        }

                        if (field.get("val").toString().equals("Case Owner")) {
                            WOERow.put("Case Owner", field.get("content").toString());
                        }

                        if (field.get("val").toString().equals("Created Time")) {
                            WOERow.put("Created Time", field.get("content").toString());
                        }
                        if (field.get("val").toString().equals("Ticket Id")) {
                            //System.out.print("\t" + field.get("content").toString());
                            WOERow.put("Ticket Id", field.get("content").toString());
                        }
                        if (field.get("val").toString().equals("Developers")) {
                            WOERow.put("Developers", field.get("content").toString());
                        }
                        if (field.get("val").toString().equals("Modules")) {
                            String moduleName = field.get("content").toString();
                            if (departName.equals("Desktop Central")) {
                                if (moduleName.equals("App Mgmt") || moduleName.equals("Enrollment")
                                        || moduleName.equals("MDM Settings") || moduleName.equals("Geo-Location")
                                        || moduleName.equals("ProfileMgmt")) {
                                    WOERow.put("Modules", field.get("content").toString());
                                } else {
                                    break;
                                }

                            } else {
                                WOERow.put("Modules", field.get("content").toString());
                            }
                        }
                        if (field.get("val").toString().equals("Department Map")) {
                            WOERow.put("Department Map", field.get("content").toString());
                        }
                        if (field.get("val").toString().equals("Due Date")) {
                            WOERow.put("Due Date", field.get("content").toString());

                        }

                        if (field.get("val").toString().equals("Problem Description")) {
                            if (field.get("content") == null || field.get("content").toString().equals("null")) {
                                WOERow.put("Problem Description", "--");
                            } else {
                                WOERow.put("Problem Description", field.get("content").toString());
                            }
                        }
                    }
                    if (WOERow.get("Status") != null && WOERow.get("Modules") != null) {
                        WOERows.add(WOERow);
                    }
                }

            }

            loggerObj.log(Level.INFO, "Successfully parsed the data");
            return WOERows;

        } catch (Exception e) {
            loggerObj.log(Level.INFO, "Error in parsing the data" + e.toString());
            return null;
        }
    }

    public JSONObject mergeOwnerWithCount(JSONObject Mod_Count, JSONObject module_Owner) {
        JSONObject Mod_Count_Owner = new JSONObject();

        Set<String> Module_Owner_Keys = module_Owner.keySet();
        Set<String> Mod_Count_keys = Mod_Count.keySet();

        for (Iterator it = Mod_Count_keys.iterator(); it.hasNext();) {
            String moduleName = it.next().toString();
            System.out.println(moduleName);
            JSONObject moduleSummary = new JSONObject();
            Mod_Count_Owner.put(moduleName, moduleSummary);
            moduleSummary.put("moduleCount", Mod_Count.get(moduleName));

            String owner = "--";
            if (Module_Owner_Keys.contains(moduleName)) {
                owner = module_Owner.get(moduleName).toString();
            }
            moduleSummary.put("moduleOwner", owner);

        }

        return Mod_Count_Owner;
    }

    //sees if the key present in first primary is avaiable in the secondary
    public JSONObject appendTwoJSONObjectsWithSameKeys(JSONObject moduleSummary, JSONObject moduleOwnerSumm) {

        Set<String> moduleCountkeys = moduleSummary.keySet();

        Set<String> moduleOwnerKeys = moduleOwnerSumm.keySet();
        for (Iterator moduleCountItr = moduleCountkeys.iterator(); moduleCountItr.hasNext();) {
            String owner = "--";
            String moduleCountName = (String) moduleCountItr.next();

            if (moduleOwnerKeys.contains(moduleCountName)) {
                owner = (String) moduleOwnerSumm.get(moduleCountName);
            }
            JSONObject indiModuleJO = (JSONObject) moduleSummary.get(moduleCountName);
            indiModuleJO.put("Owner", owner);
            moduleSummary.put(moduleCountName, indiModuleJO);
        }

        return moduleSummary;

    }

    public static boolean isErrorJSON(String JSONString) {
        JSONParser parser = new JSONParser();
        try {
            JSONObject json = (JSONObject) parser.parse(JSONString);
            JSONObject response = (JSONObject) json.get("response");
            JSONObject result = (JSONObject) response.get("result");
            JSONObject error = (JSONObject) response.get("error");
            if (result == null) {
                return true;
            }
            if (error != null) {
                return true;
            }
        } catch (ParseException ex) {
            Logger.getLogger(JSONOperations.class.getName()).log(Level.SEVERE, null, ex);
            return true;
        }

        return false;
    }

    /*public JSONObject fileToJSONObject(String fileToRead, String fileToWrite) {
        
     JSONParser parser = new JSONParser();
     HashMap<String, Integer> moduleCount = new HashMap();
     try {
        
     Object obj = parser.parse(new FileReader(fileToRead));
        
     JSONArray jsonArrObject = (JSONArray) obj;
     Iterator<JSONObject> jsonObjectItr = jsonArrObject.iterator();
     while (jsonObjectItr.hasNext()) {
     JSONObject jsonObject = jsonObjectItr.next();
        
     JSONObject response = (JSONObject) jsonObject.get("response");
     //System.out.println(result.toString());
     JSONObject result = (JSONObject) response.get("result");
     //JSONArray row = (JSONArray) cases.get("row");
     JSONObject cases = (JSONObject) result.get("Cases");
     JSONArray row = (JSONArray) cases.get("row");
     //System.out.println(row);
     //System.out.println("Name: " + name);
     //System.out.println("Author: " + author);
     //System.out.println("\nCompany List:");
     Iterator<JSONObject> iterator = row.iterator();
     while (iterator.hasNext()) {
     JSONArray rowIndex = (JSONArray) iterator.next().get("fl");
     Iterator<JSONObject> innerIterator = rowIndex.iterator();
     // int count = 0;
     String status = null;
     while (innerIterator.hasNext()) {
     JSONObject field = innerIterator.next();
     if (!field.get("val").toString().equals("URI")) {
     // System.out.println(field.get("content") + "\t" + field.get("val"));
        
     if (field.get("val").toString().equals("Status")) {
     status = field.get("content").toString();
     }
     if (field.get("val").toString().equals("Module") && (status == null || status.equals("Open"))) {
     if (moduleCount.get(field.get("content")) == null) {
     moduleCount.put(field.get("content").toString(), 0);
     }
     moduleCount.put(field.get("content").toString(), moduleCount.get(field.get("content")) + 1);
     }
        
     }
        
     }
     }
        
     }
        
     for (Map.Entry<String, Integer> entry : moduleCount.entrySet()) {
     System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
     }
        
     writeToCSV(moduleCount, fileToWrite);
        
     } catch (Exception e) {
     e.printStackTrace();
     }
     return null;
     }
        
     static void writeToCSV(HashMap<String, Integer> moduleCount, String CSVFileToWrite) {
     BufferedWriter bw = null;
     File file = new File(CSVFileToWrite);
        
     if (!file.exists()) {
     try {
     file.createNewFile();
     } catch (IOException ex) {
     Logger.getLogger(JSONOperations.class.getName()).log(Level.SEVERE, null, ex);
     }
        
     }
        
     FileWriter fw;
     try {
     fw = new FileWriter(file, true);
     bw = new BufferedWriter(fw);
        
     for (Map.Entry<String, Integer> entry : moduleCount.entrySet()) {
     //System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
     bw.write(entry.getKey() + "," + entry.getValue());
     bw.newLine();
     }
        
     bw.close();
        
     } catch (IOException ex) {
     Logger.getLogger(JSONOperations.class.getName()).log(Level.SEVERE, null, ex);
     }
        
     }*/
}