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;
901 rajveer 25
	/*	
894 rajveer 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
	}
901 rajveer 34
	*/
569 rajveer 35
		public SendMailController(){
36
			super();	
37
		}
38
 
39
		 // GET /Send Mail
40
		 public HttpHeaders index() {		
41
 
42
	    	return new DefaultHttpHeaders("index").disableCaching();
43
		 }
44
 
45
		// POST /Send Mail
46
		public String create() {
47
	    	log.info("SendMailController.create");
48
	    	Mail mail = new Mail();
49
	    	List<String> mailTo = new ArrayList<String>();
50
 
627 rajveer 51
	    	this.userMailId = request.getParameter("mailFrom");
52
	    	String mailSubject = request.getParameter("mailSubject");
53
	    	String mailBody = request.getParameter("mailBody");
569 rajveer 54
	    	mailTo.add(customerCareMailId);
55
 
56
	    	mail.setSubject(mailSubject);
57
	    	mail.setSender(userMailId);
58
	    	mail.setTo(mailTo);
59
	    	mail.setData(mailBody);
60
 
61
	    	HelperServiceClient helperServiceClient;
62
	    	try {
63
				helperServiceClient = new HelperServiceClient();
64
				helperServiceClient.getClient().sendMail(mail);
65
			} catch (Exception e) {
66
				log.error("Helper service not working properly. Error while sending mail to user.");
67
				e.printStackTrace();
68
			}
69
 
70
	    	return "success";
71
	    }
72
 
73
		public String getCustomerCareMailId() {
74
			return customerCareMailId;
75
		}
76
 
77
		public String getUserMailId() {
78
			return userMailId;
79
		}
80
 
81
}