Subversion Repositories SmartDukaan

Rev

Rev 1600 | Rev 2145 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1600 Rev 1876
Line 9... Line 9...
9
import in.shop2020.model.v1.order.LineItem;
9
import in.shop2020.model.v1.order.LineItem;
10
import in.shop2020.model.v1.order.Order;
10
import in.shop2020.model.v1.order.Order;
11
import in.shop2020.model.v1.order.OrderStatus;
11
import in.shop2020.model.v1.order.OrderStatus;
12
import in.shop2020.model.v1.user.UserContextException;
12
import in.shop2020.model.v1.user.UserContextException;
13
import in.shop2020.model.v1.user.UserContextService;
13
import in.shop2020.model.v1.user.UserContextService;
-
 
14
import in.shop2020.model.v1.user.UserCommunicationType;
14
import in.shop2020.serving.controllers.BaseController;
15
import in.shop2020.serving.controllers.BaseController;
15
import in.shop2020.thrift.clients.HelperServiceClient;
16
import in.shop2020.thrift.clients.HelperServiceClient;
16
import in.shop2020.thrift.clients.TransactionServiceClient;
17
import in.shop2020.thrift.clients.TransactionServiceClient;
17
import in.shop2020.thrift.clients.UserContextServiceClient;
18
import in.shop2020.thrift.clients.UserContextServiceClient;
18
import in.shop2020.serving.utils.UserMessage;
19
import in.shop2020.serving.utils.UserMessage;
Line 24... Line 25...
24
 
25
 
25
/**
26
/**
26
 * @author Varun Gupta
27
 * @author Varun Gupta
27
 */
28
 */
28
 
29
 
29
public class ContactUsController extends BaseController{
30
public class ContactUsController extends BaseController {
30
 
31
 
31
	private String id;
32
    private String id;
32
	private static final long serialVersionUID = 1L;
33
    private static final long serialVersionUID = 1L;
33
	private static Logger log = Logger.getLogger(Class.class);
34
    private static Logger log = Logger.getLogger(Class.class);
-
 
35
 
-
 
36
    private UserCommunicationType formType = null;
-
 
37
 
34
	List<Order> orders = null;
38
    List<Order> orders = null;
35
	List<LineItem> products = null;
39
    List<LineItem> products = null;
36
	List<Long> order_ids = null;
40
    List<Long> order_ids = null;
37
	
41
 
38
	public ContactUsController(){
42
    public ContactUsController() {
39
		super();
43
        super();
40
	}
44
    }
41
	
45
 
42
	// GET /Show Form
46
    // GET /Show Form
43
	public String index() {
47
    public String index() {
44
		try	{
48
        try {
45
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
49
            TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
46
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
50
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
47
			orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
51
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
48
		}
-
 
49
		catch(Exception e)	{
52
        } catch (Exception e) {
50
			e.printStackTrace();
53
            e.printStackTrace();
-
 
54
        }
-
 
55
 
-
 
56
        if (request.getParameter("type") != null) {
-
 
57
            String requestedFormType = request.getParameter("type").toString().trim();
51
		}
58
 
-
 
59
            if (requestedFormType.equals("return")) {
-
 
60
                this.formType = UserCommunicationType.RETURN_FORM;
-
 
61
            } else if (requestedFormType.equals("cancel")) {
-
 
62
                this.formType = UserCommunicationType.ORDER_CANCELLATION;
-
 
63
            } else if (requestedFormType.equals("delivery")) {
-
 
64
                this.formType = UserCommunicationType.DELIVERY_PROBLEM;
-
 
65
            }
-
 
66
        }
52
		return "index";
67
        return "index";
53
	}
68
    }
54
 
69
 
55
	public String show() throws SecurityException, IOException	{
70
    public String show() throws SecurityException, IOException {
56
		try	{
71
        try {
57
			TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
72
            TransactionServiceClient transactionServiceClient = new TransactionServiceClient();
58
			in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
73
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
59
 
74
 
60
			if (id.equals("to_return"))	{
75
            if (id.equals("to_return")) {
61
				order_ids = orderClient.getReturnableOrdersForCustomer(userinfo.getUserId(), 0);
76
                order_ids = orderClient.getReturnableOrdersForCustomer(userinfo.getUserId(), 0);
62
			}
-
 
63
			else if (id.equals("to_cancel"))	{
77
            } else if (id.equals("to_cancel")) {
64
				order_ids = orderClient.getCancellableOrdersForCustomer(userinfo.getUserId(), 0);
78
                order_ids = orderClient.getCancellableOrdersForCustomer(userinfo.getUserId(), 0);
65
			}
-
 
66
			else if (id.equals("all_orders"))	{
79
            } else if (id.equals("all_orders")) {
67
				orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
80
                orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
68
			}
-
 
69
			else	{
81
            } else {
70
				long orderId = Integer.parseInt(id);
82
                long orderId = Integer.parseInt(id);
71
				products = orderClient.getLineItemsForOrder(orderId);
83
                products = orderClient.getLineItemsForOrder(orderId);
72
			}
84
            }
73
		}
-
 
74
		catch (NumberFormatException e)	{
85
        } catch (NumberFormatException e) {
75
			e.printStackTrace();
86
            e.printStackTrace();
76
		}
-
 
77
		catch (Exception e) {
87
        } catch (Exception e) {
78
			e.printStackTrace();
88
            e.printStackTrace();
79
		}
89
        }
80
		return "ajax";
90
        return "ajax";
81
	}
91
    }
82
	
92
 
83
	// POST /Save Communication
93
    // POST /Save Communication
84
	public String create() {
94
    public String create() {
85
		long communicationType = -1;
95
        long communicationType = -1;
86
		long orderId = -1;
96
        long orderId = -1;
87
 
97
 
88
		try	{
98
        try {
89
			boolean u = userinfo.isLoggedIn();
99
            boolean u = userinfo.isLoggedIn();
90
			long userId = u ? userinfo.getUserId() : 0;
100
            long userId = u ? userinfo.getUserId() : 0;
91
			String email = request.getParameter("email");
101
            String email = request.getParameter("email");
92
			communicationType = Integer.parseInt(request.getParameter("communication_type"));
102
            communicationType = Integer.parseInt(request.getParameter("communication_type"));
93
			
103
 
94
			if(request.getParameter("order_id") != null)	{
104
            if (request.getParameter("order_id") != null) {
95
				orderId = Integer.parseInt(request.getParameter("order_id"));
105
                orderId = Integer.parseInt(request.getParameter("order_id"));
96
			}
106
            }
97
			String awb = request.getParameter("awb");
107
            String awb = request.getParameter("awb");
98
			String product = request.getParameter("product");
108
            String product = request.getParameter("product");
99
			String subject = request.getParameter("subject");
109
            String subject = request.getParameter("subject");
100
			String message = request.getParameter("message");
110
            String message = request.getParameter("message");
101
 
111
 
102
			UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
112
            UserContextService.Client userClient = (new UserContextServiceClient()).getClient();
103
 
113
 
104
 			if(userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject, message))	{
114
            if (userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject,
-
 
115
                    message)) {
105
				System.out.println("User Communication saved successfully!");
116
                System.out.println("User Communication saved successfully!");
106
			}
117
            }
107
		
118
 
108
		} catch(NumberFormatException e)	{
119
        } catch (NumberFormatException e) {
109
			e.printStackTrace();
120
            e.printStackTrace();
110
		} catch (UserContextException e) {
121
        } catch (UserContextException e) {
111
			e.printStackTrace();
122
            e.printStackTrace();
112
		} catch (Exception e) {
123
        } catch (Exception e) {
113
			e.printStackTrace();
124
            e.printStackTrace();
114
		} finally	{
125
        } finally {
115
		
126
 
116
		}
127
        }
117
		return "success";
128
        return "success";
118
	}
129
    }
119
	
130
 
120
	public String getId()	{
131
    public String getId() {
121
		return this.id;
132
        return this.id;
122
	}
133
    }
123
	
134
 
124
	/**
135
    /**
125
     * @param id
136
     * @param id
126
     */
137
     */
127
    public void setId(String id) {
138
    public void setId(String id) {
128
    	this.id = id;
139
        this.id = id;
-
 
140
    }
-
 
141
 
-
 
142
    public UserCommunicationType getFormType() {
-
 
143
        return this.formType;
-
 
144
    }
-
 
145
 
-
 
146
    public String getSuccessMsg() {
-
 
147
        return UserMessage.USER_COMMUNICATION_SUCCESS;
-
 
148
    }
-
 
149
 
-
 
150
    private String getOrderIdSelector(List<Long> order_ids) {
-
 
151
        String html = "";
-
 
152
 
-
 
153
        if (order_ids == null || order_ids.size() == 0) {
-
 
154
            html += "<option value='-1'>No Orders Found</option>";
-
 
155
        } else {
-
 
156
            html += "<option value='-1'>Select Order ID</option>";
-
 
157
 
-
 
158
            for (long order_id : order_ids) {
-
 
159
                html += "<option value='" + order_id + "'>" + order_id + "</option>";
-
 
160
            }
-
 
161
        }
-
 
162
        return html;
-
 
163
    }
-
 
164
 
-
 
165
    public String getProductsForOrder() {
-
 
166
        String html = "";
-
 
167
 
-
 
168
        if (products == null || products.size() == 0) {
-
 
169
            html += "<option value='-1'>No Products Found</option>";
-
 
170
        } else {
-
 
171
            for (LineItem product : products) {
-
 
172
                html += "<option value='" + product.getId() + "'>";
-
 
173
 
-
 
174
                if (product.getBrand() != null)
-
 
175
                    html += product.getBrand() + " ";
-
 
176
                if (product.getModel_name() != null)
-
 
177
                    html += product.getModel_name() + " ";
-
 
178
                if (product.getModel_number() != null)
-
 
179
                    html += product.getModel_number();
-
 
180
 
-
 
181
                html += "</option>";
-
 
182
            }
-
 
183
        }
-
 
184
        return html;
-
 
185
    }
-
 
186
 
-
 
187
    public String getIdsOfAllOrders() {
-
 
188
        List<Long> order_ids = new ArrayList<Long>();
-
 
189
 
-
 
190
        for (Order order : this.orders) {
-
 
191
            order_ids.add(order.getId());
-
 
192
        }
-
 
193
        return getOrderIdSelector(order_ids);
-
 
194
    }
-
 
195
 
-
 
196
    public String getIdsOfReturnableOrders() {
-
 
197
        return getOrderIdSelector(this.order_ids);
-
 
198
    }
-
 
199
 
-
 
200
    public String getIdsOfCancellableOrders() {
-
 
201
        return getOrderIdSelector(this.order_ids);
129
    }
202
    }
130
    
-
 
131
	public String getSuccessMsg() {
-
 
132
		return UserMessage.USER_COMMUNICATION_SUCCESS;
-
 
133
	}
-
 
134
 
-
 
135
	private String getOrderIdSelector(List<Long> order_ids)	{
-
 
136
		String html = "";
-
 
137
		
-
 
138
		if (order_ids == null || order_ids.size() == 0)	{
-
 
139
			html += "<option value='-1'>No Orders Found</option>";
-
 
140
		} else	{
-
 
141
			html += "<option value='-1'>Select Order ID</option>";
-
 
142
 
-
 
143
			for(long order_id: order_ids)	{
-
 
144
				html += "<option value='" + order_id + "'>" + order_id + "</option>";
-
 
145
			}
-
 
146
		}
-
 
147
		return html;
-
 
148
	}
-
 
149
	
-
 
150
	public String getProductsForOrder()	{
-
 
151
		String html = "";
-
 
152
		
-
 
153
		if(products == null || products.size() == 0)	{
-
 
154
			html += "<option value='-1'>No Products Found</option>";
-
 
155
		} else	{
-
 
156
			for (LineItem product: products)	{
-
 
157
				html += "<option value='" + product.getId() + "'>";
-
 
158
				
-
 
159
				if(product.getBrand() != null)	html += product.getBrand() + " ";
-
 
160
				if(product.getModel_name() != null)	html += product.getModel_name() + " ";
-
 
161
				if(product.getModel_number() != null)	html += product.getModel_number();
-
 
162
				
-
 
163
				html += "</option>";
-
 
164
			}
-
 
165
		}
-
 
166
		return html;
-
 
167
	}
-
 
168
	
-
 
169
	public String getIdsOfAllOrders()	{
-
 
170
		List<Long> order_ids = new ArrayList<Long>();
-
 
171
		
-
 
172
		for(Order order: this.orders)	{
-
 
173
			order_ids.add(order.getId());
-
 
174
		}
-
 
175
		return getOrderIdSelector(order_ids); 
-
 
176
	}
-
 
177
	
-
 
178
	public String getIdsOfReturnableOrders()	{
-
 
179
		return getOrderIdSelector(this.order_ids);
-
 
180
	}
-
 
181
	
-
 
182
	public String getIdsOfCancellableOrders()	{
-
 
183
		return getOrderIdSelector(this.order_ids);
-
 
184
	}
-
 
185
}
203
}
186
204