IoT CAS Frameworks/IOT_Server/Report_Generator_Framework/IT/source/DashBoard-JSONgenerator/src/com/merit/dashboard/bizlogic/BizLogic.java
@SuppressWarnings("rawtypes")
    public String generateDefaultServiceResourcetypeJson(LinkedHashMap<String, String> serviceMetricInfo, LinkedHashMap<String, String> ticketInfo) {
        String szMetricTypeValueJson = "";

        String createJsonWithMap = "";
        String combinedCritical = "";
        String combinedJsonOK = "";
        String combinedJsonWithoutOK = "";
        String combined_BothCritical = "";
        try {
            Iterator it = serviceMetricInfo.entrySet().iterator();

            createJsonWithMap = "";
            boolean flag = false;
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry) it.next();
                String szTicket = "";
                /**
                 * if(pairs.getKey().toString().contains(",null")){ String
                 * metricKey=pairs.getKey().toString(); String
                 * firstPartOfKey=metricKey.substring(0,metricKey.indexOf(","));
                 *
                 * if(ticketInfo.get(firstPartOfKey+",Desktop")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",Desktop"); else
                 * if(ticketInfo.get(firstPartOfKey+",server")!=null) szTicket =
                 * ticketInfo.get(firstPartOfKey+",server"); else
                 * if(ticketInfo.get(firstPartOfKey+",DataBase")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",DataBase"); else
                 * if(ticketInfo.get(firstPartOfKey+",Network")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",Network"); else
                 * if(ticketInfo.get(firstPartOfKey+",JVM")!=null) szTicket =
                 * ticketInfo.get(firstPartOfKey+",JVM"); } else
                 */
                if (ticketInfo.get(pairs.getKey()) == null) {
                    szTicket = "\"Alert\":\"Default\"";
                } else {
                    szTicket = ticketInfo.get(pairs.getKey());
                }

                createJsonWithMap += ",{" + pairs.getValue() + "," + szTicket + "}";


                createJsonWithMap = ",{" + pairs.getValue() + "," + szTicket + "}";
                JSONObject mTempJObj = new JSONObject("{" + pairs.getValue() + "}");
                if (pairs.getValue().toString().contains("CRITICAL") && szTicket.contains("CRITICAL")) {
                    if (mTempJObj.get("Health").toString().endsWith("CRITICAL\"]")) {
                        combined_BothCritical += createJsonWithMap;
                    } else {
                        combined_BothCritical += createJsonWithMap;
                    }
                } else if (createJsonWithMap.contains("CRITICAL")) {
                    if (mTempJObj.get("Health").toString().endsWith("CRITICAL\"]")) {
                        combinedCritical += createJsonWithMap;
                    } else {
                        combinedCritical += createJsonWithMap;
                    }
                }/* else if (!createJsonWithMap.contains("CRITICAL") && !createJsonWithMap.contains("OK")) {
                 combinedCritical += createJsonWithMap;
                 } */ else if (mTempJObj.get("Health").toString().contains("OK")) {
                    combinedJsonOK += createJsonWithMap;
                } else {
                    combinedJsonWithoutOK += createJsonWithMap;
                }
            }
            System.out.println(
                    "\n---------------\ncombinedCritical.substring(1) = " + combinedCritical + " "
                    + "\ncombinedJsonOK = " + combinedJsonOK
                    + "\ncombinedJsonWithoutOK = " + combinedJsonWithoutOK + "\n------------------\n");
            if (!combinedCritical.isEmpty()) {
                flag = true;
                createJsonWithMap = combinedCritical.substring(1) + combinedJsonOK + combinedJsonWithoutOK;
            } else if (!combinedJsonOK.isEmpty()) {
                flag = true;
                createJsonWithMap = combinedJsonOK.substring(1) + combinedJsonWithoutOK;
            } else if (!combinedJsonWithoutOK.isEmpty()) {
                flag = true;
                createJsonWithMap = combinedJsonWithoutOK.substring(1);
            }

            if (!combined_BothCritical.isEmpty() && flag) {
                createJsonWithMap = combined_BothCritical.substring(1) + "," + createJsonWithMap;
            } else if (!combined_BothCritical.isEmpty()) {
                createJsonWithMap = combined_BothCritical.substring(1);
            }

            if (!createJsonWithMap.isEmpty()) {
                szMetricTypeValueJson = "[" + createJsonWithMap + "]";
            } else {
                szMetricTypeValueJson = "[]";
            }

            return szMetricTypeValueJson;
            /*if (!createJsonWithMap.isEmpty())
             szMetricTypeValueJson = "[" + createJsonWithMap.substring(1)+ "]";
             else
             szMetricTypeValueJson = "[]";*/
        } catch (Exception e) {
            e.printStackTrace();
            log.error("DashBoard generateDefaultServiceResourcetypeJson \n" + e.getMessage());
        }
        return szMetricTypeValueJson;
    }
/**
     * **********************************************************************************************
     * Here We are Passing two map serviceMetricInfo and ticketInfo for
     * combining into one Json
     *
     * @param serviceMetricInfo LinkedHashMap having metric Health information
     * @param ticketInfo LinkedHashMap having Ticket Alert information
     * @return szMetricTypeValueJson String Combined Json of
     * serviceMetricInfo,ticketInfo
     * **********************************************************************************************
     */
Here We are Passing two map serviceMetricInfo and ticketInfo for
combining into one Json

@param serviceMetricInfo LinkedHashMap having metric Health information
@param ticketInfo LinkedHashMap having Ticket Alert information
@return szMetricTypeValueJson String Combined Json of
serviceMetricInfo,ticketInfo
Here We are Passing two map serviceMetricInfo and ticketInfo for combining into one Json @param serviceMetricInfo LinkedHashMap having metric Health information @param ticketInfo LinkedHashMap having Ticket Alert information @return szMetricTypeValueJson String Combined Json of serviceMetricInfo ticketInfo
@SuppressWarnings("rawtypes")
    public String generateDefaultServiceResourcetypeJson(LinkedHashMap<String, String> serviceMetricInfo, LinkedHashMap<String, String> ticketInfo) {
        String szMetricTypeValueJson = "";
        String createJsonWithMap = "";
        String combinedCritical = "";
        String combinedJsonOK = "";
        String combinedJsonWithoutOK = "";
        String combined_BothCritical = "";
        try {
            Iterator it = serviceMetricInfo.entrySet().iterator();
            createJsonWithMap = "";
            boolean flag = false;
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry) it.next();
                String szTicket = "";
                /**
                 * if(pairs.getKey().toString().contains(",null")){ String
                 * metricKey=pairs.getKey().toString(); String
                 * firstPartOfKey=metricKey.substring(0,metricKey.indexOf(","));
                 *
                 * if(ticketInfo.get(firstPartOfKey+",Desktop")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",Desktop"); else
                 * if(ticketInfo.get(firstPartOfKey+",server")!=null) szTicket =
                 * ticketInfo.get(firstPartOfKey+",server"); else
                 * if(ticketInfo.get(firstPartOfKey+",DataBase")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",DataBase"); else
                 * if(ticketInfo.get(firstPartOfKey+",Network")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",Network"); else
                 * if(ticketInfo.get(firstPartOfKey+",JVM")!=null) szTicket =
                 * ticketInfo.get(firstPartOfKey+",JVM"); } else
                 */
                if (ticketInfo.get(pairs.getKey()) == null) {
                    szTicket = "\"Alert\":\"Default\"";
                } else {
                    szTicket = ticketInfo.get(pairs.getKey());
                }
                createJsonWithMap += ",{" + pairs.getValue() + "," + szTicket + "}";
                createJsonWithMap = ",{" + pairs.getValue() + "," + szTicket + "}";
                JSONObject mTempJObj = new JSONObject("{" + pairs.getValue() + "}");
                if (pairs.getValue().toString().contains("CRITICAL") && szTicket.contains("CRITICAL")) {
                    if (mTempJObj.get("Health").toString().endsWith("CRITICAL\"]")) {
                        combined_BothCritical += createJsonWithMap;
                    } else {
                        combined_BothCritical += createJsonWithMap;
                    }
                } else if (createJsonWithMap.contains("CRITICAL")) {
                    if (mTempJObj.get("Health").toString().endsWith("CRITICAL\"]")) {
                        combinedCritical += createJsonWithMap;
                    } else {
                        combinedCritical += createJsonWithMap;
                    }
                }/* else if (!createJsonWithMap.contains("CRITICAL") && !createJsonWithMap.contains("OK")) {
                 combinedCritical += createJsonWithMap;
                 } */ else if (mTempJObj.get("Health").toString().contains("OK")) {
                    combinedJsonOK += createJsonWithMap;
                } else {
                    combinedJsonWithoutOK += createJsonWithMap;
                }
            }
            System.out.println(
                    "\n---------------\ncombinedCritical.substring(1) = " + combinedCritical + " "
                    + "\ncombinedJsonOK = " + combinedJsonOK
                    + "\ncombinedJsonWithoutOK = " + combinedJsonWithoutOK + "\n------------------\n");
            if (!combinedCritical.isEmpty()) {
                flag = true;
                createJsonWithMap = combinedCritical.substring(1) + combinedJsonOK + combinedJsonWithoutOK;
            } else if (!combinedJsonOK.isEmpty()) {
                flag = true;
                createJsonWithMap = combinedJsonOK.substring(1) + combinedJsonWithoutOK;
            } else if (!combinedJsonWithoutOK.isEmpty()) {
                flag = true;
                createJsonWithMap = combinedJsonWithoutOK.substring(1);
            }
            if (!combined_BothCritical.isEmpty() && flag) {
                createJsonWithMap = combined_BothCritical.substring(1) + "," + createJsonWithMap;
            } else if (!combined_BothCritical.isEmpty()) {
                createJsonWithMap = combined_BothCritical.substring(1);
            }
            if (!createJsonWithMap.isEmpty()) {
                szMetricTypeValueJson = "[" + createJsonWithMap + "]";
            } else {
                szMetricTypeValueJson = "[]";
            }
            return szMetricTypeValueJson;
            /*if (!createJsonWithMap.isEmpty())
             szMetricTypeValueJson = "[" + createJsonWithMap.substring(1)+ "]";
             else
             szMetricTypeValueJson = "[]";*/
        } catch (Exception e) {
            e.printStackTrace();
            log.error("DashBoard generateDefaultServiceResourcetypeJson \n" + e.getMessage());
        }
        return szMetricTypeValueJson;
    }
@ SuppressWarnings ( "rawtypes" ) public String generateDefaultServiceResourcetypeJson ( LinkedHashMap < String , String > serviceMetricInfo , LinkedHashMap < String , String > ticketInfo ) { String szMetricTypeValueJson = "" ; String createJsonWithMap = "" ; String combinedCritical = "" ; String combinedJsonOK = "" ; String combinedJsonWithoutOK = "" ; String combined_BothCritical = "" ; try { Iterator it = serviceMetricInfo . entrySet ( ) . iterator ( ) ; createJsonWithMap = "" ; boolean flag = false ; while ( it . hasNext ( ) ) { Map . Entry pairs = ( Map . Entry ) it . next ( ) ; String szTicket = "" ; /**
                 * if(pairs.getKey().toString().contains(",null")){ String
                 * metricKey=pairs.getKey().toString(); String
                 * firstPartOfKey=metricKey.substring(0,metricKey.indexOf(","));
                 *
                 * if(ticketInfo.get(firstPartOfKey+",Desktop")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",Desktop"); else
                 * if(ticketInfo.get(firstPartOfKey+",server")!=null) szTicket =
                 * ticketInfo.get(firstPartOfKey+",server"); else
                 * if(ticketInfo.get(firstPartOfKey+",DataBase")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",DataBase"); else
                 * if(ticketInfo.get(firstPartOfKey+",Network")!=null) szTicket
                 * = ticketInfo.get(firstPartOfKey+",Network"); else
                 * if(ticketInfo.get(firstPartOfKey+",JVM")!=null) szTicket =
                 * ticketInfo.get(firstPartOfKey+",JVM"); } else
                 */ if ( ticketInfo . get ( pairs . getKey ( ) ) == null ) { szTicket = "\"Alert\":\"Default\"" ; } else { szTicket = ticketInfo . get ( pairs . getKey ( ) ) ; } createJsonWithMap += ",{" + pairs . getValue ( ) + "," + szTicket + "}" ; createJsonWithMap = ",{" + pairs . getValue ( ) + "," + szTicket + "}" ; JSONObject mTempJObj = new JSONObject ( "{" + pairs . getValue ( ) + "}" ) ; if ( pairs . getValue ( ) . toString ( ) . contains ( "CRITICAL" ) && szTicket . contains ( "CRITICAL" ) ) { if ( mTempJObj . get ( "Health" ) . toString ( ) . endsWith ( "CRITICAL\"]" ) ) { combined_BothCritical += createJsonWithMap ; } else { combined_BothCritical += createJsonWithMap ; } } else if ( createJsonWithMap . contains ( "CRITICAL" ) ) { if ( mTempJObj . get ( "Health" ) . toString ( ) . endsWith ( "CRITICAL\"]" ) ) { combinedCritical += createJsonWithMap ; } else { combinedCritical += createJsonWithMap ; } } /* else if (!createJsonWithMap.contains("CRITICAL") && !createJsonWithMap.contains("OK")) {
                 combinedCritical += createJsonWithMap;
                 } */ else if ( mTempJObj . get ( "Health" ) . toString ( ) . contains ( "OK" ) ) { combinedJsonOK += createJsonWithMap ; } else { combinedJsonWithoutOK += createJsonWithMap ; } } System . out . println ( "\n---------------\ncombinedCritical.substring(1) = " + combinedCritical + " " + "\ncombinedJsonOK = " + combinedJsonOK + "\ncombinedJsonWithoutOK = " + combinedJsonWithoutOK + "\n------------------\n" ) ; if ( ! combinedCritical . isEmpty ( ) ) { flag = true ; createJsonWithMap = combinedCritical . substring ( 1 ) + combinedJsonOK + combinedJsonWithoutOK ; } else if ( ! combinedJsonOK . isEmpty ( ) ) { flag = true ; createJsonWithMap = combinedJsonOK . substring ( 1 ) + combinedJsonWithoutOK ; } else if ( ! combinedJsonWithoutOK . isEmpty ( ) ) { flag = true ; createJsonWithMap = combinedJsonWithoutOK . substring ( 1 ) ; } if ( ! combined_BothCritical . isEmpty ( ) && flag ) { createJsonWithMap = combined_BothCritical . substring ( 1 ) + "," + createJsonWithMap ; } else if ( ! combined_BothCritical . isEmpty ( ) ) { createJsonWithMap = combined_BothCritical . substring ( 1 ) ; } if ( ! createJsonWithMap . isEmpty ( ) ) { szMetricTypeValueJson = "[" + createJsonWithMap + "]" ; } else { szMetricTypeValueJson = "[]" ; } return szMetricTypeValueJson ; /*if (!createJsonWithMap.isEmpty())
             szMetricTypeValueJson = "[" + createJsonWithMap.substring(1)+ "]";
             else
             szMetricTypeValueJson = "[]";*/ } catch ( Exception e ) { e . printStackTrace ( ) ; log . error ( "DashBoard generateDefaultServiceResourcetypeJson \n" + e . getMessage ( ) ) ; } return szMetricTypeValueJson ; }
Here We are Passing two map serviceMetricInfo and ticketInfo for
 combining into one Json
Here We are Passing two map serviceMetricInfo and ticketInfo for combining into one Json