Subversion Repositories SmartDukaan

Rev

Rev 7291 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.catalog.util;

import in.shop2020.utils.GmailUtils;
import in.shop2020.utils.Utils;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;



public class ReportSender implements Runnable {
        static String EXPORT_PATH  = "/var/lib/tomcat6/webapps/export/";
        @Override
        public void run() {
                ReportGenerator repGen = new ReportGenerator();
                ByteArrayOutputStream baos = repGen.generateExcelStream(ReportGenerator.TYPE_BOTH);
                if(baos != null){
                        GmailUtils gm = new GmailUtils();
                        DateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd");
                        String[] recepients = {"cnc.center@shop2020.in", "manish.sharma@shop2020.in", "chandan.kumar@shop2020.in", "khushal.bhatia@shop2020.in", "chaitnaya.vats@shop2020.in"};
                        String subject = "Items that require your attention.";
                        String from = "cnc.center@shop2020.in";
                        String password = "5h0p2o2o";
                        String fileName = "items."+ dateFormatter.format(new Date()) + ".xls";
                        byte [] bytes = baos.toByteArray();
                           
                     try
                     {
                      FileOutputStream fos = new FileOutputStream(EXPORT_PATH + fileName);
                         
                      /*
                       * To write byte array to a file, use
                       * void write(byte[] bArray) method of Java FileOutputStream class.
                       *
                       * This method writes given byte array to a file.
                       */
                     
                       fos.write(bytes);
                     
                      /*
                       * Close FileOutputStream using,
                       * void close() method of Java FileOutputStream class.
                       *
                       */
                     
                       fos.close();
                     
                     }
                     catch(FileNotFoundException ex)
                     {
                      System.out.println("FileNotFoundException : " + ex);
                     }
                     catch(IOException ioe)
                     {
                      System.out.println("IOException : " + ioe);
                     }

//                      try {
//                              gm.sendSSLMessage(recepients, subject, "PFA", from, password, EXPORT_PATH + fileName);
//                      } catch (Exception e) {
//                              e.printStackTrace();
//                      }
                }
        }
}