Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
569 rajveer 1
package in.shop2020.serving.controllers;
2
 
1297 varun.gupt 3
import java.io.IOException;
1170 varun.gupt 4
import java.text.ParseException;
569 rajveer 5
import java.util.ArrayList;
1297 varun.gupt 6
import java.util.Date;
569 rajveer 7
import java.util.List;
1297 varun.gupt 8
import java.util.StringTokenizer;
569 rajveer 9
 
1297 varun.gupt 10
import in.shop2020.model.v1.order.LineItem;
11
import in.shop2020.model.v1.order.Order;
1170 varun.gupt 12
import in.shop2020.model.v1.user.UserContextException;
13
import in.shop2020.model.v1.user.UserContextService;
569 rajveer 14
import in.shop2020.serving.controllers.BaseController;
15
import in.shop2020.thrift.clients.HelperServiceClient;
1297 varun.gupt 16
import in.shop2020.thrift.clients.TransactionServiceClient;
1170 varun.gupt 17
import in.shop2020.thrift.clients.UserContextServiceClient;
18
import in.shop2020.serving.utils.UserMessage;
569 rajveer 19
 
832 rajveer 20
import org.apache.log4j.Logger;
569 rajveer 21
import org.apache.struts2.rest.DefaultHttpHeaders;
22
import org.apache.struts2.rest.HttpHeaders;
1297 varun.gupt 23
import org.apache.velocity.VelocityContext;
569 rajveer 24
 
980 vikas 25
public class ContactUsController extends BaseController{
1297 varun.gupt 26
 
27
	private String id;
569 rajveer 28
	private static final long serialVersionUID = 1L;
832 rajveer 29
	private static Logger log = Logger.getLogger(Class.class);
1297 varun.gupt 30
	List<Order> orders = null;
31
	List<LineItem> products = null;
32
 
1170 varun.gupt 33
	public ContactUsController(){
1297 varun.gupt 34
		super();
1170 varun.gupt 35
	}
1297 varun.gupt 36
 
1170 varun.gupt 37
	// GET /Show Form
1297 varun.gupt 38
	public String index() {
39
		try	{
40
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
41
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
42
			orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
43
 
44
		} catch(Exception e)	{
45
			e.printStackTrace();
46
		}
47
		return "index";
1170 varun.gupt 48
	}
49
 
1297 varun.gupt 50
	public String show() throws SecurityException, IOException	{
51
		try	{
52
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
53
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
54
 
55
			long orderId = Integer.parseInt(id);
56
			products = orderClient.getLineItemsForOrder(orderId);
57
		}
58
		catch (Exception e) {
59
			e.printStackTrace();
60
		}
61
		return "ajax";
62
	}
63
 
1170 varun.gupt 64
	// POST /Save Communication
65
	public String create() {
66
		long communicationType = -1;
67
		long orderId = -1;
68
 
69
		try	{
70
			boolean u = userinfo.isLoggedIn();
71
			long userId = u ? userinfo.getUserId() : 0;
72
			String email = request.getParameter("email");
73
			communicationType = Integer.parseInt(request.getParameter("communication_type"));
74
			orderId = Integer.parseInt(request.getParameter("order_id"));
75
			String awb = request.getParameter("awb");
76
			String product = request.getParameter("product");
77
			String subject = request.getParameter("subject");
78
			String message = request.getParameter("message");
79
 
80
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
81
 
82
 			if(userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject, message))	{
83
				System.out.println("User Communication saved successfully!");
84
			}
85
 
86
		} catch(NumberFormatException e)	{
87
			e.printStackTrace();
88
		} catch (UserContextException e) {
89
			e.printStackTrace();
90
		} catch (Exception e) {
91
			e.printStackTrace();
92
		} finally	{
93
 
569 rajveer 94
		}
95
 
1170 varun.gupt 96
/*	    	Mail mail = new Mail();
569 rajveer 97
	    	List<String> mailTo = new ArrayList<String>();
98
 
627 rajveer 99
	    	this.userMailId = request.getParameter("mailFrom");
100
	    	String mailSubject = request.getParameter("mailSubject");
101
	    	String mailBody = request.getParameter("mailBody");
569 rajveer 102
	    	mailTo.add(customerCareMailId);
103
 
104
	    	mail.setSubject(mailSubject);
105
	    	mail.setSender(userMailId);
106
	    	mail.setTo(mailTo);
107
	    	mail.setData(mailBody);
108
 
109
	    	HelperServiceClient helperServiceClient;
110
	    	try {
111
				helperServiceClient = new HelperServiceClient();
112
				helperServiceClient.getClient().sendMail(mail);
113
			} catch (Exception e) {
114
				log.error("Helper service not working properly. Error while sending mail to user.");
115
				e.printStackTrace();
1170 varun.gupt 116
			}*/
569 rajveer 117
 
118
	    	return "success";
119
	    }
1297 varun.gupt 120
	/**
121
     * 
122
     * @param id
123
     */
124
    public void setId(String id) {
125
    	this.id = id;
126
    }
127
 
128
	public String getSuccessMsg() {
129
		return UserMessage.USER_COMMUNICATION_SUCCESS;
130
	}
569 rajveer 131
 
1297 varun.gupt 132
	public String getOrderIdSelector()	{
133
		String html = "";
134
 
135
		if (orders == null || orders.size() == 0)	{
136
			html += "<option value='-1'>No Orders Found</option>";
137
		} else	{
138
			html += "<option value='-1'>Select Order ID</option>";
139
 
140
			for(Order order: orders)	{
141
				html += "<option value='" + order.getId() + "'>" + order.getId() + "</option>";
142
			}
569 rajveer 143
		}
1297 varun.gupt 144
		return html;
145
	}
146
 
147
	public String getProductsForOrder()	{
148
		String html = "";
149
 
150
		if(products == null || products.size() == 0)	{
151
			html += "<option value='-1'>No Products Found</option>";
152
		} else	{
153
			for (LineItem product: products)	{
154
				html += "<option value='" + product.getId() + "'>";
155
 
156
				if(product.getBrand() != null)	html += product.getBrand() + " ";
157
				if(product.getModel_name() != null)	html += product.getModel_name() + " ";
158
				if(product.getModel_number() != null)	html += product.getModel_number();
159
 
160
				html += "</option>";
161
			}
162
		}
163
		return html;
164
	}
569 rajveer 165
}