Subversion Repositories SmartDukaan

Rev

Rev 3972 | Rev 4020 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3137 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
3339 mandeep.dh 6
import in.shop2020.crm.Activity;
7
import in.shop2020.crm.ActivityType;
3137 mandeep.dh 8
import in.shop2020.crm.Agent;
3390 mandeep.dh 9
import in.shop2020.crm.SearchFilter;
3137 mandeep.dh 10
import in.shop2020.crm.Ticket;
3339 mandeep.dh 11
import in.shop2020.crm.TicketCategory;
12
import in.shop2020.crm.TicketPriority;
3137 mandeep.dh 13
import in.shop2020.crm.TicketStatus;
3546 mandeep.dh 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;
3137 mandeep.dh 18
import in.shop2020.model.v1.user.User;
19
import in.shop2020.model.v1.user.UserContextException;
3578 mandeep.dh 20
import in.shop2020.payments.Payment;
21
import in.shop2020.payments.PaymentException;
22
import in.shop2020.payments.PaymentStatus;
3390 mandeep.dh 23
import in.shop2020.serving.auth.CRMAuthorizingRealm;
24
import in.shop2020.thrift.clients.CRMClient;
3405 mandeep.dh 25
import in.shop2020.thrift.clients.HelperClient;
3578 mandeep.dh 26
import in.shop2020.thrift.clients.PaymentClient;
3546 mandeep.dh 27
import in.shop2020.thrift.clients.TransactionClient;
3390 mandeep.dh 28
import in.shop2020.thrift.clients.UserClient;
3405 mandeep.dh 29
import in.shop2020.util.CRMConstants;
30
import in.shop2020.utils.HelperService.Client;
31
import in.shop2020.utils.HelperServiceException;
3546 mandeep.dh 32
import in.shop2020.utils.ModelUtils;
3137 mandeep.dh 33
 
3397 mandeep.dh 34
import java.text.ParseException;
3137 mandeep.dh 35
import java.util.ArrayList;
3578 mandeep.dh 36
import java.util.Calendar;
3390 mandeep.dh 37
import java.util.Collections;
3405 mandeep.dh 38
import java.util.Date;
3137 mandeep.dh 39
import java.util.List;
40
 
3405 mandeep.dh 41
import org.apache.shiro.SecurityUtils;
3137 mandeep.dh 42
import org.apache.thrift.TException;
3546 mandeep.dh 43
import org.apache.thrift.transport.TTransportException;
3137 mandeep.dh 44
 
45
/**
46
 * @author mandeep
47
 * 
48
 */
49
public class TicketsController extends BaseController {
50
 
51
    /**
52
     * 
53
     */
54
    private static final long serialVersionUID = 1L;
55
 
56
    List<Ticket>              tickets          = new ArrayList<Ticket>();
3405 mandeep.dh 57
    private String            customerEmailId;
3339 mandeep.dh 58
    private String            description;
59
    private String            assigneeEmailId;
60
    private String            priority;
61
    private String            category;
62
    private String            orderId;
3397 mandeep.dh 63
    private String[]          agentIds;
64
    private String            startTimestamp;
65
    private String            endTimestamp;
3137 mandeep.dh 66
 
3405 mandeep.dh 67
    private String            userId;
68
    private String            id;
69
    private String            activityDescription;
70
    private String            status;
71
    private String            activityType;
72
    private Ticket            ticket;
73
    private List<Activity>    activities;
74
    private String            subject;
75
    private String            body;
76
    private String            customerName;
77
    private String            customerMobileNumber;
3546 mandeep.dh 78
    private User              user;
79
    private String            orderStatus;
80
    private List<Order>       orders;
3405 mandeep.dh 81
 
82
    public String index() {
83
        try {
84
            if (id != null && !id.isEmpty()) {
85
                SearchFilter searchFilter = new SearchFilter();
86
                crmServiceClient = new CRMClient().getClient();
87
                searchFilter.setTicketId(Long.parseLong(id));
88
                tickets = crmServiceClient.getTickets(searchFilter);
89
            }
90
        } catch (TException e) {
91
            log.error("Error while getting tickets", e);
92
            return EXCEPTION;
93
        }
94
 
95
        return INDEX;
96
    }
97
 
98
    public String edit() {
99
        try {
100
            long ticketId = Long.parseLong(id);
101
            SearchFilter searchFilter = new SearchFilter();
102
            searchFilter.setTicketId(ticketId);
103
            crmServiceClient = new CRMClient().getClient();
104
            ticket = crmServiceClient.getTickets(searchFilter).get(0);
105
            activities = crmServiceClient.getActivities(searchFilter);
106
            subject = createSubjectString(ticket);
107
 
108
            if (ticket.isSetCustomerId()) {
109
                userId = String.valueOf(ticket.getCustomerId());
3546 mandeep.dh 110
                userContextServiceClient = new UserClient().getClient();
111
 
112
                try {
113
                    user = userContextServiceClient.getUserById(ticket
114
                            .getCustomerId());
115
                } catch (UserContextException e) {
116
                    log.error("Could not fetch user details", e);
117
                }
3405 mandeep.dh 118
            }
119
 
120
            customerEmailId = ticket.getCustomerEmailId();
3546 mandeep.dh 121
 
122
            if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
123
                log.info("Fetching orders for " + ticket.getCustomerId());
124
                orders = new ArrayList<Order>();
125
                transactionServiceClient = new TransactionClient().getClient();
126
                for (Order order : transactionServiceClient
127
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
128
                                Collections.singletonList(OrderStatus.INIT))) {
129
                    log.info("Processing Order: " + order);
130
                    if (order.isCod()) {
131
                        orders.add(order);
132
                    }
133
                }
134
            }
3578 mandeep.dh 135
 
136
            if (TicketCategory.FAILED_PAYMENTS.equals(ticket.getCategory())) {
137
                log.info("Fetching orders for " + ticket.getCustomerId());
138
                orders = new ArrayList<Order>();
139
                in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
140
 
141
                long failedTransactionId = -1;
142
                long lastfailedTransactionTimestamp = -1;
143
                for (Payment payment : paymentClient.getPaymentsForUser(ticket.getCustomerId(), 0, getTomorrow().getTime(), PaymentStatus.FAILED, 0)) {
144
                    if (payment.getErrorTimestamp() > lastfailedTransactionTimestamp) {
145
                        failedTransactionId = payment.getMerchantTxnId();
146
                    }
147
                }
148
 
149
                transactionServiceClient = new TransactionClient().getClient();
150
                orders.addAll(transactionServiceClient.getOrdersForTransaction(failedTransactionId, ticket.getCustomerId()));
151
            }
4008 mandeep.dh 152
 
153
            if (TicketCategory.DELAYED_DELIVERY.equals(ticket.getCategory())) {
154
                log.info("Fetching orders for " + ticket.getCustomerId());
155
                orders = new ArrayList<Order>();
156
                transactionServiceClient = new TransactionClient().getClient();
157
 
158
                for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0, null)) {
159
                    if (order.getExpected_delivery_time() > order.getPromised_delivery_time() && order.getExpected_delivery_time() > new Date().getTime()) {
160
                        orders.add(order);
161
                    }
162
                }
163
            }
3405 mandeep.dh 164
        } catch (TException e) {
3546 mandeep.dh 165
            log.error("Error loading edit page", e);
166
        } catch (NumberFormatException e) {
167
            log.error("Error parsing orderId", e);
168
        } catch (TransactionServiceException e) {
169
            log.error("Error fetching orders for " + ticket.getCustomerId(), e);
3578 mandeep.dh 170
        } catch (PaymentException e) {
171
            log.error("Error fetching payments for " + ticket.getCustomerId(), e);
3405 mandeep.dh 172
        }
173
 
174
        return EDIT;
175
    }
176
 
177
    private String createSubjectString(Ticket ticket) {
178
        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
179
                + " " + ticket.getCategory().name();
180
    }
181
 
3578 mandeep.dh 182
    private Date getTomorrow() {
183
        Calendar calendar = Calendar.getInstance();
184
        calendar.setTime(new Date());
185
        calendar.add(Calendar.DAY_OF_MONTH, 1);
186
        return calendar.getTime();
187
    }
188
 
3339 mandeep.dh 189
    public String create() {
190
        try {
3546 mandeep.dh 191
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
192
                    .getId();
3339 mandeep.dh 193
            Ticket ticket = new Ticket();
194
            ticket.setDescription(description);
195
            ticket.setCreatorId(creatorId);
196
            ticket.setStatus(TicketStatus.OPEN);
197
            ticket.setPriority(TicketPriority.valueOf(priority));
198
            ticket.setCategory(TicketCategory.valueOf(category));
199
 
200
            Activity activity = new Activity();
201
            activity.setDescription("Creating Ticket");
202
            activity.setType(ActivityType.OTHER);
203
            activity.setTicketPriority(TicketPriority.valueOf(priority));
204
            activity.setTicketStatus(TicketStatus.OPEN);
205
            activity.setCreatorId(creatorId);
206
            activity.setTicketCategory(TicketCategory.valueOf(category));
207
            activity.setTicketDescription(description);
208
 
209
            if (orderId != null && !orderId.isEmpty()) {
210
                ticket.setOrderId(Long.parseLong(orderId));
211
            }
212
 
3405 mandeep.dh 213
            if (userId != null && !userId.isEmpty()) {
214
                ticket.setCustomerId(Long.parseLong(userId));
215
                activity.setCustomerId(Long.parseLong(userId));
3546 mandeep.dh 216
            } else {
3390 mandeep.dh 217
                User user = null;
218
                userContextServiceClient = new UserClient().getClient();
219
                try {
3405 mandeep.dh 220
                    if (customerName != null && !customerName.isEmpty()) {
221
                        ticket.setCustomerName(customerName);
222
                        activity.setCustomerName(customerName);
223
                    }
224
 
225
                    if (customerEmailId != null && !customerEmailId.isEmpty()) {
226
                        ticket.setCustomerEmailId(customerEmailId);
227
                        activity.setCustomerEmailId(customerEmailId);
3546 mandeep.dh 228
                        user = userContextServiceClient
229
                                .getUserByEmail(customerEmailId);
3405 mandeep.dh 230
                    }
231
 
3546 mandeep.dh 232
                    if ((user == null || user.getUserId() == -1)
233
                            && customerMobileNumber != null
234
                            && !customerMobileNumber.isEmpty()) {
3405 mandeep.dh 235
                        ticket.setCustomerMobileNumber(customerMobileNumber);
236
                        activity.setCustomerMobileNumber(customerMobileNumber);
3546 mandeep.dh 237
                        user = userContextServiceClient
238
                                .getUserByMobileNumber(Long
239
                                        .parseLong(customerMobileNumber));
3405 mandeep.dh 240
                    }
3390 mandeep.dh 241
                } catch (UserContextException e) {
3546 mandeep.dh 242
                    log.error("Could not fetch user for: " + customerEmailId
243
                            + " " + customerMobileNumber + " " + customerName,
244
                            e);
3390 mandeep.dh 245
                }
3546 mandeep.dh 246
 
3390 mandeep.dh 247
                if (user != null && user.getUserId() != -1) {
248
                    ticket.setCustomerId(user.getUserId());
249
                    activity.setCustomerId(user.getUserId());
250
                }
3339 mandeep.dh 251
            }
252
 
253
            // handling null values appropriately
254
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
3546 mandeep.dh 255
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
256
                        .getId();
3339 mandeep.dh 257
                ticket.setAssigneeId(assigneeId);
258
                activity.setTicketAssigneeId(assigneeId);
259
            }
260
 
3546 mandeep.dh 261
            crmServiceClient = new CRMClient().getClient();
262
            id = String
263
                    .valueOf(crmServiceClient.insertTicket(ticket, activity));
3339 mandeep.dh 264
        } catch (TException e) {
265
            log.error("Error while creating ticket", e);
266
            return EXCEPTION;
267
        }
268
 
3405 mandeep.dh 269
        return index();
3339 mandeep.dh 270
    }
271
 
3405 mandeep.dh 272
    public boolean isAssigneeEditable() {
273
        return SecurityUtils.getSubject().hasRole("TeamLead");
274
    }
275
 
3397 mandeep.dh 276
    public String searchTickets() throws ParseException {
3137 mandeep.dh 277
        try {
3397 mandeep.dh 278
            SearchFilter searchFilter = new SearchFilter();
3405 mandeep.dh 279
            if (userId != null && !userId.isEmpty()) {
280
                searchFilter.setCustomerId(Long.parseLong(userId));
281
            }
282
 
3397 mandeep.dh 283
            if (agentIds != null && agentIds.length != 0) {
284
                searchFilter.setTicketAssigneeIds(new ArrayList<Long>());
285
                for (String agentId : agentIds) {
3546 mandeep.dh 286
                    searchFilter.getTicketAssigneeIds().add(
287
                            CRMAuthorizingRealm.getAgent(agentId).getId());
3397 mandeep.dh 288
                }
289
            }
3137 mandeep.dh 290
 
3397 mandeep.dh 291
            if (startTimestamp != null && !startTimestamp.isEmpty()) {
3546 mandeep.dh 292
                searchFilter.setStartTimestamp(SDF.parse(startTimestamp)
293
                        .getTime());
3397 mandeep.dh 294
            }
295
 
296
            if (endTimestamp != null && !endTimestamp.isEmpty()) {
297
                searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());
298
            }
299
 
3422 mandeep.dh 300
            if (id != null && !id.isEmpty()) {
301
                searchFilter.setTicketId(Long.parseLong(id));
302
            }
303
 
3499 mandeep.dh 304
            if (status != null && !status.isEmpty()) {
3972 mandeep.dh 305
                searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
306
                searchFilter.getTicketStatuses().add(TicketStatus.valueOf(status));
307
                if (TicketStatus.OPEN.name().equals(status)) {
308
                    searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
309
                }
3499 mandeep.dh 310
            }
311
 
312
            if (category != null && !category.isEmpty()) {
3546 mandeep.dh 313
                searchFilter
314
                        .setTicketCategory(TicketCategory.valueOf(category));
3499 mandeep.dh 315
            }
316
 
3546 mandeep.dh 317
            crmServiceClient = new CRMClient().getClient();
3405 mandeep.dh 318
            tickets = crmServiceClient.getTickets(searchFilter);
3137 mandeep.dh 319
        } catch (TException e) {
320
            String errorString = "Error getting tickets for "
321
                    + currentAgentEmailId;
322
            log.error(errorString, e);
323
            addActionError(errorString);
324
        }
325
 
3405 mandeep.dh 326
        return index();
3137 mandeep.dh 327
    }
328
 
329
    public String getUnassignedTickets() {
330
        try {
3546 mandeep.dh 331
            crmServiceClient = new CRMClient().getClient();
3137 mandeep.dh 332
            tickets = crmServiceClient.getUnassignedTickets();
333
        } catch (TException e) {
3339 mandeep.dh 334
            String errorString = "Error getting tickets for "
335
                    + currentAgentEmailId;
3137 mandeep.dh 336
            log.error(errorString, e);
337
            addActionError(errorString);
338
        }
339
 
3405 mandeep.dh 340
        return index();
3137 mandeep.dh 341
    }
342
 
3405 mandeep.dh 343
    public String update() {
344
        try {
345
            long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
346
                    .getId();
347
 
3546 mandeep.dh 348
            SearchFilter searchFilter = new SearchFilter();
349
            searchFilter.setTicketId(Long.parseLong(id));
350
            crmServiceClient = new CRMClient().getClient();
351
            Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
3405 mandeep.dh 352
            ticket.setDescription(description);
353
            ticket.setPriority(TicketPriority.valueOf(priority));
354
 
355
            // Update when a ticket is closed!
3578 mandeep.dh 356
            if (TicketStatus.CLOSED.name().equals(status) || TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
3546 mandeep.dh 357
                if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())
358
                        && pendingCODOrders(ticket.getCustomerId())) {
359
                    addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");
360
                } else {
361
                    ticket.setCategory(TicketCategory.valueOf(category));
362
                    ticket.setStatus(TicketStatus.valueOf(status));
363
                    ticket.setCloseDate(new Date().getTime());
364
                }
3405 mandeep.dh 365
            }
3546 mandeep.dh 366
            else {
367
                ticket.setCategory(TicketCategory.valueOf(category));
3578 mandeep.dh 368
                ticket.setStatus(TicketStatus.valueOf(status));
3546 mandeep.dh 369
            }
3405 mandeep.dh 370
 
371
            if (activityDescription == null || activityDescription.isEmpty()) {
372
                activityDescription = "Updating ticket fields";
373
            }
374
 
375
            Activity activity = new Activity();
376
            activity.setDescription(activityDescription);
377
            activity.setType(ActivityType.valueOf(activityType));
3546 mandeep.dh 378
            activity.setTicketPriority(ticket.getPriority());
379
            activity.setTicketStatus(ticket.getStatus());
3405 mandeep.dh 380
            activity.setCreatorId(creatorId);
3546 mandeep.dh 381
            activity.setTicketCategory(ticket.getCategory());
382
            activity.setTicketDescription(ticket.getDescription());
3405 mandeep.dh 383
 
384
            if (userId != null && !userId.isEmpty()) {
385
                activity.setCustomerId(Long.parseLong(userId));
386
            }
387
 
388
            if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
389
                log.info("Sending mail");
390
                Client helperClient = new HelperClient().getClient();
391
                activity.setUserEmailId(helperClient.saveUserEmailForSending(
3546 mandeep.dh 392
                        customerEmailId, CRMConstants.CRM_EMAIL_SENDOR,
393
                        subject, body, null, CRMConstants.CRM_EMAIL_TYPE));
3405 mandeep.dh 394
 
395
                // We change activityType to OTHER when pop up box for email
396
                // closes
397
                activity.setDescription("Subject: " + subject + "\n\n"
398
                        + "Body: " + body);
399
            }
400
 
401
            // handling null values appropriately
402
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
3546 mandeep.dh 403
                long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
404
                        .getId();
3405 mandeep.dh 405
                ticket.setAssigneeId(assigneeId);
406
                activity.setTicketAssigneeId(assigneeId);
407
            }
408
 
409
            User user = null;
410
            userContextServiceClient = new UserClient().getClient();
411
            try {
412
                if (customerName != null && !customerName.isEmpty()) {
413
                    ticket.setCustomerName(customerName);
414
                    activity.setCustomerName(customerName);
415
                }
416
 
417
                if (customerEmailId != null && !customerEmailId.isEmpty()) {
418
                    ticket.setCustomerEmailId(customerEmailId);
419
                    activity.setCustomerEmailId(customerEmailId);
3546 mandeep.dh 420
                    user = userContextServiceClient
421
                            .getUserByEmail(customerEmailId);
3405 mandeep.dh 422
                }
423
 
3546 mandeep.dh 424
                if ((user == null || user.getUserId() == -1)
425
                        && customerMobileNumber != null
426
                        && !customerMobileNumber.isEmpty()) {
3405 mandeep.dh 427
                    ticket.setCustomerMobileNumber(customerMobileNumber);
428
                    activity.setCustomerMobileNumber(customerMobileNumber);
3546 mandeep.dh 429
                    user = userContextServiceClient.getUserByMobileNumber(Long
430
                            .parseLong(customerMobileNumber));
3405 mandeep.dh 431
                }
432
            } catch (UserContextException e) {
433
                log.error("Could not fetch user for: " + customerEmailId + " "
434
                        + customerMobileNumber + " " + customerName, e);
435
            }
3546 mandeep.dh 436
 
3405 mandeep.dh 437
            if (user != null && user.getUserId() != -1) {
438
                ticket.setCustomerId(user.getUserId());
439
                activity.setCustomerId(user.getUserId());
440
            }
441
 
442
            crmServiceClient = new CRMClient().getClient();
443
            crmServiceClient.updateTicket(ticket, activity);
444
        } catch (TException e) {
445
            log.error("Error while updating ticket", e);
446
            return EXCEPTION;
447
        } catch (HelperServiceException hse) {
448
            log.error("Error while sending mail", hse);
449
            return EXCEPTION;
450
        }
451
 
452
        return index();
453
    }
454
 
3546 mandeep.dh 455
    private boolean pendingCODOrders(long customerId) {
456
        try {
457
            log.info("Trying to fetch orders for " + customerId);
458
            transactionServiceClient = new TransactionClient().getClient();
459
            for (Order order : transactionServiceClient.getOrdersForCustomer(
460
                    customerId, 0, 0,
461
                    Collections.singletonList(OrderStatus.INIT))) {
462
                log.info("Processing order: " + order.getId() + " with COD: " + order.isCod());
463
                if (order.isCod()) {
464
                    log.info("Returning true from pendingCODOrders() for " + customerId);
465
                    return true;
466
                }
467
            }
468
        } catch (TTransportException e) {
469
            log.error("Error while creating thrift client", e);
470
        } catch (TransactionServiceException e) {
471
            log.error("Error fetching orders", e);
472
        } catch (TException e) {
473
            log.error("Error fetching orders", e);
474
        }
475
 
476
        log.info("Returning false from pendingCODOrders() for " + customerId);
477
        return false;
478
    }
479
 
480
    public String updateOrderStatus() throws NumberFormatException,
481
            TransactionServiceException, TException {
482
        long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
483
                .getId();
484
 
3578 mandeep.dh 485
        OrderStatus orderStatusEnum = OrderStatus.valueOf(orderStatus);
3546 mandeep.dh 486
        transactionServiceClient = new TransactionClient().getClient();
487
 
3578 mandeep.dh 488
        if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {
489
            transactionServiceClient.verifyOrder(Long.parseLong(orderId));
490
        }
491
        else if (OrderStatus.CANCELED.equals(orderStatusEnum)) {
492
            transactionServiceClient.refundOrder(Long.parseLong(orderId), currentAgentEmailId, "COD - Cancelled");
493
        }
494
        else {
495
            throw new UnsupportedOperationException("Cannot update status of orderId: " + orderId + " to: " + orderStatus);
496
        }
497
 
3546 mandeep.dh 498
        SearchFilter searchFilter = new SearchFilter();
499
        searchFilter.setTicketId(Long.parseLong(id));
500
        crmServiceClient = new CRMClient().getClient();
501
        Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
502
 
503
        // Inserting activity
504
        Activity activity = new Activity();
505
        activity.setDescription("Updating status for Order Id: " + orderId
506
                + " to " + orderStatus);
507
        activity.setType(ActivityType.OTHER);
508
        activity.setTicketPriority(ticket.getPriority());
509
        activity.setTicketStatus(ticket.getStatus());
510
        activity.setCreatorId(creatorId);
511
        activity.setTicketCategory(ticket.getCategory());
512
        activity.setTicketDescription(ticket.getDescription());
513
        activity.setCustomerId(ticket.getCustomerId());
514
        activity.setTicketAssigneeId(ticket.getAssigneeId());
515
 
516
        crmServiceClient = new CRMClient().getClient();
517
        crmServiceClient.updateTicket(ticket, activity);
518
 
519
        return edit();
520
    }
521
 
3137 mandeep.dh 522
    public User getUser(Long userId) {
523
        User user = null;
524
 
525
        try {
3390 mandeep.dh 526
            userContextServiceClient = new UserClient().getClient();
3137 mandeep.dh 527
            user = userContextServiceClient.getUserById(userId);
528
        } catch (UserContextException e) {
529
            String errorString = "Could not fetch user for " + userId;
530
            log.error(errorString, e);
531
            addActionError(errorString);
532
        } catch (TException e) {
533
            String errorString = "Could not create client";
534
            log.error(errorString, e);
535
            addActionError(errorString);
536
        }
537
 
538
        return user;
539
    }
540
 
3546 mandeep.dh 541
    public String getAddress(Order order) {
542
        return ModelUtils.extractAddressFromOrder(order);
543
    }
544
 
545
    public String getProductName(LineItem lineItem) {
4008 mandeep.dh 546
        return ModelUtils.extractProductNameFromLineItem(lineItem) + " " + lineItem.getColor();
3546 mandeep.dh 547
    }
548
 
3405 mandeep.dh 549
    public ActivityType[] getActivityTypes() {
550
        return ActivityType.values();
551
    }
552
 
553
    public TicketStatus[] getTicketStatuses() {
554
        return TicketStatus.values();
555
    }
556
 
3390 mandeep.dh 557
    public Agent getAgent(long agentId) throws TException {
558
        return CRMAuthorizingRealm.getAgent(agentId);
3137 mandeep.dh 559
    }
560
 
3339 mandeep.dh 561
    public List<Agent> getAllAgents() {
3390 mandeep.dh 562
        return CRMAuthorizingRealm.getAgents();
3339 mandeep.dh 563
    }
564
 
565
    public TicketCategory[] getTicketCategories() {
566
        return TicketCategory.values();
567
    }
568
 
569
    public TicketPriority[] getTicketPriorities() {
570
        return TicketPriority.values();
571
    }
572
 
3137 mandeep.dh 573
    public List<Ticket> getTickets() {
574
        return tickets;
575
    }
576
 
577
    public void setTickets(List<Ticket> tickets) {
578
        this.tickets = tickets;
579
    }
3339 mandeep.dh 580
 
3405 mandeep.dh 581
    public String getCustomerEmailId() {
582
        return customerEmailId;
3339 mandeep.dh 583
    }
584
 
3405 mandeep.dh 585
    public void setCustomerEmailId(String customerEmailId) {
586
        this.customerEmailId = customerEmailId;
3339 mandeep.dh 587
    }
588
 
589
    public String getDescription() {
590
        return description;
591
    }
592
 
593
    public void setDescription(String description) {
594
        this.description = description;
595
    }
596
 
597
    public String getAssigneeEmailId() {
598
        return assigneeEmailId;
599
    }
600
 
601
    public void setAssigneeEmailId(String assigneeEmailId) {
602
        this.assigneeEmailId = assigneeEmailId;
603
    }
604
 
605
    public String getPriority() {
606
        return priority;
607
    }
608
 
609
    public void setPriority(String priority) {
610
        this.priority = priority;
611
    }
612
 
613
    public String getCategory() {
614
        return category;
615
    }
616
 
617
    public void setCategory(String category) {
618
        this.category = category;
619
    }
620
 
621
    public String getOrderId() {
622
        return orderId;
623
    }
624
 
625
    public void setOrderId(String orderId) {
626
        this.orderId = orderId;
627
    }
3397 mandeep.dh 628
 
629
    public String[] getAgentIds() {
630
        return agentIds;
631
    }
632
 
633
    public void setAgentIds(String[] agentIds) {
634
        this.agentIds = agentIds;
635
    }
636
 
637
    public String getStartTimestamp() {
638
        return startTimestamp;
639
    }
640
 
641
    public void setStartTimestamp(String startTimestamp) {
642
        this.startTimestamp = startTimestamp;
643
    }
644
 
645
    public String getEndTimestamp() {
646
        return endTimestamp;
647
    }
648
 
649
    public void setEndTimestamp(String endTimestamp) {
650
        this.endTimestamp = endTimestamp;
651
    }
3405 mandeep.dh 652
 
653
    public String getUserId() {
654
        return userId;
655
    }
656
 
657
    public void setUserId(String userId) {
658
        this.userId = userId;
659
    }
660
 
661
    public String getId() {
662
        return id;
663
    }
664
 
665
    public void setId(String id) {
666
        this.id = id;
667
    }
668
 
669
    public String getActivityDescription() {
670
        return activityDescription;
671
    }
672
 
673
    public void setActivityDescription(String activityDescription) {
674
        this.activityDescription = activityDescription;
675
    }
676
 
677
    public String getStatus() {
678
        return status;
679
    }
680
 
681
    public void setStatus(String status) {
682
        this.status = status;
683
    }
684
 
685
    public String getActivityType() {
686
        return activityType;
687
    }
688
 
689
    public void setActivityType(String activityType) {
690
        this.activityType = activityType;
691
    }
692
 
693
    public Ticket getTicket() {
694
        return ticket;
695
    }
696
 
697
    public void setTicket(Ticket ticket) {
698
        this.ticket = ticket;
699
    }
700
 
701
    public List<Activity> getActivities() {
702
        return activities;
703
    }
704
 
705
    public void setActivities(List<Activity> activities) {
706
        this.activities = activities;
707
    }
708
 
709
    public String getSubject() {
710
        return subject;
711
    }
712
 
713
    public void setSubject(String subject) {
714
        this.subject = subject;
715
    }
716
 
717
    public String getBody() {
718
        return body;
719
    }
720
 
721
    public void setBody(String body) {
722
        this.body = body;
723
    }
724
 
725
    public String getCustomerName() {
726
        return customerName;
727
    }
728
 
729
    public void setCustomerName(String customerName) {
730
        this.customerName = customerName;
731
    }
732
 
733
    public String getCustomerMobileNumber() {
734
        return customerMobileNumber;
735
    }
736
 
737
    public void setCustomerMobileNumber(String customerMobileNumber) {
738
        this.customerMobileNumber = customerMobileNumber;
739
    }
3546 mandeep.dh 740
 
741
    public User getUser() {
742
        return user;
743
    }
744
 
745
    public void setUser(User user) {
746
        this.user = user;
747
    }
748
 
749
    public String getOrderStatus() {
750
        return orderStatus;
751
    }
752
 
753
    public void setOrderStatus(String orderStatus) {
754
        this.orderStatus = orderStatus;
755
    }
756
 
757
    public List<Order> getOrders() {
758
        return orders;
759
    }
760
 
761
    public void setOrders(List<Order> orders) {
762
        this.orders = orders;
763
    }
3137 mandeep.dh 764
}