Subversion Repositories SmartDukaan

Rev

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