Subversion Repositories SmartDukaan

Rev

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