Subversion Repositories SmartDukaan

Rev

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

Rev 3519 Rev 3546
Line 9... Line 9...
9
import in.shop2020.crm.SearchFilter;
9
import in.shop2020.crm.SearchFilter;
10
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.Ticket;
11
import in.shop2020.crm.TicketCategory;
11
import in.shop2020.crm.TicketCategory;
12
import in.shop2020.crm.TicketPriority;
12
import in.shop2020.crm.TicketPriority;
13
import in.shop2020.crm.TicketStatus;
13
import in.shop2020.crm.TicketStatus;
-
 
14
import in.shop2020.model.v1.order.LineItem;
-
 
15
import in.shop2020.model.v1.order.Order;
-
 
16
import in.shop2020.model.v1.order.OrderStatus;
-
 
17
import in.shop2020.model.v1.order.TransactionServiceException;
14
import in.shop2020.model.v1.user.User;
18
import in.shop2020.model.v1.user.User;
15
import in.shop2020.model.v1.user.UserContextException;
19
import in.shop2020.model.v1.user.UserContextException;
16
import in.shop2020.serving.auth.CRMAuthorizingRealm;
20
import in.shop2020.serving.auth.CRMAuthorizingRealm;
17
import in.shop2020.thrift.clients.CRMClient;
21
import in.shop2020.thrift.clients.CRMClient;
18
import in.shop2020.thrift.clients.HelperClient;
22
import in.shop2020.thrift.clients.HelperClient;
-
 
23
import in.shop2020.thrift.clients.TransactionClient;
19
import in.shop2020.thrift.clients.UserClient;
24
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.util.CRMConstants;
25
import in.shop2020.util.CRMConstants;
21
import in.shop2020.utils.HelperService.Client;
26
import in.shop2020.utils.HelperService.Client;
22
import in.shop2020.utils.HelperServiceException;
27
import in.shop2020.utils.HelperServiceException;
-
 
28
import in.shop2020.utils.ModelUtils;
23
 
29
 
24
import java.text.ParseException;
30
import java.text.ParseException;
25
import java.util.ArrayList;
31
import java.util.ArrayList;
26
import java.util.Collections;
32
import java.util.Collections;
27
import java.util.Date;
33
import java.util.Date;
28
import java.util.List;
34
import java.util.List;
29
 
35
 
30
import org.apache.shiro.SecurityUtils;
36
import org.apache.shiro.SecurityUtils;
31
import org.apache.thrift.TException;
37
import org.apache.thrift.TException;
-
 
38
import org.apache.thrift.transport.TTransportException;
32
 
39
 
33
/**
40
/**
34
 * @author mandeep
41
 * @author mandeep
35
 * 
42
 * 
36
 */
43
 */
Line 61... Line 68...
61
    private List<Activity>    activities;
68
    private List<Activity>    activities;
62
    private String            subject;
69
    private String            subject;
63
    private String            body;
70
    private String            body;
64
    private String            customerName;
71
    private String            customerName;
65
    private String            customerMobileNumber;
72
    private String            customerMobileNumber;
-
 
73
    private User              user;
-
 
74
    private String            orderStatus;
-
 
75
    private List<Order>       orders;
66
 
76
 
67
    public String index() {
77
    public String index() {
68
        try {
78
        try {
69
            if (id != null && !id.isEmpty()) {
79
            if (id != null && !id.isEmpty()) {
70
                SearchFilter searchFilter = new SearchFilter();
80
                SearchFilter searchFilter = new SearchFilter();
Line 90... Line 100...
90
            activities = crmServiceClient.getActivities(searchFilter);
100
            activities = crmServiceClient.getActivities(searchFilter);
91
            subject = createSubjectString(ticket);
101
            subject = createSubjectString(ticket);
92
 
102
 
93
            if (ticket.isSetCustomerId()) {
103
            if (ticket.isSetCustomerId()) {
94
                userId = String.valueOf(ticket.getCustomerId());
104
                userId = String.valueOf(ticket.getCustomerId());
-
 
105
                userContextServiceClient = new UserClient().getClient();
-
 
106
 
-
 
107
                try {
-
 
108
                    user = userContextServiceClient.getUserById(ticket
-
 
109
                            .getCustomerId());
-
 
110
                } catch (UserContextException e) {
-
 
111
                    log.error("Could not fetch user details", e);
-
 
112
                }
95
            }
113
            }
96
 
114
 
97
            customerEmailId = ticket.getCustomerEmailId();
115
            customerEmailId = ticket.getCustomerEmailId();
-
 
116
 
-
 
117
            if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
-
 
118
                log.info("Fetching orders for " + ticket.getCustomerId());
-
 
119
                orders = new ArrayList<Order>();
-
 
120
                transactionServiceClient = new TransactionClient().getClient();
-
 
121
                for (Order order : transactionServiceClient
-
 
122
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
-
 
123
                                Collections.singletonList(OrderStatus.INIT))) {
-
 
124
                    log.info("Processing Order: " + order);
-
 
125
                    if (order.isCod()) {
-
 
126
                        orders.add(order);
-
 
127
                    }
-
 
128
                }
-
 
129
            }
98
        } catch (TException e) {
130
        } catch (TException e) {
99
            log.error("Error while loading edit page", e);
131
            log.error("Error loading edit page", e);
-
 
132
            return EXCEPTION;
-
 
133
        } catch (NumberFormatException e) {
-
 
134
            log.error("Error parsing orderId", e);
-
 
135
            return EXCEPTION;
-
 
136
        } catch (TransactionServiceException e) {
-
 
137
            log.error("Error fetching orders for " + ticket.getCustomerId(), e);
100
            return EXCEPTION;
138
            return EXCEPTION;
101
        }
139
        }
102
 
140
 
103
        return EDIT;
141
        return EDIT;
104
    }
142
    }
Line 108... Line 146...
108
                + " " + ticket.getCategory().name();
146
                + " " + ticket.getCategory().name();
109
    }
147
    }
110
 
148
 
111
    public String create() {
149
    public String create() {
112
        try {
150
        try {
113
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
151
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
-
 
152
                    .getId();
114
            Ticket ticket = new Ticket();
153
            Ticket ticket = new Ticket();
115
            ticket.setDescription(description);
154
            ticket.setDescription(description);
116
            ticket.setCreatorId(creatorId);
155
            ticket.setCreatorId(creatorId);
117
            ticket.setStatus(TicketStatus.OPEN);
156
            ticket.setStatus(TicketStatus.OPEN);
118
            ticket.setPriority(TicketPriority.valueOf(priority));
157
            ticket.setPriority(TicketPriority.valueOf(priority));
Line 132... Line 171...
132
            }
171
            }
133
 
172
 
134
            if (userId != null && !userId.isEmpty()) {
173
            if (userId != null && !userId.isEmpty()) {
135
                ticket.setCustomerId(Long.parseLong(userId));
174
                ticket.setCustomerId(Long.parseLong(userId));
136
                activity.setCustomerId(Long.parseLong(userId));
175
                activity.setCustomerId(Long.parseLong(userId));
137
            }
-
 
138
            else {
176
            } else {
139
                User user = null;
177
                User user = null;
140
                userContextServiceClient = new UserClient().getClient();
178
                userContextServiceClient = new UserClient().getClient();
141
                try {
179
                try {
142
                    if (customerName != null && !customerName.isEmpty()) {
180
                    if (customerName != null && !customerName.isEmpty()) {
143
                        ticket.setCustomerName(customerName);
181
                        ticket.setCustomerName(customerName);
Line 145... Line 183...
145
                    }
183
                    }
146
 
184
 
147
                    if (customerEmailId != null && !customerEmailId.isEmpty()) {
185
                    if (customerEmailId != null && !customerEmailId.isEmpty()) {
148
                        ticket.setCustomerEmailId(customerEmailId);
186
                        ticket.setCustomerEmailId(customerEmailId);
149
                        activity.setCustomerEmailId(customerEmailId);
187
                        activity.setCustomerEmailId(customerEmailId);
-
 
188
                        user = userContextServiceClient
150
                        user = userContextServiceClient.getUserByEmail(customerEmailId);
189
                                .getUserByEmail(customerEmailId);
151
                    }
190
                    }
152
 
191
 
-
 
192
                    if ((user == null || user.getUserId() == -1)
-
 
193
                            && customerMobileNumber != null
153
                    if ((user == null || user.getUserId() == -1) && customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
194
                            && !customerMobileNumber.isEmpty()) {
154
                        ticket.setCustomerMobileNumber(customerMobileNumber);
195
                        ticket.setCustomerMobileNumber(customerMobileNumber);
155
                        activity.setCustomerMobileNumber(customerMobileNumber);
196
                        activity.setCustomerMobileNumber(customerMobileNumber);
-
 
197
                        user = userContextServiceClient
-
 
198
                                .getUserByMobileNumber(Long
156
                        user = userContextServiceClient.getUserByMobileNumber(Long.parseLong(customerMobileNumber));
199
                                        .parseLong(customerMobileNumber));
157
                    }
200
                    }
158
                } catch (UserContextException e) {
201
                } catch (UserContextException e) {
159
                    log.error("Could not fetch user for: " + customerEmailId + " "
202
                    log.error("Could not fetch user for: " + customerEmailId
160
                            + customerMobileNumber + " " + customerName, e);
203
                            + " " + customerMobileNumber + " " + customerName,
-
 
204
                            e);
161
                }
205
                }
162
                
-
 
-
 
206
 
163
                if (user != null && user.getUserId() != -1) {
207
                if (user != null && user.getUserId() != -1) {
164
                    ticket.setCustomerId(user.getUserId());
208
                    ticket.setCustomerId(user.getUserId());
165
                    activity.setCustomerId(user.getUserId());
209
                    activity.setCustomerId(user.getUserId());
166
                }
210
                }
167
            }
211
            }
168
 
212
 
169
            // handling null values appropriately
213
            // handling null values appropriately
170
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
214
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
171
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId).getId();
215
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
-
 
216
                        .getId();
172
                ticket.setAssigneeId(assigneeId);
217
                ticket.setAssigneeId(assigneeId);
173
                activity.setTicketAssigneeId(assigneeId);
218
                activity.setTicketAssigneeId(assigneeId);
174
            }
219
            }
175
 
220
 
176
            crmServiceClient         = new CRMClient().getClient();
221
            crmServiceClient = new CRMClient().getClient();
-
 
222
            id = String
177
            id = String.valueOf(crmServiceClient.insertTicket(ticket, activity));
223
                    .valueOf(crmServiceClient.insertTicket(ticket, activity));
178
        } catch (TException e) {
224
        } catch (TException e) {
179
            log.error("Error while creating ticket", e);
225
            log.error("Error while creating ticket", e);
180
            return EXCEPTION;
226
            return EXCEPTION;
181
        }
227
        }
182
 
228
 
Line 195... Line 241...
195
            }
241
            }
196
 
242
 
197
            if (agentIds != null && agentIds.length != 0) {
243
            if (agentIds != null && agentIds.length != 0) {
198
                searchFilter.setTicketAssigneeIds(new ArrayList<Long>());
244
                searchFilter.setTicketAssigneeIds(new ArrayList<Long>());
199
                for (String agentId : agentIds) {
245
                for (String agentId : agentIds) {
-
 
246
                    searchFilter.getTicketAssigneeIds().add(
200
                    searchFilter.getTicketAssigneeIds().add(CRMAuthorizingRealm.getAgent(agentId).getId());
247
                            CRMAuthorizingRealm.getAgent(agentId).getId());
201
                }
248
                }
202
            }
249
            }
203
 
250
 
204
            if (startTimestamp != null && !startTimestamp.isEmpty()) {
251
            if (startTimestamp != null && !startTimestamp.isEmpty()) {
205
                searchFilter.setStartTimestamp(SDF.parse(startTimestamp).getTime());
252
                searchFilter.setStartTimestamp(SDF.parse(startTimestamp)
-
 
253
                        .getTime());
206
            }
254
            }
207
 
255
 
208
            if (endTimestamp != null && !endTimestamp.isEmpty()) {
256
            if (endTimestamp != null && !endTimestamp.isEmpty()) {
209
                searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());
257
                searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());
210
            }
258
            }
Line 212... Line 260...
212
            if (id != null && !id.isEmpty()) {
260
            if (id != null && !id.isEmpty()) {
213
                searchFilter.setTicketId(Long.parseLong(id));
261
                searchFilter.setTicketId(Long.parseLong(id));
214
            }
262
            }
215
 
263
 
216
            if (status != null && !status.isEmpty()) {
264
            if (status != null && !status.isEmpty()) {
-
 
265
                searchFilter.setTicketStatuses(Collections
217
                searchFilter.setTicketStatus(TicketStatus.valueOf(status));
266
                        .singletonList(TicketStatus.valueOf(status)));
218
            }
267
            }
219
 
268
 
220
            if (category != null && !category.isEmpty()) {
269
            if (category != null && !category.isEmpty()) {
-
 
270
                searchFilter
221
                searchFilter.setTicketCategory(TicketCategory.valueOf(category));
271
                        .setTicketCategory(TicketCategory.valueOf(category));
222
            }
272
            }
223
 
273
 
224
            crmServiceClient         = new CRMClient().getClient();
274
            crmServiceClient = new CRMClient().getClient();
225
            tickets = crmServiceClient.getTickets(searchFilter);
275
            tickets = crmServiceClient.getTickets(searchFilter);
226
        } catch (TException e) {
276
        } catch (TException e) {
227
            String errorString = "Error getting tickets for "
277
            String errorString = "Error getting tickets for "
228
                    + currentAgentEmailId;
278
                    + currentAgentEmailId;
229
            log.error(errorString, e);
279
            log.error(errorString, e);
Line 233... Line 283...
233
        return index();
283
        return index();
234
    }
284
    }
235
 
285
 
236
    /**
286
    /**
237
     * Returns tickets assigned to the current logged in agent
287
     * Returns tickets assigned to the current logged in agent
238
     *
288
     * 
239
     * @return
289
     * @return
240
     */
290
     */
241
    public String getMyOpenTickets() {
291
    public String getMyOpenTickets() {
242
        try {
292
        try {
243
            Agent agent = CRMAuthorizingRealm.getAgent(currentAgentEmailId);
293
            Agent agent = CRMAuthorizingRealm.getAgent(currentAgentEmailId);
244
 
294
 
245
            SearchFilter searchFilter = new SearchFilter();
295
            SearchFilter searchFilter = new SearchFilter();
246
            searchFilter.setTicketAssigneeIds(Collections.singletonList(agent.getId()));
296
            searchFilter.setTicketAssigneeIds(Collections.singletonList(agent
-
 
297
                    .getId()));
247
            crmServiceClient         = new CRMClient().getClient();
298
            crmServiceClient = new CRMClient().getClient();
248
            for (Ticket ticket : crmServiceClient.getTickets(searchFilter)) {
299
            for (Ticket ticket : crmServiceClient.getTickets(searchFilter)) {
249
                if (TicketStatus.OPEN.equals(ticket.getStatus())) {
300
                if (TicketStatus.OPEN.equals(ticket.getStatus())) {
250
                    tickets.add(ticket);
301
                    tickets.add(ticket);
251
                }
302
                }
252
            }
303
            }
Line 260... Line 311...
260
        return index();
311
        return index();
261
    }
312
    }
262
 
313
 
263
    public String getUnassignedTickets() {
314
    public String getUnassignedTickets() {
264
        try {
315
        try {
265
            crmServiceClient         = new CRMClient().getClient();
316
            crmServiceClient = new CRMClient().getClient();
266
            tickets = crmServiceClient.getUnassignedTickets();
317
            tickets = crmServiceClient.getUnassignedTickets();
267
        } catch (TException e) {
318
        } catch (TException e) {
268
            String errorString = "Error getting tickets for "
319
            String errorString = "Error getting tickets for "
269
                    + currentAgentEmailId;
320
                    + currentAgentEmailId;
270
            log.error(errorString, e);
321
            log.error(errorString, e);
Line 277... Line 328...
277
    public String update() {
328
    public String update() {
278
        try {
329
        try {
279
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
330
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
280
                    .getId();
331
                    .getId();
281
 
332
 
282
            // Only subject and close date are editable fields for a ticket
333
            SearchFilter searchFilter = new SearchFilter();
283
            Ticket ticket = new Ticket();
334
            searchFilter.setTicketId(Long.parseLong(id));
284
            ticket.setId(Long.parseLong(id));
335
            crmServiceClient = new CRMClient().getClient();
-
 
336
            Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
285
            ticket.setDescription(description);
337
            ticket.setDescription(description);
286
            ticket.setCategory(TicketCategory.valueOf(category));
-
 
287
            ticket.setPriority(TicketPriority.valueOf(priority));
338
            ticket.setPriority(TicketPriority.valueOf(priority));
288
            ticket.setStatus(TicketStatus.valueOf(status));
-
 
289
 
339
 
290
            // Update when a ticket is closed!
340
            // Update when a ticket is closed!
291
            if (TicketStatus.CLOSED.name().equals(status)) {
341
            if (TicketStatus.CLOSED.name().equals(status)) {
-
 
342
                if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())
-
 
343
                        && pendingCODOrders(ticket.getCustomerId())) {
-
 
344
                    addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");
-
 
345
                } else {
-
 
346
                    ticket.setCategory(TicketCategory.valueOf(category));
-
 
347
                    ticket.setStatus(TicketStatus.valueOf(status));
292
                ticket.setCloseDate(new Date().getTime());
348
                    ticket.setCloseDate(new Date().getTime());
-
 
349
                }
-
 
350
            }
-
 
351
            else {
-
 
352
                ticket.setCategory(TicketCategory.valueOf(category));
-
 
353
                ticket.setStatus(TicketStatus.valueOf(status));                
293
            }
354
            }
294
 
355
 
295
            if (activityDescription == null || activityDescription.isEmpty()) {
356
            if (activityDescription == null || activityDescription.isEmpty()) {
296
                activityDescription = "Updating ticket fields";
357
                activityDescription = "Updating ticket fields";
297
            }
358
            }
298
 
359
 
299
            Activity activity = new Activity();
360
            Activity activity = new Activity();
300
            activity.setDescription(activityDescription);
361
            activity.setDescription(activityDescription);
301
            activity.setType(ActivityType.valueOf(activityType));
362
            activity.setType(ActivityType.valueOf(activityType));
302
            activity.setTicketPriority(TicketPriority.valueOf(priority));
363
            activity.setTicketPriority(ticket.getPriority());
303
            activity.setTicketStatus(TicketStatus.valueOf(status));
364
            activity.setTicketStatus(ticket.getStatus());
304
            activity.setCreatorId(creatorId);
365
            activity.setCreatorId(creatorId);
305
            activity.setTicketCategory(TicketCategory.valueOf(category));
366
            activity.setTicketCategory(ticket.getCategory());
306
            activity.setTicketDescription(description);
367
            activity.setTicketDescription(ticket.getDescription());
307
 
368
 
308
            if (userId != null && !userId.isEmpty()) {
369
            if (userId != null && !userId.isEmpty()) {
309
                activity.setCustomerId(Long.parseLong(userId));
370
                activity.setCustomerId(Long.parseLong(userId));
310
            }
371
            }
311
 
372
 
312
            log.info(activityType);
-
 
313
            if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
373
            if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
314
                log.info("Sending mail");
374
                log.info("Sending mail");
315
                Client helperClient = new HelperClient().getClient();
375
                Client helperClient = new HelperClient().getClient();
316
                activity.setUserEmailId(helperClient.saveUserEmailForSending(
376
                activity.setUserEmailId(helperClient.saveUserEmailForSending(
317
                        customerEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
377
                        customerEmailId, CRMConstants.CRM_EMAIL_SENDOR,
318
                        body, null, CRMConstants.CRM_EMAIL_TYPE));
378
                        subject, body, null, CRMConstants.CRM_EMAIL_TYPE));
319
 
379
 
320
                // We change activityType to OTHER when pop up box for email
380
                // We change activityType to OTHER when pop up box for email
321
                // closes
381
                // closes
322
                activity.setDescription("Subject: " + subject + "\n\n"
382
                activity.setDescription("Subject: " + subject + "\n\n"
323
                        + "Body: " + body);
383
                        + "Body: " + body);
324
            }
384
            }
325
 
385
 
326
            // handling null values appropriately
386
            // handling null values appropriately
327
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
387
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
328
                long assigneeId = CRMAuthorizingRealm.getAgent(
388
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
329
                        assigneeEmailId).getId();
389
                        .getId();
330
                ticket.setAssigneeId(assigneeId);
390
                ticket.setAssigneeId(assigneeId);
331
                activity.setTicketAssigneeId(assigneeId);
391
                activity.setTicketAssigneeId(assigneeId);
332
            }
392
            }
333
 
393
 
334
            User user = null;
394
            User user = null;
Line 340... Line 400...
340
                }
400
                }
341
 
401
 
342
                if (customerEmailId != null && !customerEmailId.isEmpty()) {
402
                if (customerEmailId != null && !customerEmailId.isEmpty()) {
343
                    ticket.setCustomerEmailId(customerEmailId);
403
                    ticket.setCustomerEmailId(customerEmailId);
344
                    activity.setCustomerEmailId(customerEmailId);
404
                    activity.setCustomerEmailId(customerEmailId);
-
 
405
                    user = userContextServiceClient
345
                    user = userContextServiceClient.getUserByEmail(customerEmailId);
406
                            .getUserByEmail(customerEmailId);
346
                }
407
                }
347
 
408
 
-
 
409
                if ((user == null || user.getUserId() == -1)
-
 
410
                        && customerMobileNumber != null
348
                if ((user == null || user.getUserId() == -1) && customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
411
                        && !customerMobileNumber.isEmpty()) {
349
                    ticket.setCustomerMobileNumber(customerMobileNumber);
412
                    ticket.setCustomerMobileNumber(customerMobileNumber);
350
                    activity.setCustomerMobileNumber(customerMobileNumber);
413
                    activity.setCustomerMobileNumber(customerMobileNumber);
351
                    user = userContextServiceClient.getUserByMobileNumber(Long.parseLong(customerMobileNumber));
414
                    user = userContextServiceClient.getUserByMobileNumber(Long
-
 
415
                            .parseLong(customerMobileNumber));
352
                }
416
                }
353
            } catch (UserContextException e) {
417
            } catch (UserContextException e) {
354
                log.error("Could not fetch user for: " + customerEmailId + " "
418
                log.error("Could not fetch user for: " + customerEmailId + " "
355
                        + customerMobileNumber + " " + customerName, e);
419
                        + customerMobileNumber + " " + customerName, e);
356
            }
420
            }
357
            
421
 
358
            if (user != null && user.getUserId() != -1) {
422
            if (user != null && user.getUserId() != -1) {
359
                ticket.setCustomerId(user.getUserId());
423
                ticket.setCustomerId(user.getUserId());
360
                activity.setCustomerId(user.getUserId());
424
                activity.setCustomerId(user.getUserId());
361
            }
425
            }
362
 
426
 
Line 371... Line 435...
371
        }
435
        }
372
 
436
 
373
        return index();
437
        return index();
374
    }
438
    }
375
 
439
 
-
 
440
    private boolean pendingCODOrders(long customerId) {
-
 
441
        try {
-
 
442
            log.info("Trying to fetch orders for " + customerId);
-
 
443
            transactionServiceClient = new TransactionClient().getClient();
-
 
444
            for (Order order : transactionServiceClient.getOrdersForCustomer(
-
 
445
                    customerId, 0, 0,
-
 
446
                    Collections.singletonList(OrderStatus.INIT))) {
-
 
447
                log.info("Processing order: " + order.getId() + " with COD: " + order.isCod());
-
 
448
                if (order.isCod()) {
-
 
449
                    log.info("Returning true from pendingCODOrders() for " + customerId);
-
 
450
                    return true;
-
 
451
                }
-
 
452
            }
-
 
453
        } catch (TTransportException e) {
-
 
454
            log.error("Error while creating thrift client", e);
-
 
455
        } catch (TransactionServiceException e) {
-
 
456
            log.error("Error fetching orders", e);
-
 
457
        } catch (TException e) {
-
 
458
            log.error("Error fetching orders", e);
-
 
459
        }
-
 
460
 
-
 
461
        log.info("Returning false from pendingCODOrders() for " + customerId);
-
 
462
        return false;
-
 
463
    }
-
 
464
 
-
 
465
    public String updateOrderStatus() throws NumberFormatException,
-
 
466
            TransactionServiceException, TException {
-
 
467
        long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
-
 
468
                .getId();
-
 
469
 
-
 
470
        transactionServiceClient = new TransactionClient().getClient();
-
 
471
        transactionServiceClient.changeOrderStatus(Long.parseLong(orderId),
-
 
472
                OrderStatus.valueOf(orderStatus),
-
 
473
                OrderStatus.valueOf(orderStatus).getDescription());
-
 
474
 
-
 
475
        SearchFilter searchFilter = new SearchFilter();
-
 
476
        searchFilter.setTicketId(Long.parseLong(id));
-
 
477
        crmServiceClient = new CRMClient().getClient();
-
 
478
        Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
-
 
479
 
-
 
480
        // Inserting activity
-
 
481
        Activity activity = new Activity();
-
 
482
        activity.setDescription("Updating status for Order Id: " + orderId
-
 
483
                + " to " + orderStatus);
-
 
484
        activity.setType(ActivityType.OTHER);
-
 
485
        activity.setTicketPriority(ticket.getPriority());
-
 
486
        activity.setTicketStatus(ticket.getStatus());
-
 
487
        activity.setCreatorId(creatorId);
-
 
488
        activity.setTicketCategory(ticket.getCategory());
-
 
489
        activity.setTicketDescription(ticket.getDescription());
-
 
490
        activity.setCustomerId(ticket.getCustomerId());
-
 
491
        activity.setTicketAssigneeId(ticket.getAssigneeId());
-
 
492
 
-
 
493
        crmServiceClient = new CRMClient().getClient();
-
 
494
        crmServiceClient.updateTicket(ticket, activity);
-
 
495
 
-
 
496
        return edit();
-
 
497
    }
-
 
498
 
376
    public User getUser(Long userId) {
499
    public User getUser(Long userId) {
377
        User user = null;
500
        User user = null;
378
 
501
 
379
        try {
502
        try {
380
            userContextServiceClient = new UserClient().getClient();
503
            userContextServiceClient = new UserClient().getClient();
Line 390... Line 513...
390
        }
513
        }
391
 
514
 
392
        return user;
515
        return user;
393
    }
516
    }
394
 
517
 
-
 
518
    public String getAddress(Order order) {
-
 
519
        return ModelUtils.extractAddressFromOrder(order);
-
 
520
    }
-
 
521
 
-
 
522
    public String getProductName(LineItem lineItem) {
-
 
523
        return ModelUtils.extractProductNameFromLineItem(lineItem);
-
 
524
    }
-
 
525
 
395
    public ActivityType[] getActivityTypes() {
526
    public ActivityType[] getActivityTypes() {
396
        return ActivityType.values();
527
        return ActivityType.values();
397
    }
528
    }
398
 
529
 
399
    public TicketStatus[] getTicketStatuses() {
530
    public TicketStatus[] getTicketStatuses() {
Line 581... Line 712...
581
    }
712
    }
582
 
713
 
583
    public void setCustomerMobileNumber(String customerMobileNumber) {
714
    public void setCustomerMobileNumber(String customerMobileNumber) {
584
        this.customerMobileNumber = customerMobileNumber;
715
        this.customerMobileNumber = customerMobileNumber;
585
    }
716
    }
-
 
717
 
-
 
718
    public User getUser() {
-
 
719
        return user;
-
 
720
    }
-
 
721
 
-
 
722
    public void setUser(User user) {
-
 
723
        this.user = user;
-
 
724
    }
-
 
725
 
-
 
726
    public String getOrderStatus() {
-
 
727
        return orderStatus;
-
 
728
    }
-
 
729
 
-
 
730
    public void setOrderStatus(String orderStatus) {
-
 
731
        this.orderStatus = orderStatus;
-
 
732
    }
-
 
733
 
-
 
734
    public List<Order> getOrders() {
-
 
735
        return orders;
-
 
736
    }
-
 
737
 
-
 
738
    public void setOrders(List<Order> orders) {
-
 
739
        this.orders = orders;
-
 
740
    }
586
}
741
}