Subversion Repositories SmartDukaan

Rev

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

Rev 3090 Rev 3106
Line 2... Line 2...
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
import in.shop2020.crm.Activity;
6
import in.shop2020.crm.Activity;
-
 
7
import in.shop2020.crm.ActivityType;
7
import in.shop2020.crm.Agent;
8
import in.shop2020.crm.Agent;
8
import in.shop2020.crm.ContactMedium;
-
 
9
import in.shop2020.crm.Ticket;
9
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.TicketCategory;
10
import in.shop2020.crm.TicketCategory;
11
import in.shop2020.crm.TicketPriority;
11
import in.shop2020.crm.TicketPriority;
12
import in.shop2020.crm.TicketStatus;
12
import in.shop2020.crm.TicketStatus;
13
import in.shop2020.model.v1.user.User;
13
import in.shop2020.model.v1.user.User;
Line 20... Line 20...
20
 
20
 
21
import org.apache.thrift.TException;
21
import org.apache.thrift.TException;
22
 
22
 
23
/**
23
/**
24
 * Action class for ticket pages in CRM tool.
24
 * Action class for ticket pages in CRM tool.
25
 *
25
 * 
26
 * @author mandeep
26
 * @author mandeep
27
 */
27
 */
28
@SuppressWarnings("serial")
28
@SuppressWarnings("serial")
29
public class UserTicketsController extends BaseController {
29
public class UserTicketsController extends BaseController {
-
 
30
    private static final String AGENT = "Agent";
-
 
31
 
30
    private Map<Long, Ticket> ticketsMap = new HashMap<Long, Ticket>();
32
    private Map<Long, Ticket> ticketsMap = new HashMap<Long, Ticket>();
31
 
33
 
32
    private long              userId;
34
    private long              userId;
33
    private String            id;
35
    private String            id;
34
    private String            subject;
36
    private String            activityDescription;
35
    private String            description;
37
    private String            description;
36
    private String            ticketAssigneeEmailId;
38
    private String            assigneeEmailId;
37
    private String            ticketStatus;
39
    private String            status;
38
    private String            ticketPriority;
40
    private String            priority;
39
    private String            ticketCategory;
41
    private String            category;
40
    private String            contactMedium;
-
 
41
    private String            contactTimestamp;
42
    private String            activityType;
42
    private String            contactingAgentEmailId;
-
 
43
    private Ticket            ticket;
43
    private Ticket            ticket;
44
    private Activity          lastActivity;
-
 
45
    private List<Activity>    activities;
44
    private List<Activity>    activities;
46
    private long              orderId;
45
    private String            orderId;
47
 
46
 
48
    public String index() throws Exception {
47
    public String index() {
-
 
48
        try {
49
        createServiceClients();
49
            createServiceClients();
50
        List<Ticket> ticketsList = crmServiceClient.getTickets(userId);
50
            List<Ticket> ticketsList = crmServiceClient.getTickets(userId);
51
        if (ticketsList != null) {
51
            if (ticketsList != null) {
52
            for (Ticket ticket : ticketsList) {
52
                for (Ticket ticket : ticketsList) {
53
                ticketsMap.put(ticket.getId(), ticket);
53
                    ticketsMap.put(ticket.getId(), ticket);
-
 
54
                }
54
            }
55
            }
-
 
56
        } catch (TException e) {
-
 
57
            log.error("Error while getting tickets", e);
-
 
58
            return EXCEPTION;
55
        }
59
        }
56
 
-
 
57
        return INDEX;
60
        return INDEX;
58
    }
61
    }
59
 
62
 
60
    public String editNew() {
63
    public String update() {
61
        contactTimestamp = SDF.format(new Date());
64
        try {
62
        return EDIT_NEW;
65
            createServiceClients();
63
    }
-
 
64
 
66
 
65
    public String update() throws Exception {
67
            long creatorId = crmServiceClient.getAgentByEmailId(
66
        createServiceClients();
68
                    currentAgentEmailId).getId();
67
 
69
 
68
        // Only subject and close date are editable fields for a ticket
70
            // Only subject and close date are editable fields for a ticket
69
        Ticket ticket = new Ticket();
71
            Ticket ticket = new Ticket();
70
        ticket.setId(Long.parseLong(id));
72
            ticket.setId(Long.parseLong(id));
71
        ticket.setSubject(subject);
73
            ticket.setDescription(description);
-
 
74
            ticket.setCategory(TicketCategory.valueOf(category));
-
 
75
            ticket.setPriority(TicketPriority.valueOf(priority));
-
 
76
            ticket.setStatus(TicketStatus.valueOf(status));
72
 
77
 
73
        // Update when a ticket is closed!
78
            // Update when a ticket is closed!
74
        if (TicketStatus.CLOSED.name().equals(ticketStatus)) {
79
            if (TicketStatus.CLOSED.name().equals(status)) {
75
            ticket.setCloseDate(new Date().getTime());
80
                ticket.setCloseDate(new Date().getTime());
-
 
81
            } else {
-
 
82
                ticket.setCloseDateIsSet(false);
76
        }
83
            }
77
 
84
 
78
        Activity activity = new Activity();
85
            Activity activity = new Activity();
79
        long creatorId = crmServiceClient.getAgentByEmailId(currentAgentEmailId).getId();
86
            activity.setDescription(activityDescription);
80
        activity.setContactingAgentId(creatorId);
87
            activity.setCustomerId(userId);
81
        activity.setDescription(description);
88
            activity.setType(ActivityType.valueOf(activityType));
82
        activity.setContactMedium(ContactMedium.valueOf(contactMedium));
89
            activity.setTicketPriority(TicketPriority.valueOf(priority));
83
        activity.setTicketAssigneeId(crmServiceClient.getAgentByEmailId(
90
            activity.setTicketStatus(TicketStatus.valueOf(status));
84
                ticketAssigneeEmailId).getId());
91
            activity.setCreatorId(creatorId);
85
        activity.setTicketPriority(TicketPriority.valueOf(ticketPriority));
92
            activity.setTicketCategory(TicketCategory.valueOf(category));
86
        activity.setTicketStatus(TicketStatus.valueOf(ticketStatus));
93
            activity.setTicketDescription(description);
-
 
94
 
-
 
95
            // handling null values appropriately
87
        activity.setContactTimestamp(SDF.parse(contactTimestamp).getTime());
96
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
-
 
97
                long assigneeId = crmServiceClient.getAgentByEmailId(
-
 
98
                        assigneeEmailId).getId();
-
 
99
                ticket.setAssigneeId(assigneeId);
88
        activity.setCreatorId(creatorId);
100
                activity.setTicketAssigneeId(assigneeId);
-
 
101
            } else {
-
 
102
                ticket.setAssigneeIdIsSet(false);
89
        activity.setTicketCategory(TicketCategory.valueOf(ticketCategory));
103
                activity.setTicketAssigneeIdIsSet(false);
-
 
104
            }
90
 
105
 
91
        crmServiceClient.updateTicket(ticket);
106
            crmServiceClient.updateTicket(ticket);
92
        activity.setTicketId(ticket.getId());
107
            activity.setTicketId(ticket.getId());
93
        crmServiceClient.insertActivity(activity);
108
            crmServiceClient.insertActivity(activity);
-
 
109
        } catch (TException e) {
-
 
110
            log.error("Error while updating ticket", e);
-
 
111
            return EXCEPTION;
-
 
112
        }
94
 
113
 
95
        return index();
114
        return index();
96
    }
115
    }
97
 
116
 
98
    public String edit() throws TException, UserContextException {
117
    public String edit() {
-
 
118
        try {
99
        createServiceClients();
119
            createServiceClients();
100
        long ticketId = Long.parseLong(id);
120
            long ticketId = Long.parseLong(id);
101
        ticket = crmServiceClient.getTicket(ticketId);
121
            ticket = crmServiceClient.getTicket(ticketId);
102
        lastActivity = crmServiceClient.getLastActivity(ticketId);
122
            activities = crmServiceClient.getActivitiesForTicket(Long
103
        activities = crmServiceClient.getActivitiesForTicket(Long.parseLong(id));
123
                    .parseLong(id));
-
 
124
        } catch (TException e) {
104
        contactTimestamp = SDF.format(new Date());
125
            log.error("Error while loading edit page", e);
-
 
126
            return EXCEPTION;
-
 
127
        }
-
 
128
 
105
        return EDIT;
129
        return EDIT;
106
    }
130
    }
107
 
131
 
108
    public Map<Long, Ticket> getTickets() {
132
    public Map<Long, Ticket> getTickets() {
109
        return ticketsMap;
133
        return ticketsMap;
Line 111... Line 135...
111
 
135
 
112
    public User getUser() throws UserContextException, TException {
136
    public User getUser() throws UserContextException, TException {
113
        return userContextServiceClient.getUserById(userId);
137
        return userContextServiceClient.getUserById(userId);
114
    }
138
    }
115
 
139
 
116
    public Activity getLastActivity(long ticketId) throws TException {
-
 
117
        return crmServiceClient.getLastActivity(ticketId);
-
 
118
    }
-
 
119
 
-
 
120
    public Agent getAgent(long agentId) throws TException {
140
    public Agent getAgent(long agentId) throws TException {
121
        return crmServiceClient.getAgent(agentId);
141
        return crmServiceClient.getAgent(agentId);
122
    }
142
    }
123
 
143
 
124
    public TicketStatus[] getTicketStatuses() {
144
    public TicketStatus[] getTicketStatuses() {
Line 127... Line 147...
127
 
147
 
128
    public TicketPriority[] getTicketPriorities() {
148
    public TicketPriority[] getTicketPriorities() {
129
        return TicketPriority.values();
149
        return TicketPriority.values();
130
    }
150
    }
131
 
151
 
132
    public ContactMedium[] getContactMedia() {
152
    public String create() {
-
 
153
        try {
133
        return ContactMedium.values();
154
            createServiceClients();
-
 
155
            long creatorId = crmServiceClient.getAgentByEmailId(
-
 
156
                    currentAgentEmailId).getId();
-
 
157
            Ticket ticket = new Ticket();
-
 
158
            ticket.setDescription(description);
-
 
159
            ticket.setCustomerId(userId);
-
 
160
            ticket.setCreatorId(creatorId);
-
 
161
 
-
 
162
            if (orderId == null || orderId.isEmpty()) {
-
 
163
                ticket.setOrderIdIsSet(false);
-
 
164
            }
-
 
165
            else {
-
 
166
                ticket.setOrderId(Long.parseLong(orderId));
134
    }
167
            }
135
 
168
 
136
    public String create() throws Exception {
169
            ticket.setStatus(TicketStatus.OPEN);
137
        createServiceClients();
170
            ticket.setPriority(TicketPriority.valueOf(priority));
138
        long creatorId = crmServiceClient.getAgentByEmailId(currentAgentEmailId).getId();
171
            ticket.setCategory(TicketCategory.valueOf(category));
-
 
172
 
139
        Ticket ticket = new Ticket();
173
            Activity activity = new Activity();
140
        ticket.setOpenDate(new Date().getTime());
174
            // At creation of ticket activity's description is same as that of
-
 
175
            // ticket
141
        ticket.setSubject(subject);
176
            activity.setDescription(description);
142
        ticket.setCustomerId(userId);
177
            activity.setCustomerId(userId);
143
        ticket.setCreatorId(creatorId);
178
            activity.setType(ActivityType.OTHER);
144
        ticket.setOrderId(creatorId);
179
            activity.setTicketPriority(TicketPriority.valueOf(priority));
145
 
-
 
146
        Activity activity = new Activity();
180
            activity.setTicketStatus(TicketStatus.OPEN);
147
        activity.setCustomerId(userId);
181
            activity.setCreatorId(creatorId);
148
        activity.setContactingAgentId(creatorId);
182
            activity.setTicketCategory(TicketCategory.valueOf(category));
149
        activity.setDescription(description);
183
            activity.setTicketDescription(description);
-
 
184
 
-
 
185
            // handling null values appropriately
150
        activity.setContactMedium(ContactMedium.valueOf(contactMedium));
186
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
151
        activity.setTicketAssigneeId(crmServiceClient.getAgentByEmailId(ticketAssigneeEmailId).getId());
187
                long assigneeId = crmServiceClient.getAgentByEmailId(
152
        activity.setTicketPriority(TicketPriority.valueOf(ticketPriority));
188
                        assigneeEmailId).getId();
153
        activity.setTicketStatus(TicketStatus.OPEN);
189
                ticket.setAssigneeId(assigneeId);
154
        activity.setContactTimestamp(SDF.parse(contactTimestamp).getTime());
190
                activity.setTicketAssigneeId(assigneeId);
-
 
191
            } else {
155
        activity.setCreatorId(creatorId);
192
                ticket.setAssigneeIdIsSet(false);
156
        activity.setTicketCategory(TicketCategory.valueOf(ticketCategory));
193
                activity.setTicketAssigneeIdIsSet(false);
-
 
194
            }
157
 
195
 
158
        activity.setTicketId(crmServiceClient.insertTicket(ticket));
196
            activity.setTicketId(crmServiceClient.insertTicket(ticket));
159
        crmServiceClient.insertActivity(activity);
197
            crmServiceClient.insertActivity(activity);
-
 
198
        } catch (TException e) {
-
 
199
            log.error("Error while creating ticket", e);
-
 
200
            return EXCEPTION;
-
 
201
        }
160
 
202
 
161
        return index();
203
        return index();
162
    }
204
    }
163
 
205
 
164
    public TicketCategory[] getTicketCategories()
206
    public String getLoggerRole() {
-
 
207
        try {
-
 
208
            createServiceClients();
-
 
209
            return crmServiceClient.getRoleNamesForAgent(currentAgentEmailId).get(0);
-
 
210
        } catch (TException e) {
-
 
211
            log.error("Error while getting roles", e);
-
 
212
            return AGENT;
-
 
213
        }
165
    {
214
    }
-
 
215
 
-
 
216
    public TicketCategory[] getTicketCategories() {
166
        return TicketCategory.values();
217
        return TicketCategory.values();
167
    }
218
    }
168
 
219
 
169
    public List<Agent> getAllAgents() throws TException
220
    public ActivityType[] getActivityTypes() {
-
 
221
        return ActivityType.values();
170
    {
222
    }
-
 
223
 
-
 
224
    public List<Agent> getAllAgents() {
-
 
225
        List<Agent> agents = null;
-
 
226
 
-
 
227
        try {
171
        createServiceClients();
228
            createServiceClients();
172
        return crmServiceClient.getAllAgents();
229
            agents = crmServiceClient.getAllAgents();            
-
 
230
        }
-
 
231
        catch (TException e) {
-
 
232
            String errorString = "Error while getting roles";
-
 
233
            log.error(errorString, e);
-
 
234
            addActionError(errorString);
-
 
235
        }
-
 
236
 
-
 
237
        return agents;
173
    }
238
    }
174
 
239
 
175
    public Map<Long, Ticket> getTicketsMap() {
240
    public Map<Long, Ticket> getTicketsMap() {
176
        return ticketsMap;
241
        return ticketsMap;
177
    }
242
    }
178
 
243
 
179
    public void setUserId(String userId) {
244
    public void setUserId(String userId) {
180
        this.userId = Long.parseLong(userId);
245
        this.userId = Long.parseLong(userId);
181
    }
246
    }
182
 
247
 
183
    public void setSubject(String subject) {
248
    public void setOrderId(String orderId) {
-
 
249
        this.orderId = orderId;
-
 
250
    }
-
 
251
 
-
 
252
    public long getUserId() {
-
 
253
        return userId;
-
 
254
    }
-
 
255
 
-
 
256
    public void setUserId(long userId) {
184
        this.subject = subject;
257
        this.userId = userId;
-
 
258
    }
-
 
259
 
-
 
260
    public String getId() {
-
 
261
        return id;
-
 
262
    }
-
 
263
 
-
 
264
    public void setId(String id) {
-
 
265
        this.id = id;
-
 
266
    }
-
 
267
 
-
 
268
    public String getActivityDescription() {
-
 
269
        return activityDescription;
-
 
270
    }
-
 
271
 
-
 
272
    public void setActivityDescription(String activityDescription) {
-
 
273
        this.activityDescription = activityDescription;
-
 
274
    }
-
 
275
 
-
 
276
    public String getDescription() {
-
 
277
        return description;
185
    }
278
    }
186
 
279
 
187
    public void setDescription(String description) {
280
    public void setDescription(String description) {
188
        this.description = description;
281
        this.description = description;
189
    }
282
    }
190
 
283
 
191
    public void setTicketAssigneeEmailId(String ticketAssigneeEmailId) {
284
    public String getAssigneeEmailId() {
192
        this.ticketAssigneeEmailId = ticketAssigneeEmailId;
285
        return assigneeEmailId;
193
    }
286
    }
194
 
287
 
195
    public void setTicketStatus(String ticketStatus) {
288
    public void setAssigneeEmailId(String assigneeEmailId) {
196
        this.ticketStatus = ticketStatus;
289
        this.assigneeEmailId = assigneeEmailId;
197
    }
290
    }
198
 
291
 
199
    public void setTicketPriority(String ticketPriority) {
292
    public String getStatus() {
200
        this.ticketPriority = ticketPriority;
293
        return status;
201
    }
294
    }
202
 
295
 
203
    public void setContactMedium(String contactMedium) {
296
    public void setStatus(String status) {
204
        this.contactMedium = contactMedium;
297
        this.status = status;
205
    }
298
    }
206
 
299
 
207
    public void setContactTimestamp(String contactTimestamp) {
300
    public String getPriority() {
208
        this.contactTimestamp = contactTimestamp;
301
        return priority;
209
    }
302
    }
210
 
303
 
211
    public void setContactingAgentEmailId(String contactingAgentEmailId) {
304
    public void setPriority(String priority) {
212
        this.contactingAgentEmailId = contactingAgentEmailId;
305
        this.priority = priority;
213
    }
306
    }
214
 
307
 
215
    public void setId(String id) {
308
    public String getCategory() {
216
        this.id = id;
309
        return category;
217
    }
310
    }
218
 
311
 
219
    public Ticket getTicket() {
312
    public void setCategory(String category) {
220
        return ticket;
313
        this.category = category;
221
    }
314
    }
222
 
315
 
223
    public Activity getLastActivity() {
316
    public String getActivityType() {
224
        return lastActivity;
317
        return activityType;
225
    }
318
    }
226
 
319
 
227
    public List<Activity> getActivities() {
320
    public void setActivityType(String activityType) {
228
        return activities;
321
        this.activityType = activityType;
229
    }
322
    }
230
 
323
 
231
    public long getUserId() {
324
    public Ticket getTicket() {
232
        return userId;
325
        return ticket;
233
    }
326
    }
234
 
327
 
235
    public String getContactTimestamp() {
328
    public void setTicket(Ticket ticket) {
236
        return contactTimestamp;
329
        this.ticket = ticket;
237
    }
330
    }
238
 
331
 
239
    public String getTicketCategory() {
332
    public List<Activity> getActivities() {
240
        return ticketCategory;
333
        return activities;
241
    }
334
    }
242
 
335
 
243
    public void setTicketCategory(String ticketCategory) {
336
    public void setActivities(List<Activity> activities) {
244
        this.ticketCategory = ticketCategory;
337
        this.activities = activities;
245
    }
338
    }
246
 
339
 
247
    public long getOrderId() {
340
    public String getOrderId() {
248
        return orderId;
341
        return orderId;
249
    }
342
    }
250
 
343
 
251
    public void setOrderId(String orderId) {
344
    public void setTicketsMap(Map<Long, Ticket> ticketsMap) {
252
        if (orderId != null && !orderId.isEmpty()) {
-
 
253
            this.orderId = Long.parseLong(orderId);
345
        this.ticketsMap = ticketsMap;
254
        }
-
 
255
    }
346
    }
256
}
347
}