Subversion Repositories SmartDukaan

Rev

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