IoT CAS Frameworks/IOT_Server/Report_Generator_Framework/source/DashBoard-JSONgenerator-ArbitraryDate/src/com/merit/dashboard/file/SendFileToJson.java
public void sendDataToFile(String timestampselection, String selection) {
        String szProjectName = DBUtilHelper.getMetrics_mapping_properties().getProperty("projectName");
        //String tomcat_home = System.getProperty("catalina.base");
        String tomcat_home = DBUtilHelper.dashBoardJSONPATH;
        String file_Path = "";
        String szDate = sdf.format(cal.getTime());
        System.out.println("currentTime in sendDataToFile=" + cal.toString());
        System.out.println("szDate in sendDataToFile=" + szDate);
        if (resourceType.equalsIgnoreCase("")) {
            //file_Path = tomcat_home + File.separator + "webapps" + File.separator + szProjectName + File.separator + customer + File.separator + timestampselection + File.separator + jsonFileName + ".json";
            /*this line replace with below if else block for watchdogalert.json to be saved under date directory
             * file_Path = tomcat_home + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
             */
            if (jsonFileName.equalsIgnoreCase("watchdogalert")) {
                file_Path = tomcat_home/*+ File.separator + "webapps"*/ + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate;
            } else {
                file_Path = tomcat_home/*+ File.separator + "webapps"*/ + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
            }
            if (cCustomer != null) {
                file_Path += File.separator + cCustomer;
            }
            if (service != null) {
                file_Path += File.separator + service;
            }
            file_Path += File.separator + jsonFileName + ".json";
        } else {
            if (selection.equalsIgnoreCase("")) {
                //file_Path = tomcat_home + File.separator + "webapps" + File.separator + szProjectName + File.separator + customer + File.separator + timestampselection + File.separator + resourceType + File.separator + resourceType + jsonFileName + ".json";
                file_Path = tomcat_home + /*File.separator + "webapps" +*/ File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
                if (cCustomer != null) {
                    file_Path += File.separator + cCustomer;
                }
                if (service != null) {
                    file_Path += File.separator + service;
                }
                file_Path += File.separator + resourceType + File.separator + resourceType + jsonFileName + ".json";
            } else {
                //file_Path = tomcat_home + File.separator + "webapps" + File.separator + szProjectName + File.separator + customer + File.separator + timestampselection + File.separator + resourceType + File.separator + selection + File.separator + resourceType + jsonFileName + ".json";
                file_Path = tomcat_home + /*File.separator + "webapps" +*/ File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
                if (cCustomer != null) {
                    file_Path += File.separator + cCustomer;
                }
                if (service != null) {
                    file_Path += File.separator + service;
                }
                file_Path += File.separator + resourceType + File.separator + selection + File.separator + resourceType
                        + jsonFileName + ".json";
            }
        }
        while (file_Path.contains(File.separator + File.separator)) {
            file_Path = file_Path.replaceAll(File.separator + File.separator, File.separator);
        }
        File file = new File(file_Path);
        if (file.exists()) {
            file.delete();
        }
        try {
            file.createNewFile();
        } catch (IOException ex) {
            ex.printStackTrace();
            log.error("Error in sendDataToFile" + ex.toString());
        }
        try {
            FileOutputStream fos = new FileOutputStream(file, false);
            fos.write(dataString.getBytes());
            fos.close();
            String szFileContent = "";
            if (dataString.length() < 5) {
                szFileContent = " File is Empty::" + dataString + ";\n";
            }
            log.info(szFileContent + "\n File Sent Successfully:::" + file_Path);
            System.out.println(szFileContent + "\n File Sent Successfully:::" + file_Path);
            file = null;
            fos = null;
            Date date = new Date();
            log.info(" System Time:::::::::::::" + date.toString() + "\n");
            date = null;
            dataString = null;
        } catch (Exception e) {
            log.error("DashBoard SendFileToJson Writing into :" + file_Path + "\n" + e.getMessage());
            e.printStackTrace();

        } finally {
            dataString = null;
            file_Path = null;
        }


    }
/**
     * *************************************************************************************************
     * This method is sending JSON File Periodically to Specific defined Path.
     *
     * @param customer name of Directory, where all JSON file should be placed
     * @param timestampselection Inside customer directory different
     * sub-Directory of timestamp like (hour, day, week, month, year). Here
     * timestampselection is telling where all JSON file should be placed
     * **************************************************************************************************
     */
This method is sending JSON File Periodically to Specific defined Path.

@param customer name of Directory, where all JSON file should be placed
@param timestampselection Inside customer directory different
sub-Directory of timestamp like (hour, day, week, month, year). Here
timestampselection is telling where all JSON file should be placed
This method is sending JSON File Periodically to Specific defined Path . @param customer name of Directory where all JSON file should be placed @param timestampselection Inside customer directory different sub - Directory of timestamp like ( hour day week month year ) . Here timestampselection is telling where all JSON file should be placed
public void sendDataToFile(String timestampselection, String selection) {
        String szProjectName = DBUtilHelper.getMetrics_mapping_properties().getProperty("projectName");
        String tomcat_home = DBUtilHelper.dashBoardJSONPATH;
        String file_Path = "";
        String szDate = sdf.format(cal.getTime());
        System.out.println("currentTime in sendDataToFile=" + cal.toString());
        System.out.println("szDate in sendDataToFile=" + szDate);
        if (resourceType.equalsIgnoreCase("")) {
            /*this line replace with below if else block for watchdogalert.json to be saved under date directory
             * file_Path = tomcat_home + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
             */
            if (jsonFileName.equalsIgnoreCase("watchdogalert")) {
                file_Path = tomcat_home/*+ File.separator + "webapps"*/ + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate;
            } else {
                file_Path = tomcat_home/*+ File.separator + "webapps"*/ + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
            }
            if (cCustomer != null) {
                file_Path += File.separator + cCustomer;
            }
            if (service != null) {
                file_Path += File.separator + service;
            }
            file_Path += File.separator + jsonFileName + ".json";
        } else {
            if (selection.equalsIgnoreCase("")) {
                file_Path = tomcat_home + /*File.separator + "webapps" +*/ File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
                if (cCustomer != null) {
                    file_Path += File.separator + cCustomer;
                }
                if (service != null) {
                    file_Path += File.separator + service;
                }
                file_Path += File.separator + resourceType + File.separator + resourceType + jsonFileName + ".json";
            } else {
                file_Path = tomcat_home + /*File.separator + "webapps" +*/ File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
                if (cCustomer != null) {
                    file_Path += File.separator + cCustomer;
                }
                if (service != null) {
                    file_Path += File.separator + service;
                }
                file_Path += File.separator + resourceType + File.separator + selection + File.separator + resourceType
                        + jsonFileName + ".json";
            }
        }
        while (file_Path.contains(File.separator + File.separator)) {
            file_Path = file_Path.replaceAll(File.separator + File.separator, File.separator);
        }
        File file = new File(file_Path);
        if (file.exists()) {
            file.delete();
        }
        try {
            file.createNewFile();
        } catch (IOException ex) {
            ex.printStackTrace();
            log.error("Error in sendDataToFile" + ex.toString());
        }
        try {
            FileOutputStream fos = new FileOutputStream(file, false);
            fos.write(dataString.getBytes());
            fos.close();
            String szFileContent = "";
            if (dataString.length() < 5) {
                szFileContent = " File is Empty::" + dataString + ";\n";
            }
            log.info(szFileContent + "\n File Sent Successfully:::" + file_Path);
            System.out.println(szFileContent + "\n File Sent Successfully:::" + file_Path);
            file = null;
            fos = null;
            Date date = new Date();
            log.info(" System Time:::::::::::::" + date.toString() + "\n");
            date = null;
            dataString = null;
        } catch (Exception e) {
            log.error("DashBoard SendFileToJson Writing into :" + file_Path + "\n" + e.getMessage());
            e.printStackTrace();
        } finally {
            dataString = null;
            file_Path = null;
        }
    }
public void sendDataToFile ( String timestampselection , String selection ) { String szProjectName = DBUtilHelper . getMetrics_mapping_properties ( ) . getProperty ( "projectName" ) ; String tomcat_home = DBUtilHelper . dashBoardJSONPATH ; String file_Path = "" ; String szDate = sdf . format ( cal . getTime ( ) ) ; System . out . println ( "currentTime in sendDataToFile=" + cal . toString ( ) ) ; System . out . println ( "szDate in sendDataToFile=" + szDate ) ; if ( resourceType . equalsIgnoreCase ( "" ) ) { /*this line replace with below if else block for watchdogalert.json to be saved under date directory
             * file_Path = tomcat_home + File.separator + szProjectName + File.separator + customer
                        + File.separator + szDate + File.separator + timestampselection;
             */ if ( jsonFileName . equalsIgnoreCase ( "watchdogalert" ) ) { file_Path = tomcat_home /*+ File.separator + "webapps"*/ + File . separator + szProjectName + File . separator + customer + File . separator + szDate ; } else { file_Path = tomcat_home /*+ File.separator + "webapps"*/ + File . separator + szProjectName + File . separator + customer + File . separator + szDate + File . separator + timestampselection ; } if ( cCustomer != null ) { file_Path += File . separator + cCustomer ; } if ( service != null ) { file_Path += File . separator + service ; } file_Path += File . separator + jsonFileName + ".json" ; } else { if ( selection . equalsIgnoreCase ( "" ) ) { file_Path = tomcat_home + /*File.separator + "webapps" +*/ File . separator + szProjectName + File . separator + customer + File . separator + szDate + File . separator + timestampselection ; if ( cCustomer != null ) { file_Path += File . separator + cCustomer ; } if ( service != null ) { file_Path += File . separator + service ; } file_Path += File . separator + resourceType + File . separator + resourceType + jsonFileName + ".json" ; } else { file_Path = tomcat_home + /*File.separator + "webapps" +*/ File . separator + szProjectName + File . separator + customer + File . separator + szDate + File . separator + timestampselection ; if ( cCustomer != null ) { file_Path += File . separator + cCustomer ; } if ( service != null ) { file_Path += File . separator + service ; } file_Path += File . separator + resourceType + File . separator + selection + File . separator + resourceType + jsonFileName + ".json" ; } } while ( file_Path . contains ( File . separator + File . separator ) ) { file_Path = file_Path . replaceAll ( File . separator + File . separator , File . separator ) ; } File file = new File ( file_Path ) ; if ( file . exists ( ) ) { file . delete ( ) ; } try { file . createNewFile ( ) ; } catch ( IOException ex ) { ex . printStackTrace ( ) ; log . error ( "Error in sendDataToFile" + ex . toString ( ) ) ; } try { FileOutputStream fos = new FileOutputStream ( file , false ) ; fos . write ( dataString . getBytes ( ) ) ; fos . close ( ) ; String szFileContent = "" ; if ( dataString . length ( ) < 5 ) { szFileContent = " File is Empty::" + dataString + ";\n" ; } log . info ( szFileContent + "\n File Sent Successfully:::" + file_Path ) ; System . out . println ( szFileContent + "\n File Sent Successfully:::" + file_Path ) ; file = null ; fos = null ; Date date = new Date ( ) ; log . info ( " System Time:::::::::::::" + date . toString ( ) + "\n" ) ; date = null ; dataString = null ; } catch ( Exception e ) { log . error ( "DashBoard SendFileToJson Writing into :" + file_Path + "\n" + e . getMessage ( ) ) ; e . printStackTrace ( ) ; } finally { dataString = null ; file_Path = null ; } }
This method is sending JSON File Periodically to Specific defined Path.
This method is sending JSON File Periodically to Specific defined Path .
//String tomcat_home = System.getProperty("catalina.base"); //file_Path = tomcat_home + File.separator + "webapps" + File.separator + szProjectName + File.separator + customer + File.separator + timestampselection + File.separator + jsonFileName + ".json"; //file_Path = tomcat_home + File.separator + "webapps" + File.separator + szProjectName + File.separator + customer + File.separator + timestampselection + File.separator + resourceType + File.separator + resourceType + jsonFileName + ".json"; //file_Path = tomcat_home + File.separator + "webapps" + File.separator + szProjectName + File.separator + customer + File.separator + timestampselection + File.separator + resourceType + File.separator + selection + File.separator + resourceType + jsonFileName + ".json";