Subversion Repositories SmartDukaan

Rev

Rev 5140 | Rev 6322 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5128 amit.gupta 1
package in.shop2020.catalog.util;
2
 
3
import in.shop2020.utils.GmailUtils;
5181 amit.gupta 4
import in.shop2020.utils.Utils;
5128 amit.gupta 5
 
6
import java.io.ByteArrayOutputStream;
5140 amit.gupta 7
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
9
import java.io.IOException;
5128 amit.gupta 10
import java.text.DateFormat;
11
import java.text.SimpleDateFormat;
12
import java.util.Date;
13
 
14
 
5181 amit.gupta 15
 
5128 amit.gupta 16
public class ReportSender implements Runnable {
5181 amit.gupta 17
	static String EXPORT_PATH  = "/var/lib/tomcat6/webapps/export/";
5128 amit.gupta 18
	@Override
19
	public void run() {
20
		ReportGenerator repGen = new ReportGenerator();
21
		ByteArrayOutputStream baos = repGen.generateExcelStream(ReportGenerator.TYPE_BOTH);
22
		if(baos != null){
23
			GmailUtils gm = new GmailUtils();
24
			DateFormat dateFormatter = new SimpleDateFormat("yyyy.MM.dd");
5140 amit.gupta 25
			String[] recepients = {"cnc.center@shop2020.in", "ashutosh.saxena@shop2020.in", "chaitnaya.vats@shop2020.in"};
5128 amit.gupta 26
			String subject = "Items that require your attention.";
27
			String from = "cnc.center@shop2020.in";
28
			String password = "5h0p2o2o";
29
			String fileName = "items."+ dateFormatter.format(new Date()) + ".xls";
5140 amit.gupta 30
			byte [] bytes = baos.toByteArray();
31
 
32
		     try
33
		     {
5181 amit.gupta 34
		      FileOutputStream fos = new FileOutputStream(EXPORT_PATH + fileName);
5140 amit.gupta 35
 
36
		      /*
37
		       * To write byte array to a file, use
38
		       * void write(byte[] bArray) method of Java FileOutputStream class.
39
		       *
40
		       * This method writes given byte array to a file.
41
		       */
42
 
43
		       fos.write(bytes);
44
 
45
		      /*
46
		       * Close FileOutputStream using,
47
		       * void close() method of Java FileOutputStream class.
48
		       *
49
		       */
50
 
51
		       fos.close();
52
 
53
		     }
54
		     catch(FileNotFoundException ex)
55
		     {
56
		      System.out.println("FileNotFoundException : " + ex);
57
		     }
58
		     catch(IOException ioe)
59
		     {
60
		      System.out.println("IOException : " + ioe);
61
		     }
62
 
5128 amit.gupta 63
			try {
5181 amit.gupta 64
				gm.sendSSLMessage(recepients, subject, "PFA", from, password, EXPORT_PATH + fileName);
5128 amit.gupta 65
			} catch (Exception e) {
66
				e.printStackTrace();
67
			}
68
		}
69
	}
70
}