Subversion Repositories SmartDukaan

Rev

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

Rev 3126 Rev 3272
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
3
import java.io.IOException;
3
import in.shop2020.crm.Activity;
-
 
4
import in.shop2020.crm.ActivityType;
4
import java.lang.NumberFormatException;
5
import in.shop2020.crm.CRMService.Client;
5
import java.util.ArrayList;
6
import in.shop2020.crm.Ticket;
6
import java.util.Date;
7
import in.shop2020.crm.TicketCategory;
-
 
8
import in.shop2020.crm.TicketPriority;
7
import java.util.List;
9
import in.shop2020.crm.TicketStatus;
8
 
-
 
9
import in.shop2020.model.v1.order.LineItem;
10
import in.shop2020.model.v1.order.LineItem;
10
import in.shop2020.model.v1.order.Order;
11
import in.shop2020.model.v1.order.Order;
-
 
12
import in.shop2020.model.v1.user.User;
11
import in.shop2020.model.v1.user.UserCommunicationException;
13
import in.shop2020.model.v1.user.UserCommunicationException;
12
import in.shop2020.model.v1.user.UserContextService;
-
 
13
import in.shop2020.model.v1.user.UserCommunicationType;
14
import in.shop2020.model.v1.user.UserCommunicationType;
-
 
15
import in.shop2020.model.v1.user.UserContextException;
-
 
16
import in.shop2020.model.v1.user.UserContextService;
14
import in.shop2020.serving.controllers.BaseController;
17
import in.shop2020.serving.utils.UserMessage;
-
 
18
import in.shop2020.thrift.clients.CRMClient;
15
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.TransactionClient;
16
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.thrift.clients.UserClient;
-
 
21
 
-
 
22
import java.io.IOException;
17
import in.shop2020.serving.utils.UserMessage;
23
import java.util.ArrayList;
-
 
24
import java.util.Date;
-
 
25
import java.util.List;
18
 
26
 
19
import org.apache.log4j.Logger;
27
import org.apache.log4j.Logger;
20
import org.apache.thrift.TException;
28
import org.apache.thrift.TException;
21
import org.apache.thrift.transport.TTransportException;
29
import org.apache.thrift.transport.TTransportException;
22
 
30
 
Line 25... Line 33...
25
 */
33
 */
26
 
34
 
27
@SuppressWarnings("serial")
35
@SuppressWarnings("serial")
28
public class ContactUsController extends BaseController {
36
public class ContactUsController extends BaseController {
29
 
37
 
-
 
38
    private static final long     CREATOR_ID = 1;
-
 
39
 
30
    private String id;
40
    private String                id;
31
 
41
 
32
    private static Logger log = Logger.getLogger(Class.class);
42
    private static Logger         log        = Logger.getLogger(Class.class);
33
 
43
 
34
    private UserCommunicationType formType = null;
44
    private UserCommunicationType formType   = null;
35
 
45
 
36
    List<Order> orders = null;
46
    List<Order>                   orders     = null;
37
    List<LineItem> products = null;
47
    List<LineItem>                products   = null;
38
    List<Long> order_ids = null;
48
    List<Long>                    order_ids  = null;
39
 
49
 
40
    public ContactUsController() {
50
    public ContactUsController() {
41
        super();
51
        super();
42
    }
52
    }
43
 
53
 
44
    // GET /Show Form
54
    // GET /Show Form
45
    public String index() {
55
    public String index() {
46
        try {
56
        try {
47
            TransactionClient transactionServiceClient = new TransactionClient();
57
            TransactionClient transactionServiceClient = new TransactionClient();
48
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
58
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient
-
 
59
                    .getClient();
49
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
60
            orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0,
-
 
61
                    (new Date()).getTime(), null);
50
        } catch (Exception e) {
62
        } catch (Exception e) {
51
            log.error("Unable to get the orders for the user becauase of: ", e);
63
            log.error("Unable to get the orders for the user becauase of: ", e);
52
        }
64
        }
53
 
65
 
54
        if (request.getParameter("type") != null) {
66
        if (request.getParameter("type") != null) {
55
            String requestedFormType = request.getParameter("type").toString().trim();
67
            String requestedFormType = request.getParameter("type").toString()
-
 
68
                    .trim();
56
            log.debug("Contact us requested for: " + requestedFormType);
69
            log.debug("Contact us requested for: " + requestedFormType);
57
            
70
 
58
            if (requestedFormType.equals("return")) {
71
            if (requestedFormType.equals("return")) {
59
                this.formType = UserCommunicationType.RETURN_FORM;
72
                this.formType = UserCommunicationType.RETURN_FORM;
60
            } else if (requestedFormType.equals("cancel")) {
73
            } else if (requestedFormType.equals("cancel")) {
61
                this.formType = UserCommunicationType.ORDER_CANCELLATION;
74
                this.formType = UserCommunicationType.ORDER_CANCELLATION;
62
            } else if (requestedFormType.equals("delivery")) {
75
            } else if (requestedFormType.equals("delivery")) {
Line 67... Line 80...
67
    }
80
    }
68
 
81
 
69
    public String show() throws SecurityException, IOException {
82
    public String show() throws SecurityException, IOException {
70
        try {
83
        try {
71
            TransactionClient transactionServiceClient = new TransactionClient();
84
            TransactionClient transactionServiceClient = new TransactionClient();
72
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();
85
            in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient
-
 
86
                    .getClient();
73
 
87
 
74
            if (id.equals("to_return")) {
88
            if (id.equals("to_return")) {
75
                order_ids = orderClient.getReturnableOrdersForCustomer(userinfo.getUserId(), 0);
89
                order_ids = orderClient.getReturnableOrdersForCustomer(
-
 
90
                        userinfo.getUserId(), 0);
76
            } else if (id.equals("to_cancel")) {
91
            } else if (id.equals("to_cancel")) {
77
                order_ids = orderClient.getCancellableOrdersForCustomer(userinfo.getUserId(), 0);
92
                order_ids = orderClient.getCancellableOrdersForCustomer(
-
 
93
                        userinfo.getUserId(), 0);
78
            } else if (id.equals("all_orders")) {
94
            } else if (id.equals("all_orders")) {
79
                orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);
95
                orders = orderClient.getOrdersForCustomer(userinfo.getUserId(),
-
 
96
                        0, (new Date()).getTime(), null);
80
            } else {
97
            } else {
81
                long orderId = Integer.parseInt(id);
98
                long orderId = Integer.parseInt(id);
82
                products = orderClient.getLineItemsForOrder(orderId);
99
                products = orderClient.getLineItemsForOrder(orderId);
83
            }
100
            }
84
        } catch (NumberFormatException e) {
101
        } catch (NumberFormatException e) {
Line 93... Line 110...
93
    public String create() {
110
    public String create() {
94
        long communicationType = -1;
111
        long communicationType = -1;
95
        long orderId = -1;
112
        long orderId = -1;
96
 
113
 
97
        try {
114
        try {
98
            boolean u = userinfo.isLoggedIn();
115
            boolean isUserLoggedIn = userinfo.isLoggedIn();
99
            long userId = u ? userinfo.getUserId() : 0;
116
            long userId = isUserLoggedIn ? userinfo.getUserId() : 0;
100
            String email = request.getParameter("email");
117
            String email = request.getParameter("email");
101
            communicationType = Integer.parseInt(request.getParameter("communication_type"));
118
            communicationType = Integer.parseInt(request
-
 
119
                    .getParameter("communication_type"));
102
 
120
 
103
            if (request.getParameter("order_id") != null) {
121
            if (request.getParameter("order_id") != null) {
104
                orderId = Integer.parseInt(request.getParameter("order_id"));
122
                orderId = Integer.parseInt(request.getParameter("order_id"));
105
            }
123
            }
-
 
124
 
106
            String awb = request.getParameter("awb");
125
            String awb = request.getParameter("awb");
107
            String product = request.getParameter("product");
126
            String product = request.getParameter("product");
108
            String subject = request.getParameter("subject");
127
            String subject = request.getParameter("subject");
109
            String message = request.getParameter("message");
128
            String message = request.getParameter("message");
110
 
129
 
111
            UserContextService.Client userClient = (new UserClient()).getClient();
130
            UserContextService.Client userClient = (new UserClient())
-
 
131
                    .getClient();
112
 
132
 
113
            if (userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject,
133
            if (userClient.saveUserCommunication(userId, email,
114
                    message)) {
134
                    communicationType, orderId, awb, product, subject, message)) {
115
                log.info("User Communication saved successfully!");
135
                log.info("User Communication saved successfully!");
116
            }
136
            }
117
 
137
 
-
 
138
            // We need to have tickets for all data communication!
-
 
139
            log.info("Creating ticket!");
-
 
140
            Client crmServiceClient = new CRMClient().getClient();
-
 
141
            Ticket ticket = new Ticket();
-
 
142
            ticket.setAirwayBillNo(awb);
-
 
143
            ticket.setProductName(product);
-
 
144
            ticket.setCategory(TicketCategory
-
 
145
                    .findByValue((int) communicationType));
-
 
146
            ticket.setDescription(subject + "-" + message);
-
 
147
 
-
 
148
            if (orderId != -1) {
-
 
149
                ticket.setOrderId(orderId);
-
 
150
            }
-
 
151
 
-
 
152
            ticket.setCreatorId(CREATOR_ID);
-
 
153
            ticket.setPriority(TicketPriority.MEDIUM);
-
 
154
            ticket.setStatus(TicketStatus.OPEN);
-
 
155
 
-
 
156
            log.info("Creating activity!");
-
 
157
            Activity activity = new Activity();
-
 
158
            activity.setCreatorId(CREATOR_ID);
-
 
159
            activity.setDescription("Ticket created");
-
 
160
            activity.setTicketCategory(ticket.getCategory());
-
 
161
            activity.setTicketDescription(ticket.getDescription());
-
 
162
            activity.setTicketPriority(ticket.getPriority());
-
 
163
            activity.setTicketStatus(ticket.getStatus());
-
 
164
            activity.setType(ActivityType.OTHER);
-
 
165
 
-
 
166
            if (isUserLoggedIn) {
-
 
167
                activity.setCustomerId(userId);
-
 
168
                ticket.setCustomerId(userId);
-
 
169
            } else {
-
 
170
                User user = userClient.getUserByEmail(email);
-
 
171
                if (user != null && user.getUserId() != -1) {
-
 
172
                    log.info("Found registered user for: " + email);
-
 
173
                    ticket.setCustomerId(user.getUserId());
-
 
174
                    activity.setCustomerId(user.getUserId());
-
 
175
                } else {
-
 
176
                    log.info("Setting customer email id to: " + email);
-
 
177
                    ticket.setCustomerEmailId(email);
-
 
178
                }
-
 
179
            }
-
 
180
 
-
 
181
            crmServiceClient.insertTicket(ticket, activity);
118
        } catch (NumberFormatException e) {
182
        } catch (NumberFormatException e) {
119
            log.error("Unable to get communication type or order id: ", e);
183
            log.error("Unable to get communication type or order id: ", e);
120
        } catch (TTransportException e) {
184
        } catch (TTransportException e) {
121
        	log.error("Unable to initialize client: ", e);
185
            log.error("Unable to initialize client: ", e);
122
		} catch (UserCommunicationException e) {
186
        } catch (UserCommunicationException e) {
123
            log.error("Unable to get communication type or order id: ", e);
187
            log.error("Unable to get communication type or order id: ", e);
124
		} catch (TException e) {
188
        } catch (TException e) {
125
			log.error("Thrift exception: ", e);
189
            log.error("Thrift exception: ", e);
-
 
190
        } catch (UserContextException e) {
-
 
191
            log.error("Thrift exception: ", e);
126
		}
192
        }
127
        return "success";
193
        return "success";
128
    }
194
    }
129
 
195
 
130
    public String getId() {
196
    public String getId() {
131
        return this.id;
197
        return this.id;
Line 153... Line 219...
153
            html.append("<option value='-1'>No Orders Found</option>");
219
            html.append("<option value='-1'>No Orders Found</option>");
154
        } else {
220
        } else {
155
            html.append("<option value='-1'>Select Order ID</option>");
221
            html.append("<option value='-1'>Select Order ID</option>");
156
 
222
 
157
            for (long order_id : order_ids) {
223
            for (long order_id : order_ids) {
158
                html.append("<option value='" + order_id + "'>" + order_id + "</option>");
224
                html.append("<option value='" + order_id + "'>" + order_id
-
 
225
                        + "</option>");
159
            }
226
            }
160
        }
227
        }
161
        return html.toString();
228
        return html.toString();
162
    }
229
    }
163
 
230