Subversion Repositories SmartDukaan

Rev

Rev 1380 | Rev 1600 | 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;
1380 varun.gupt 4
import java.lang.NumberFormatException;
569 rajveer 5
import java.util.ArrayList;
1297 varun.gupt 6
import java.util.Date;
569 rajveer 7
import java.util.List;
8
 
1297 varun.gupt 9
import in.shop2020.model.v1.order.LineItem;
10
import in.shop2020.model.v1.order.Order;
1380 varun.gupt 11
import in.shop2020.model.v1.order.OrderStatus;
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;
1380 varun.gupt 36
	List<Long> order_ids = null;
1297 varun.gupt 37
 
1170 varun.gupt 38
	public ContactUsController(){
1297 varun.gupt 39
		super();
1170 varun.gupt 40
	}
1297 varun.gupt 41
 
1170 varun.gupt 42
	// GET /Show Form
1297 varun.gupt 43
	public String index() {
44
		try	{
45
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
46
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
47
			orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
1481 varun.gupt 48
		}
49
		catch(Exception e)	{
1297 varun.gupt 50
			e.printStackTrace();
51
		}
52
		return "index";
1170 varun.gupt 53
	}
54
 
1297 varun.gupt 55
	public String show() throws SecurityException, IOException	{
56
		try	{
57
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
58
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
1380 varun.gupt 59
 
60
			if (id.equals("to_return"))	{
61
				order_ids = orderClient.getReturnableOrdersForCustomer(userinfo.getUserId(), 0);
62
			}
63
			else if (id.equals("to_cancel"))	{
64
				order_ids = orderClient.getCancellableOrdersForCustomer(userinfo.getUserId(), 0);
65
			}
66
			else if (id.equals("all_orders"))	{
67
				orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
68
			}
69
			else	{
70
				long orderId = Integer.parseInt(id);
71
				products = orderClient.getLineItemsForOrder(orderId);
72
			}
1297 varun.gupt 73
		}
1380 varun.gupt 74
		catch (NumberFormatException e)	{
75
			e.printStackTrace();
76
		}
1297 varun.gupt 77
		catch (Exception e) {
78
			e.printStackTrace();
79
		}
80
		return "ajax";
81
	}
82
 
1170 varun.gupt 83
	// POST /Save Communication
84
	public String create() {
85
		long communicationType = -1;
86
		long orderId = -1;
87
 
88
		try	{
89
			boolean u = userinfo.isLoggedIn();
90
			long userId = u ? userinfo.getUserId() : 0;
91
			String email = request.getParameter("email");
92
			communicationType = Integer.parseInt(request.getParameter("communication_type"));
93
			orderId = Integer.parseInt(request.getParameter("order_id"));
94
			String awb = request.getParameter("awb");
95
			String product = request.getParameter("product");
96
			String subject = request.getParameter("subject");
97
			String message = request.getParameter("message");
98
 
99
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
100
 
101
 			if(userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject, message))	{
102
				System.out.println("User Communication saved successfully!");
103
			}
104
 
105
		} catch(NumberFormatException e)	{
106
			e.printStackTrace();
107
		} catch (UserContextException e) {
108
			e.printStackTrace();
109
		} catch (Exception e) {
110
			e.printStackTrace();
111
		} finally	{
112
 
569 rajveer 113
		}
1380 varun.gupt 114
		return "success";
115
	}
116
 
117
	public String getId()	{
118
		return this.id;
119
	}
120
 
1297 varun.gupt 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
 
1380 varun.gupt 132
	private String getOrderIdSelector(List<Long> order_ids)	{
1297 varun.gupt 133
		String html = "";
134
 
1380 varun.gupt 135
		if (order_ids == null || order_ids.size() == 0)	{
1297 varun.gupt 136
			html += "<option value='-1'>No Orders Found</option>";
137
		} else	{
138
			html += "<option value='-1'>Select Order ID</option>";
139
 
1380 varun.gupt 140
			for(long order_id: order_ids)	{
141
				html += "<option value='" + order_id + "'>" + order_id + "</option>";
1297 varun.gupt 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
	}
1380 varun.gupt 165
 
166
	public String getIdsOfAllOrders()	{
167
		List<Long> order_ids = new ArrayList<Long>();
168
 
169
		for(Order order: this.orders)	{
170
			order_ids.add(order.getId());
171
		}
172
		return getOrderIdSelector(order_ids); 
173
	}
174
 
175
	public String getIdsOfReturnableOrders()	{
176
		return getOrderIdSelector(this.order_ids);
177
	}
178
 
179
	public String getIdsOfCancellableOrders()	{
180
		return getOrderIdSelector(this.order_ids);
181
	}
569 rajveer 182
}