Subversion Repositories SmartDukaan

Rev

Rev 3234 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3234 Rev 3269
Line 33... Line 33...
33
public class UserTicketsController extends BaseController {
33
public class UserTicketsController extends BaseController {
34
    private static final String AGENT      = "Agent";
34
    private static final String AGENT      = "Agent";
35
 
35
 
36
    private Map<Long, Ticket>   ticketsMap = new HashMap<Long, Ticket>();
36
    private Map<Long, Ticket>   ticketsMap = new HashMap<Long, Ticket>();
37
 
37
 
38
    private long                userId;
38
    private String              userId;
39
    private String              userEmailId;
39
    private String              userEmailId;
40
    private String              id;
40
    private String              id;
41
    private String              activityDescription;
41
    private String              activityDescription;
42
    private String              description;
42
    private String              description;
43
    private String              assigneeEmailId;
43
    private String              assigneeEmailId;
Line 52... Line 52...
52
    private String              body;
52
    private String              body;
53
 
53
 
54
    public String index() {
54
    public String index() {
55
        try {
55
        try {
56
            createServiceClients();
56
            createServiceClients();
57
            List<Ticket> ticketsList = crmServiceClient.getTickets(userId);
57
            List<Ticket> ticketsList = crmServiceClient.getTickets(Long.parseLong(userId));
58
            if (ticketsList != null) {
58
            if (ticketsList != null) {
59
                for (Ticket ticket : ticketsList) {
59
                for (Ticket ticket : ticketsList) {
60
                    ticketsMap.put(ticket.getId(), ticket);
60
                    ticketsMap.put(ticket.getId(), ticket);
61
                }
61
                }
62
            }
62
            }
Line 83... Line 83...
83
            ticket.setStatus(TicketStatus.valueOf(status));
83
            ticket.setStatus(TicketStatus.valueOf(status));
84
 
84
 
85
            // Update when a ticket is closed!
85
            // Update when a ticket is closed!
86
            if (TicketStatus.CLOSED.name().equals(status)) {
86
            if (TicketStatus.CLOSED.name().equals(status)) {
87
                ticket.setCloseDate(new Date().getTime());
87
                ticket.setCloseDate(new Date().getTime());
88
            } else {
88
            }
-
 
89
 
-
 
90
            if (activityDescription == null || activityDescription.isEmpty()) {
89
                ticket.setCloseDateIsSet(false);
91
                activityDescription = "Updating ticket fields";
90
            }
92
            }
91
 
93
 
92
            Activity activity = new Activity();
94
            Activity activity = new Activity();
93
            activity.setDescription(activityDescription);
95
            activity.setDescription(activityDescription);
94
            activity.setCustomerId(userId);
-
 
95
            activity.setType(ActivityType.valueOf(activityType));
96
            activity.setType(ActivityType.valueOf(activityType));
96
            activity.setTicketPriority(TicketPriority.valueOf(priority));
97
            activity.setTicketPriority(TicketPriority.valueOf(priority));
97
            activity.setTicketStatus(TicketStatus.valueOf(status));
98
            activity.setTicketStatus(TicketStatus.valueOf(status));
98
            activity.setCreatorId(creatorId);
99
            activity.setCreatorId(creatorId);
99
            activity.setTicketCategory(TicketCategory.valueOf(category));
100
            activity.setTicketCategory(TicketCategory.valueOf(category));
100
            activity.setTicketDescription(description);
101
            activity.setTicketDescription(description);
101
 
102
 
-
 
103
            if (userId != null && !userId.isEmpty()) {
-
 
104
                activity.setCustomerId(Long.parseLong(userId));
-
 
105
            }
-
 
106
 
102
            log.info(activityType);
107
            log.info(activityType);
103
            if (ActivityType.EMAIL_CUSTOMER.equals(activity.getType())) {
108
            if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
104
                log.info("Sending mail");
109
                log.info("Sending mail");
105
                Client helperClient = new HelperClient().getClient();
110
                Client helperClient = new HelperClient().getClient();
106
                activity.setEmailId(helperClient.saveUserEmailForSending(
111
                activity.setEmailId(helperClient.saveUserEmailForSending(
107
                        userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
112
                        userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
108
                        body, null, CRMConstants.CRM_EMAIL_TYPE));
113
                        body, null, CRMConstants.CRM_EMAIL_TYPE));
109
 
114
 
110
                // We change activityType to OTHER when pop up box for email
115
                // We change activityType to OTHER when pop up box for email
111
                // closes
116
                // closes
112
                activity.setDescription("Subject: " + subject + "\n\n" + "Body: " + body);
117
                activity.setDescription("Subject: " + subject + "\n\n"
-
 
118
                        + "Body: " + body);
113
            }
119
            }
114
 
120
 
115
            // handling null values appropriately
121
            // handling null values appropriately
116
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
122
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
117
                long assigneeId = crmServiceClient.getAgentByEmailId(
123
                long assigneeId = crmServiceClient.getAgentByEmailId(
Line 125... Line 131...
125
 
131
 
126
            crmServiceClient.updateTicket(ticket, activity);
132
            crmServiceClient.updateTicket(ticket, activity);
127
        } catch (TException e) {
133
        } catch (TException e) {
128
            log.error("Error while updating ticket", e);
134
            log.error("Error while updating ticket", e);
129
            return EXCEPTION;
135
            return EXCEPTION;
130
        }
-
 
131
        catch (HelperServiceException hse) {
136
        } catch (HelperServiceException hse) {
132
            log.error("Error while sending mail", hse);
137
            log.error("Error while sending mail", hse);
133
            return EXCEPTION;
138
            return EXCEPTION;
134
        }
139
        }
135
 
140
 
136
        return index();
141
        return index();
Line 141... Line 146...
141
            createServiceClients();
146
            createServiceClients();
142
            long ticketId = Long.parseLong(id);
147
            long ticketId = Long.parseLong(id);
143
            ticket = crmServiceClient.getTicket(ticketId);
148
            ticket = crmServiceClient.getTicket(ticketId);
144
            activities = crmServiceClient.getActivitiesForTicket(ticketId);
149
            activities = crmServiceClient.getActivitiesForTicket(ticketId);
145
            subject = createSubjectString(ticket);
150
            subject = createSubjectString(ticket);
-
 
151
            userId = String.valueOf(ticket.getCustomerId());
146
            userId = ticket.getCustomerId();
152
            userEmailId = ticket.getCustomerEmailId();
147
        } catch (TException e) {
153
        } catch (TException e) {
148
            log.error("Error while loading edit page", e);
154
            log.error("Error while loading edit page", e);
149
            return EXCEPTION;
155
            return EXCEPTION;
150
        }
156
        }
151
 
157
 
Line 160... Line 166...
160
    public Map<Long, Ticket> getTickets() {
166
    public Map<Long, Ticket> getTickets() {
161
        return ticketsMap;
167
        return ticketsMap;
162
    }
168
    }
163
 
169
 
164
    public User getUser() throws UserContextException, TException {
170
    public User getUser() throws UserContextException, TException {
165
        return userContextServiceClient.getUserById(userId);
171
        return userContextServiceClient.getUserById(Long.parseLong(userId));
166
    }
172
    }
167
 
173
 
168
    public Agent getAgent(long agentId) {
174
    public Agent getAgent(long agentId) {
169
        Agent agent = null;
175
        Agent agent = null;
170
 
176
 
Line 188... Line 194...
188
    }
194
    }
189
 
195
 
190
    public String create() {
196
    public String create() {
191
        try {
197
        try {
192
            createServiceClients();
198
            createServiceClients();
193
            long creatorId = crmServiceClient.getAgentByEmailId(
199
            long creatorId = crmServiceClient.getAgentByEmailId(currentAgentEmailId).getId();
194
                    currentAgentEmailId).getId();
-
 
195
            Ticket ticket = new Ticket();
200
            Ticket ticket = new Ticket();
196
            ticket.setDescription(description);
201
            ticket.setDescription(description);
197
            ticket.setCustomerId(userId);
-
 
198
            ticket.setCreatorId(creatorId);
202
            ticket.setCreatorId(creatorId);
199
 
-
 
200
            if (orderId == null || orderId.isEmpty()) {
-
 
201
                ticket.setOrderIdIsSet(false);
-
 
202
            } else {
-
 
203
                ticket.setOrderId(Long.parseLong(orderId));
-
 
204
            }
-
 
205
 
-
 
206
            ticket.setStatus(TicketStatus.OPEN);
203
            ticket.setStatus(TicketStatus.OPEN);
207
            ticket.setPriority(TicketPriority.valueOf(priority));
204
            ticket.setPriority(TicketPriority.valueOf(priority));
208
            ticket.setCategory(TicketCategory.valueOf(category));
205
            ticket.setCategory(TicketCategory.valueOf(category));
209
 
206
            
210
            Activity activity = new Activity();
207
            Activity activity = new Activity();
211
            // At creation of ticket activity's description is same as that of
208
            // At creation of ticket activity's description is same as that of
212
            // ticket
209
            // ticket
213
            activity.setDescription(description);
210
            activity.setDescription("Creating Ticket");
214
            activity.setCustomerId(userId);
-
 
215
            activity.setType(ActivityType.OTHER);
211
            activity.setType(ActivityType.OTHER);
216
            activity.setTicketPriority(TicketPriority.valueOf(priority));
212
            activity.setTicketPriority(TicketPriority.valueOf(priority));
217
            activity.setTicketStatus(TicketStatus.OPEN);
213
            activity.setTicketStatus(TicketStatus.OPEN);
218
            activity.setCreatorId(creatorId);
214
            activity.setCreatorId(creatorId);
219
            activity.setTicketCategory(TicketCategory.valueOf(category));
215
            activity.setTicketCategory(TicketCategory.valueOf(category));
220
            activity.setTicketDescription(description);
216
            activity.setTicketDescription(description);
221
 
217
 
-
 
218
            if (userEmailId != null && !userEmailId.isEmpty()) {
-
 
219
                ticket.setCustomerEmailId(userEmailId);
-
 
220
            }
-
 
221
 
-
 
222
            if (orderId != null && !orderId.isEmpty()) {
-
 
223
                ticket.setOrderId(Long.parseLong(orderId));
-
 
224
            }
-
 
225
 
-
 
226
            if (userId != null && !userId.isEmpty()) {
-
 
227
                ticket.setCustomerId(Long.parseLong(userId));
-
 
228
                activity.setCustomerId(Long.parseLong(userId));
-
 
229
            }
-
 
230
 
222
            // handling null values appropriately
231
            // handling null values appropriately
223
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
232
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
224
                long assigneeId = crmServiceClient.getAgentByEmailId(
233
                long assigneeId = crmServiceClient.getAgentByEmailId(assigneeEmailId).getId();
225
                        assigneeEmailId).getId();
-
 
226
                ticket.setAssigneeId(assigneeId);
234
                ticket.setAssigneeId(assigneeId);
227
                activity.setTicketAssigneeId(assigneeId);
235
                activity.setTicketAssigneeId(assigneeId);
228
            } else {
-
 
229
                ticket.setAssigneeIdIsSet(false);
-
 
230
                activity.setTicketAssigneeIdIsSet(false);
-
 
231
            }
236
            }
232
 
237
 
233
            crmServiceClient.insertTicket(ticket, activity);
238
            crmServiceClient.insertTicket(ticket, activity);
234
            
-
 
235
        } catch (TException e) {
239
        } catch (TException e) {
236
            log.error("Error while creating ticket", e);
240
            log.error("Error while creating ticket", e);
237
            return EXCEPTION;
241
            return EXCEPTION;
238
        }
242
        }
239
 
243
 
Line 277... Line 281...
277
    public Map<Long, Ticket> getTicketsMap() {
281
    public Map<Long, Ticket> getTicketsMap() {
278
        return ticketsMap;
282
        return ticketsMap;
279
    }
283
    }
280
 
284
 
281
    public void setUserId(String userId) {
285
    public void setUserId(String userId) {
282
        this.userId = Long.parseLong(userId);
286
        this.userId = userId;
283
    }
287
    }
284
 
288
 
285
    public void setOrderId(String orderId) {
289
    public void setOrderId(String orderId) {
286
        this.orderId = orderId;
290
        this.orderId = orderId;
287
    }
291
    }
288
 
292
 
289
    public long getUserId() {
293
    public String getUserId() {
290
        return userId;
294
        return userId;
291
    }
295
    }
292
 
296
 
293
    public void setUserId(long userId) {
-
 
294
        this.userId = userId;
-
 
295
    }
-
 
296
 
-
 
297
    public String getId() {
297
    public String getId() {
298
        return id;
298
        return id;
299
    }
299
    }
300
 
300
 
301
    public void setId(String id) {
301
    public void setId(String id) {