| 3090 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.crm.Activity;
|
|
|
7 |
import in.shop2020.crm.Agent;
|
|
|
8 |
import in.shop2020.crm.ContactMedium;
|
|
|
9 |
import in.shop2020.crm.Ticket;
|
|
|
10 |
import in.shop2020.crm.TicketCategory;
|
|
|
11 |
import in.shop2020.crm.TicketPriority;
|
|
|
12 |
import in.shop2020.crm.TicketStatus;
|
|
|
13 |
import in.shop2020.model.v1.user.User;
|
|
|
14 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
15 |
|
|
|
16 |
import java.util.Date;
|
|
|
17 |
import java.util.HashMap;
|
|
|
18 |
import java.util.List;
|
|
|
19 |
import java.util.Map;
|
|
|
20 |
|
|
|
21 |
import org.apache.thrift.TException;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Action class for ticket pages in CRM tool.
|
|
|
25 |
*
|
|
|
26 |
* @author mandeep
|
|
|
27 |
*/
|
|
|
28 |
@SuppressWarnings("serial")
|
|
|
29 |
public class UserTicketsController extends BaseController {
|
|
|
30 |
private Map<Long, Ticket> ticketsMap = new HashMap<Long, Ticket>();
|
|
|
31 |
|
|
|
32 |
private long userId;
|
|
|
33 |
private String id;
|
|
|
34 |
private String subject;
|
|
|
35 |
private String description;
|
|
|
36 |
private String ticketAssigneeEmailId;
|
|
|
37 |
private String ticketStatus;
|
|
|
38 |
private String ticketPriority;
|
|
|
39 |
private String ticketCategory;
|
|
|
40 |
private String contactMedium;
|
|
|
41 |
private String contactTimestamp;
|
|
|
42 |
private String contactingAgentEmailId;
|
|
|
43 |
private Ticket ticket;
|
|
|
44 |
private Activity lastActivity;
|
|
|
45 |
private List<Activity> activities;
|
|
|
46 |
private long orderId;
|
|
|
47 |
|
|
|
48 |
public String index() throws Exception {
|
|
|
49 |
createServiceClients();
|
|
|
50 |
List<Ticket> ticketsList = crmServiceClient.getTickets(userId);
|
|
|
51 |
if (ticketsList != null) {
|
|
|
52 |
for (Ticket ticket : ticketsList) {
|
|
|
53 |
ticketsMap.put(ticket.getId(), ticket);
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
return INDEX;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public String editNew() {
|
|
|
61 |
contactTimestamp = SDF.format(new Date());
|
|
|
62 |
return EDIT_NEW;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public String update() throws Exception {
|
|
|
66 |
createServiceClients();
|
|
|
67 |
|
|
|
68 |
// Only subject and close date are editable fields for a ticket
|
|
|
69 |
Ticket ticket = new Ticket();
|
|
|
70 |
ticket.setId(Long.parseLong(id));
|
|
|
71 |
ticket.setSubject(subject);
|
|
|
72 |
|
|
|
73 |
// Update when a ticket is closed!
|
|
|
74 |
if (TicketStatus.CLOSED.name().equals(ticketStatus)) {
|
|
|
75 |
ticket.setCloseDate(new Date().getTime());
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
Activity activity = new Activity();
|
|
|
79 |
long creatorId = crmServiceClient.getAgentByEmailId(currentAgentEmailId).getId();
|
|
|
80 |
activity.setContactingAgentId(creatorId);
|
|
|
81 |
activity.setDescription(description);
|
|
|
82 |
activity.setContactMedium(ContactMedium.valueOf(contactMedium));
|
|
|
83 |
activity.setTicketAssigneeId(crmServiceClient.getAgentByEmailId(
|
|
|
84 |
ticketAssigneeEmailId).getId());
|
|
|
85 |
activity.setTicketPriority(TicketPriority.valueOf(ticketPriority));
|
|
|
86 |
activity.setTicketStatus(TicketStatus.valueOf(ticketStatus));
|
|
|
87 |
activity.setContactTimestamp(SDF.parse(contactTimestamp).getTime());
|
|
|
88 |
activity.setCreatorId(creatorId);
|
|
|
89 |
activity.setTicketCategory(TicketCategory.valueOf(ticketCategory));
|
|
|
90 |
|
|
|
91 |
crmServiceClient.updateTicket(ticket);
|
|
|
92 |
activity.setTicketId(ticket.getId());
|
|
|
93 |
crmServiceClient.insertActivity(activity);
|
|
|
94 |
|
|
|
95 |
return index();
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
public String edit() throws TException, UserContextException {
|
|
|
99 |
createServiceClients();
|
|
|
100 |
long ticketId = Long.parseLong(id);
|
|
|
101 |
ticket = crmServiceClient.getTicket(ticketId);
|
|
|
102 |
lastActivity = crmServiceClient.getLastActivity(ticketId);
|
|
|
103 |
activities = crmServiceClient.getActivitiesForTicket(Long.parseLong(id));
|
|
|
104 |
contactTimestamp = SDF.format(new Date());
|
|
|
105 |
return EDIT;
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
public Map<Long, Ticket> getTickets() {
|
|
|
109 |
return ticketsMap;
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
public User getUser() throws UserContextException, TException {
|
|
|
113 |
return userContextServiceClient.getUserById(userId);
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
public Activity getLastActivity(long ticketId) throws TException {
|
|
|
117 |
return crmServiceClient.getLastActivity(ticketId);
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
public Agent getAgent(long agentId) throws TException {
|
|
|
121 |
return crmServiceClient.getAgent(agentId);
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
public TicketStatus[] getTicketStatuses() {
|
|
|
125 |
return TicketStatus.values();
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public TicketPriority[] getTicketPriorities() {
|
|
|
129 |
return TicketPriority.values();
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
public ContactMedium[] getContactMedia() {
|
|
|
133 |
return ContactMedium.values();
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
public String create() throws Exception {
|
|
|
137 |
createServiceClients();
|
|
|
138 |
long creatorId = crmServiceClient.getAgentByEmailId(currentAgentEmailId).getId();
|
|
|
139 |
Ticket ticket = new Ticket();
|
|
|
140 |
ticket.setOpenDate(new Date().getTime());
|
|
|
141 |
ticket.setSubject(subject);
|
|
|
142 |
ticket.setCustomerId(userId);
|
|
|
143 |
ticket.setCreatorId(creatorId);
|
|
|
144 |
ticket.setOrderId(creatorId);
|
|
|
145 |
|
|
|
146 |
Activity activity = new Activity();
|
|
|
147 |
activity.setCustomerId(userId);
|
|
|
148 |
activity.setContactingAgentId(creatorId);
|
|
|
149 |
activity.setDescription(description);
|
|
|
150 |
activity.setContactMedium(ContactMedium.valueOf(contactMedium));
|
|
|
151 |
activity.setTicketAssigneeId(crmServiceClient.getAgentByEmailId(ticketAssigneeEmailId).getId());
|
|
|
152 |
activity.setTicketPriority(TicketPriority.valueOf(ticketPriority));
|
|
|
153 |
activity.setTicketStatus(TicketStatus.OPEN);
|
|
|
154 |
activity.setContactTimestamp(SDF.parse(contactTimestamp).getTime());
|
|
|
155 |
activity.setCreatorId(creatorId);
|
|
|
156 |
activity.setTicketCategory(TicketCategory.valueOf(ticketCategory));
|
|
|
157 |
|
|
|
158 |
activity.setTicketId(crmServiceClient.insertTicket(ticket));
|
|
|
159 |
crmServiceClient.insertActivity(activity);
|
|
|
160 |
|
|
|
161 |
return index();
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
public TicketCategory[] getTicketCategories()
|
|
|
165 |
{
|
|
|
166 |
return TicketCategory.values();
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
public List<Agent> getAllAgents() throws TException
|
|
|
170 |
{
|
|
|
171 |
createServiceClients();
|
|
|
172 |
return crmServiceClient.getAllAgents();
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
public Map<Long, Ticket> getTicketsMap() {
|
|
|
176 |
return ticketsMap;
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
public void setUserId(String userId) {
|
|
|
180 |
this.userId = Long.parseLong(userId);
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
public void setSubject(String subject) {
|
|
|
184 |
this.subject = subject;
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
public void setDescription(String description) {
|
|
|
188 |
this.description = description;
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
public void setTicketAssigneeEmailId(String ticketAssigneeEmailId) {
|
|
|
192 |
this.ticketAssigneeEmailId = ticketAssigneeEmailId;
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
public void setTicketStatus(String ticketStatus) {
|
|
|
196 |
this.ticketStatus = ticketStatus;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
public void setTicketPriority(String ticketPriority) {
|
|
|
200 |
this.ticketPriority = ticketPriority;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public void setContactMedium(String contactMedium) {
|
|
|
204 |
this.contactMedium = contactMedium;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
public void setContactTimestamp(String contactTimestamp) {
|
|
|
208 |
this.contactTimestamp = contactTimestamp;
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
public void setContactingAgentEmailId(String contactingAgentEmailId) {
|
|
|
212 |
this.contactingAgentEmailId = contactingAgentEmailId;
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
public void setId(String id) {
|
|
|
216 |
this.id = id;
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
public Ticket getTicket() {
|
|
|
220 |
return ticket;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
public Activity getLastActivity() {
|
|
|
224 |
return lastActivity;
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public List<Activity> getActivities() {
|
|
|
228 |
return activities;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
public long getUserId() {
|
|
|
232 |
return userId;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
public String getContactTimestamp() {
|
|
|
236 |
return contactTimestamp;
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
public String getTicketCategory() {
|
|
|
240 |
return ticketCategory;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
public void setTicketCategory(String ticketCategory) {
|
|
|
244 |
this.ticketCategory = ticketCategory;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
public long getOrderId() {
|
|
|
248 |
return orderId;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
public void setOrderId(String orderId) {
|
|
|
252 |
if (orderId != null && !orderId.isEmpty()) {
|
|
|
253 |
this.orderId = Long.parseLong(orderId);
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
}
|