IoT DAS Frameworks - IT Infra Monitoring and Analytics/IOT_Applications/Performance_Dashboard_Application(Reference App)/source/SA-DashBoard/src/java/com/merit/dashboard/DAO/metrics/LineChartMetrics.java
public String executeQueryForLineChart_1(String szQuery,String customer){
    	Connection uniqueconnection=null;
    	Statement stat=null;
    	ResultSet rs=null;
    	String szLineChartJson="[]";
    	HashMap<String,String> map_metricName      = new HashMap<String, String>();
    	HashMap<String,String> map_metricTimeStamp = new HashMap<String, String>();
    	HashMap<String,String> map_metricValue     = new HashMap<String, String>();
        HashMap<String,String> map_metricSla       = new HashMap<String, String>();
        HashMap<String, JSONObject> jsonObjMap     = new HashMap<String, JSONObject>();
    	try{

             /**
                ServerName
                ResourceType
                ResourceID
                ServiceName
                arr_    ResourceNames
                arr_    TimeStamps
                arr_    ResourceValues
                arr_    SlaValues
                * key = "'ServerName':'"+serverName+"','ResourceType':'"+resourceType+"','ResourceID':'"+resourceID+"','ServiceName':'"+serviceName+"',"
             */
             uniqueconnection=ConnectionDAO.getConnection(customer);
             stat = uniqueconnection.createStatement();
             rs = stat.executeQuery(szQuery);
             String key = null;
             JSONObject tjsonObj = null;
             System.out.println("manual lineChart logic start:"+new Date());
             while (rs.next()) {
                key =   "'ServerName':'"     + rs.getString("ServerName") +
                      "','ResourceType':'"   + rs.getString("ResourceType") +
                      "','ResourceID':'"     + rs.getString("ResourceID") +
                      "','ServiceName':'"    + rs.getString("ServiceName") +
                      "','ActualMetricNames':['" + rs.getString("ResourceNames")+"']" +
                      " ,'ResourceNames':['" + DBUtilHelper.getMetrics_mapping_properties().getProperty(rs.getString("ResourceNames"))+"'],";

                //updateMap(map_metricName,      rs, key, "ResourceNames");
                updateMap(map_metricTimeStamp, rs, key, "TimeStamps");
                updateMap(map_metricValue,     rs, key, "ResourceValues");
                updateMap(map_metricSla,       rs, key, "SlaValues");
             }
             Set <String> keySet = map_metricTimeStamp.keySet();
             for(String keyStr : keySet){
                 String jsonSTR = keyStr
                                    + "'TimeStamps':     [[" + map_metricTimeStamp.get(keyStr) + " ]],"
                                    + "'ResourceValues': [[" + map_metricValue.get(keyStr).replaceAll("\"", "").replaceAll("'", "")     + " ]],"
                                    + "'SlaValues':      [[" + map_metricSla.get(keyStr).replaceAll("\"", "").replaceAll("'", "")      + " ]]";
                 JSONObject jsonObj = new JSONObject("{" +jsonSTR +"}");
                 key = keyStr.split(",'ResourceNames'")[0];
                 tjsonObj = jsonObjMap.get(key);
                 if(tjsonObj == null){
                     tjsonObj = jsonObj;
                 } else{

                    /*tjsonObj = CommonMongoChangerMethods.accumulateJSONObject(
                            tjsonObj,
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"},
                            jsonObj,
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"},
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName"});*/
                    tjsonObj = accumulateJSONSAllArray(
                            tjsonObj,
                            jsonObj,
                            new String[] {"ActualMetricNames", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"}
                    );
                 }
                 jsonObjMap.put(key, tjsonObj);
             }
             System.out.println("manual lineChart logic End:"+new Date());
            /**
                ServerName
                ResourceType
                ResourceID
                ServiceName
                arr_    ResourceNames
                arr_    TimeStamps
                arr_    ResourceValues
                arr_    SlaValues
                *

                * key = "'ServerName':'"+serverName+"','ResourceType':'"+resourceType+"','ResourceID':'"+resourceID+"','ServiceName':'"+serviceName+"',"
             */
             //System.out.println("\n\n\n jsonObjMap = " + jsonObjMap);
             szLineChartJson = getJSONArrayFromObjectMap(jsonObjMap).toString();
             map_metricName=null;
             map_metricValue=null;
             map_metricTimeStamp=null;
             map_metricSla=null;
        } catch (Exception e) {
    		e.printStackTrace();
    	}
    	finally {
    		try {
    			if (stat != null) {
    				stat.close();
    				stat = null;
    			}
				if (rs != null) {
					rs.close();
					rs = null;
				}
    		}
    		catch (Exception e) {
				e.printStackTrace();
				log.error("DashBoard LineCharMetrics  executeQueryForLineChart()  :\n"+ e.getMessage());
			}
		}
    	return szLineChartJson;
	}
/**
	 * ***************************************************************************************************
	 *  Executing Query and making HashMap of SLA,MetricValues,MetricNames,Timestamp
	 *  then sending to generateJsonForMultipleMetricType() to generate JSON for
	 *  TimeLine LineChart
	 *  @param szQuery Query to Be Executed for Line Chart
	 *  @param customer Customer Id
	 *
	 * ***************************************************************************************************
	 */
Executing Query and making HashMap of SLA,MetricValues,MetricNames,Timestamp
then sending to generateJsonForMultipleMetricType() to generate JSON for
TimeLine LineChart
@param szQuery Query to Be Executed for Line Chart
@param customer Customer Id
Executing Query and making HashMap of SLA MetricValues MetricNames Timestamp then sending to generateJsonForMultipleMetricType () to generate JSON for TimeLine LineChart @param szQuery Query to Be Executed for Line Chart @param customer Customer Id
public String executeQueryForLineChart_1(String szQuery,String customer){
    	Connection uniqueconnection=null;
    	Statement stat=null;
    	ResultSet rs=null;
    	String szLineChartJson="[]";
    	HashMap<String,String> map_metricName      = new HashMap<String, String>();
    	HashMap<String,String> map_metricTimeStamp = new HashMap<String, String>();
    	HashMap<String,String> map_metricValue     = new HashMap<String, String>();
        HashMap<String,String> map_metricSla       = new HashMap<String, String>();
        HashMap<String, JSONObject> jsonObjMap     = new HashMap<String, JSONObject>();
    	try{
             /**
                ServerName
                ResourceType
                ResourceID
                ServiceName
                arr_    ResourceNames
                arr_    TimeStamps
                arr_    ResourceValues
                arr_    SlaValues
                * key = "'ServerName':'"+serverName+"','ResourceType':'"+resourceType+"','ResourceID':'"+resourceID+"','ServiceName':'"+serviceName+"',"
             */
             uniqueconnection=ConnectionDAO.getConnection(customer);
             stat = uniqueconnection.createStatement();
             rs = stat.executeQuery(szQuery);
             String key = null;
             JSONObject tjsonObj = null;
             System.out.println("manual lineChart logic start:"+new Date());
             while (rs.next()) {
                key =   "'ServerName':'"     + rs.getString("ServerName") +
                      "','ResourceType':'"   + rs.getString("ResourceType") +
                      "','ResourceID':'"     + rs.getString("ResourceID") +
                      "','ServiceName':'"    + rs.getString("ServiceName") +
                      "','ActualMetricNames':['" + rs.getString("ResourceNames")+"']" +
                      " ,'ResourceNames':['" + DBUtilHelper.getMetrics_mapping_properties().getProperty(rs.getString("ResourceNames"))+"'],";
                updateMap(map_metricTimeStamp, rs, key, "TimeStamps");
                updateMap(map_metricValue,     rs, key, "ResourceValues");
                updateMap(map_metricSla,       rs, key, "SlaValues");
             }
             Set <String> keySet = map_metricTimeStamp.keySet();
             for(String keyStr : keySet){
                 String jsonSTR = keyStr
                                    + "'TimeStamps':     [[" + map_metricTimeStamp.get(keyStr) + " ]],"
                                    + "'ResourceValues': [[" + map_metricValue.get(keyStr).replaceAll("\"", "").replaceAll("'", "")     + " ]],"
                                    + "'SlaValues':      [[" + map_metricSla.get(keyStr).replaceAll("\"", "").replaceAll("'", "")      + " ]]";
                 JSONObject jsonObj = new JSONObject("{" +jsonSTR +"}");
                 key = keyStr.split(",'ResourceNames'")[0];
                 tjsonObj = jsonObjMap.get(key);
                 if(tjsonObj == null){
                     tjsonObj = jsonObj;
                 } else{
                    /*tjsonObj = CommonMongoChangerMethods.accumulateJSONObject(
                            tjsonObj,
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"},
                            jsonObj,
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"},
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName"});*/
                    tjsonObj = accumulateJSONSAllArray(
                            tjsonObj,
                            jsonObj,
                            new String[] {"ActualMetricNames", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"}
                    );
                 }
                 jsonObjMap.put(key, tjsonObj);
             }
             System.out.println("manual lineChart logic End:"+new Date());
            /**
                ServerName
                ResourceType
                ResourceID
                ServiceName
                arr_    ResourceNames
                arr_    TimeStamps
                arr_    ResourceValues
                arr_    SlaValues
                *
                * key = "'ServerName':'"+serverName+"','ResourceType':'"+resourceType+"','ResourceID':'"+resourceID+"','ServiceName':'"+serviceName+"',"
             */
             szLineChartJson = getJSONArrayFromObjectMap(jsonObjMap).toString();
             map_metricName=null;
             map_metricValue=null;
             map_metricTimeStamp=null;
             map_metricSla=null;
        } catch (Exception e) {
    		e.printStackTrace();
    	}
    	finally {
    		try {
    			if (stat != null) {
    				stat.close();
    				stat = null;
    			}
				if (rs != null) {
					rs.close();
					rs = null;
				}
    		}
    		catch (Exception e) {
				e.printStackTrace();
				log.error("DashBoard LineCharMetrics  executeQueryForLineChart()  :\n"+ e.getMessage());
			}
		}
    	return szLineChartJson;
	}
public String executeQueryForLineChart_1 ( String szQuery , String customer ) { Connection uniqueconnection = null ; Statement stat = null ; ResultSet rs = null ; String szLineChartJson = "[]" ; HashMap < String , String > map_metricName = new HashMap < String , String > ( ) ; HashMap < String , String > map_metricTimeStamp = new HashMap < String , String > ( ) ; HashMap < String , String > map_metricValue = new HashMap < String , String > ( ) ; HashMap < String , String > map_metricSla = new HashMap < String , String > ( ) ; HashMap < String , JSONObject > jsonObjMap = new HashMap < String , JSONObject > ( ) ; try { /**
                ServerName
                ResourceType
                ResourceID
                ServiceName
                arr_    ResourceNames
                arr_    TimeStamps
                arr_    ResourceValues
                arr_    SlaValues
                * key = "'ServerName':'"+serverName+"','ResourceType':'"+resourceType+"','ResourceID':'"+resourceID+"','ServiceName':'"+serviceName+"',"
             */ uniqueconnection = ConnectionDAO . getConnection ( customer ) ; stat = uniqueconnection . createStatement ( ) ; rs = stat . executeQuery ( szQuery ) ; String key = null ; JSONObject tjsonObj = null ; System . out . println ( "manual lineChart logic start:" + new Date ( ) ) ; while ( rs . next ( ) ) { key = "'ServerName':'" + rs . getString ( "ServerName" ) + "','ResourceType':'" + rs . getString ( "ResourceType" ) + "','ResourceID':'" + rs . getString ( "ResourceID" ) + "','ServiceName':'" + rs . getString ( "ServiceName" ) + "','ActualMetricNames':['" + rs . getString ( "ResourceNames" ) + "']" + " ,'ResourceNames':['" + DBUtilHelper . getMetrics_mapping_properties ( ) . getProperty ( rs . getString ( "ResourceNames" ) ) + "']," ; updateMap ( map_metricTimeStamp , rs , key , "TimeStamps" ) ; updateMap ( map_metricValue , rs , key , "ResourceValues" ) ; updateMap ( map_metricSla , rs , key , "SlaValues" ) ; } Set < String > keySet = map_metricTimeStamp . keySet ( ) ; for ( String keyStr : keySet ) { String jsonSTR = keyStr + "'TimeStamps':     [[" + map_metricTimeStamp . get ( keyStr ) + " ]]," + "'ResourceValues': [[" + map_metricValue . get ( keyStr ) . replaceAll ( "\"" , "" ) . replaceAll ( "'" , "" ) + " ]]," + "'SlaValues':      [[" + map_metricSla . get ( keyStr ) . replaceAll ( "\"" , "" ) . replaceAll ( "'" , "" ) + " ]]" ; JSONObject jsonObj = new JSONObject ( "{" + jsonSTR + "}" ) ; key = keyStr . split ( ",'ResourceNames'" ) [ 0 ] ; tjsonObj = jsonObjMap . get ( key ) ; if ( tjsonObj == null ) { tjsonObj = jsonObj ; } else { /*tjsonObj = CommonMongoChangerMethods.accumulateJSONObject(
                            tjsonObj,
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"},
                            jsonObj,
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName", "ResourceNames", "TimeStamps", "ResourceValues", "SlaValues"},
                            new String[] {"ServerName","ResourceType", "ResourceID", "ServiceName"});*/ tjsonObj = accumulateJSONSAllArray ( tjsonObj , jsonObj , new String [ ] { "ActualMetricNames" , "ResourceNames" , "TimeStamps" , "ResourceValues" , "SlaValues" } ) ; } jsonObjMap . put ( key , tjsonObj ) ; } System . out . println ( "manual lineChart logic End:" + new Date ( ) ) ; /**
                ServerName
                ResourceType
                ResourceID
                ServiceName
                arr_    ResourceNames
                arr_    TimeStamps
                arr_    ResourceValues
                arr_    SlaValues
                *

                * key = "'ServerName':'"+serverName+"','ResourceType':'"+resourceType+"','ResourceID':'"+resourceID+"','ServiceName':'"+serviceName+"',"
             */ szLineChartJson = getJSONArrayFromObjectMap ( jsonObjMap ) . toString ( ) ; map_metricName = null ; map_metricValue = null ; map_metricTimeStamp = null ; map_metricSla = null ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { try { if ( stat != null ) { stat . close ( ) ; stat = null ; } if ( rs != null ) { rs . close ( ) ; rs = null ; } } catch ( Exception e ) { e . printStackTrace ( ) ; log . error ( "DashBoard LineCharMetrics  executeQueryForLineChart()  :\n" + e . getMessage ( ) ) ; } } return szLineChartJson ; }
Executing Query and making HashMap of SLA,MetricValues,MetricNames,Timestamp
  then sending to generateJsonForMultipleMetricType() to generate JSON for
  TimeLine LineChart
  @param szQuery Query to Be Executed for Line Chart
  @param customer Customer Id
Executing Query and making HashMap of SLA MetricValues MetricNames Timestamp then sending to generateJsonForMultipleMetricType () to generate JSON for TimeLine LineChart @param szQuery Query to Be Executed for Line Chart @param customer Customer Id
//updateMap(map_metricName,      rs, key, "ResourceNames"); //System.out.println("\n\n\n jsonObjMap = " + jsonObjMap);