Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
569 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Map;
6
 
894 rajveer 7
import in.shop2020.config.ConfigException;
569 rajveer 8
import in.shop2020.serving.controllers.BaseController;
9
import in.shop2020.thrift.clients.HelperServiceClient;
894 rajveer 10
import in.shop2020.thrift.clients.config.ConfigClient;
569 rajveer 11
import in.shop2020.utils.Mail;
12
 
13
import org.apache.juli.logging.Log;
14
import org.apache.juli.logging.LogFactory;
832 rajveer 15
import org.apache.log4j.Logger;
569 rajveer 16
import org.apache.struts2.rest.DefaultHttpHeaders;
17
import org.apache.struts2.rest.HttpHeaders;
18
 
19
public class SendMailController extends BaseController{
20
 
21
	private static final long serialVersionUID = 1L;
832 rajveer 22
	private static Logger log = Logger.getLogger(Class.class);
894 rajveer 23
	private static String customerCareMailId = "help@saholic.com";
569 rajveer 24
	private String userMailId;
894 rajveer 25
 
26
	static {
27
		try {
28
			customerCareMailId = ConfigClient.getClient().get("saholic_customer_care_mail");
29
		} catch (ConfigException e) {
30
			customerCareMailId = "help@saholic.com";
31
			e.printStackTrace();
32
		}
33
	}
569 rajveer 34
		public SendMailController(){
35
			super();	
36
		}
37
 
38
		 // GET /Send Mail
39
		 public HttpHeaders index() {		
40
 
41
	    	return new DefaultHttpHeaders("index").disableCaching();
42
		 }
43
 
44
		// POST /Send Mail
45
		public String create() {
46
	    	log.info("SendMailController.create");
47
	    	Mail mail = new Mail();
48
	    	List<String> mailTo = new ArrayList<String>();
49
 
627 rajveer 50
	    	this.userMailId = request.getParameter("mailFrom");
51
	    	String mailSubject = request.getParameter("mailSubject");
52
	    	String mailBody = request.getParameter("mailBody");
569 rajveer 53
	    	mailTo.add(customerCareMailId);
54
 
55
	    	mail.setSubject(mailSubject);
56
	    	mail.setSender(userMailId);
57
	    	mail.setTo(mailTo);
58
	    	mail.setData(mailBody);
59
 
60
	    	HelperServiceClient helperServiceClient;
61
	    	try {
62
				helperServiceClient = new HelperServiceClient();
63
				helperServiceClient.getClient().sendMail(mail);
64
			} catch (Exception e) {
65
				log.error("Helper service not working properly. Error while sending mail to user.");
66
				e.printStackTrace();
67
			}
68
 
69
	    	return "success";
70
	    }
71
 
72
		public String getCustomerCareMailId() {
73
			return customerCareMailId;
74
		}
75
 
76
		public String getUserMailId() {
77
			return userMailId;
78
		}
79
 
80
}