| 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;
|
|
|
14 |
import in.shop2020.model.v1.user.User;
|
|
|
15 |
import in.shop2020.model.v1.user.UserContextException;
|
| 3390 |
mandeep.dh |
16 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
|
|
17 |
import in.shop2020.thrift.clients.CRMClient;
|
|
|
18 |
import in.shop2020.thrift.clients.UserClient;
|
| 3137 |
mandeep.dh |
19 |
|
|
|
20 |
import java.util.ArrayList;
|
| 3390 |
mandeep.dh |
21 |
import java.util.Collections;
|
| 3137 |
mandeep.dh |
22 |
import java.util.List;
|
|
|
23 |
|
|
|
24 |
import org.apache.thrift.TException;
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* @author mandeep
|
|
|
28 |
*
|
|
|
29 |
*/
|
|
|
30 |
public class TicketsController extends BaseController {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
*
|
|
|
34 |
*/
|
|
|
35 |
private static final long serialVersionUID = 1L;
|
|
|
36 |
|
|
|
37 |
List<Ticket> tickets = new ArrayList<Ticket>();
|
| 3339 |
mandeep.dh |
38 |
private String userEmailId;
|
|
|
39 |
private String description;
|
|
|
40 |
private String assigneeEmailId;
|
|
|
41 |
private String priority;
|
|
|
42 |
private String category;
|
|
|
43 |
private String orderId;
|
| 3137 |
mandeep.dh |
44 |
|
| 3339 |
mandeep.dh |
45 |
public String create() {
|
|
|
46 |
try {
|
| 3390 |
mandeep.dh |
47 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();
|
| 3339 |
mandeep.dh |
48 |
Ticket ticket = new Ticket();
|
|
|
49 |
ticket.setDescription(description);
|
|
|
50 |
ticket.setCreatorId(creatorId);
|
|
|
51 |
ticket.setStatus(TicketStatus.OPEN);
|
|
|
52 |
ticket.setPriority(TicketPriority.valueOf(priority));
|
|
|
53 |
ticket.setCategory(TicketCategory.valueOf(category));
|
|
|
54 |
|
|
|
55 |
Activity activity = new Activity();
|
|
|
56 |
// At creation of ticket activity's description is same as that of
|
|
|
57 |
// ticket
|
|
|
58 |
activity.setDescription("Creating Ticket");
|
|
|
59 |
activity.setType(ActivityType.OTHER);
|
|
|
60 |
activity.setTicketPriority(TicketPriority.valueOf(priority));
|
|
|
61 |
activity.setTicketStatus(TicketStatus.OPEN);
|
|
|
62 |
activity.setCreatorId(creatorId);
|
|
|
63 |
activity.setTicketCategory(TicketCategory.valueOf(category));
|
|
|
64 |
activity.setTicketDescription(description);
|
|
|
65 |
|
|
|
66 |
if (orderId != null && !orderId.isEmpty()) {
|
|
|
67 |
ticket.setOrderId(Long.parseLong(orderId));
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
if (userEmailId != null && !userEmailId.isEmpty()) {
|
| 3390 |
mandeep.dh |
71 |
User user = null;
|
|
|
72 |
userContextServiceClient = new UserClient().getClient();
|
|
|
73 |
try {
|
|
|
74 |
user = userContextServiceClient.getUserByEmail(userEmailId);
|
|
|
75 |
} catch (UserContextException e) {
|
|
|
76 |
log.error("Could not fetch user for " + userEmailId, e);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
if (user != null && user.getUserId() != -1) {
|
|
|
80 |
ticket.setCustomerId(user.getUserId());
|
|
|
81 |
activity.setCustomerId(user.getUserId());
|
|
|
82 |
}
|
|
|
83 |
else {
|
|
|
84 |
ticket.setCustomerEmailId(userEmailId);
|
|
|
85 |
activity.setCustomerEmailId(userEmailId);
|
|
|
86 |
}
|
| 3339 |
mandeep.dh |
87 |
}
|
|
|
88 |
|
|
|
89 |
// handling null values appropriately
|
|
|
90 |
if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
|
| 3390 |
mandeep.dh |
91 |
long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId).getId();
|
| 3339 |
mandeep.dh |
92 |
ticket.setAssigneeId(assigneeId);
|
|
|
93 |
activity.setTicketAssigneeId(assigneeId);
|
|
|
94 |
}
|
|
|
95 |
|
| 3390 |
mandeep.dh |
96 |
crmServiceClient = new CRMClient().getClient();
|
| 3339 |
mandeep.dh |
97 |
crmServiceClient.insertTicket(ticket, activity);
|
|
|
98 |
} catch (TException e) {
|
|
|
99 |
log.error("Error while creating ticket", e);
|
|
|
100 |
return EXCEPTION;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
return getMyOpenTickets();
|
|
|
104 |
}
|
|
|
105 |
|
| 3137 |
mandeep.dh |
106 |
public String getMyOpenTickets() {
|
|
|
107 |
try {
|
| 3390 |
mandeep.dh |
108 |
Agent agent = CRMAuthorizingRealm.getAgent(currentAgentEmailId);
|
| 3137 |
mandeep.dh |
109 |
|
| 3390 |
mandeep.dh |
110 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
111 |
searchFilter.setTicketAssigneeIds(Collections.singletonList(agent.getId()));
|
|
|
112 |
crmServiceClient = new CRMClient().getClient();
|
|
|
113 |
for (Ticket ticket : crmServiceClient.getTickets(searchFilter)) {
|
| 3137 |
mandeep.dh |
114 |
if (TicketStatus.OPEN.equals(ticket.getStatus())) {
|
|
|
115 |
tickets.add(ticket);
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
} catch (TException e) {
|
|
|
119 |
String errorString = "Error getting tickets for "
|
|
|
120 |
+ currentAgentEmailId;
|
|
|
121 |
log.error(errorString, e);
|
|
|
122 |
addActionError(errorString);
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
return INDEX;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public String getMyTickets() {
|
|
|
129 |
try {
|
| 3390 |
mandeep.dh |
130 |
Agent agent = CRMAuthorizingRealm.getAgent(currentAgentEmailId);
|
|
|
131 |
|
|
|
132 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
133 |
searchFilter.setTicketAssigneeIds(Collections.singletonList(agent.getId()));
|
|
|
134 |
crmServiceClient = new CRMClient().getClient();
|
|
|
135 |
tickets = crmServiceClient.getTickets(searchFilter);
|
| 3137 |
mandeep.dh |
136 |
} catch (TException e) {
|
| 3339 |
mandeep.dh |
137 |
String errorString = "Error getting tickets for "
|
|
|
138 |
+ currentAgentEmailId;
|
| 3137 |
mandeep.dh |
139 |
log.error(errorString, e);
|
|
|
140 |
addActionError(errorString);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
return INDEX;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
public String getUnassignedTickets() {
|
|
|
147 |
try {
|
| 3390 |
mandeep.dh |
148 |
crmServiceClient = new CRMClient().getClient();
|
| 3137 |
mandeep.dh |
149 |
tickets = crmServiceClient.getUnassignedTickets();
|
|
|
150 |
} catch (TException e) {
|
| 3339 |
mandeep.dh |
151 |
String errorString = "Error getting tickets for "
|
|
|
152 |
+ currentAgentEmailId;
|
| 3137 |
mandeep.dh |
153 |
log.error(errorString, e);
|
|
|
154 |
addActionError(errorString);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
return INDEX;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
public String getAllTickets() {
|
|
|
161 |
try {
|
| 3390 |
mandeep.dh |
162 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
163 |
searchFilter.setTicketAssigneeIds(Collections.singletonList(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId()));
|
|
|
164 |
crmServiceClient = new CRMClient().getClient();
|
|
|
165 |
tickets = crmServiceClient.getTickets(searchFilter);
|
| 3137 |
mandeep.dh |
166 |
} catch (TException e) {
|
| 3339 |
mandeep.dh |
167 |
String errorString = "Error getting tickets for "
|
|
|
168 |
+ currentAgentEmailId;
|
| 3137 |
mandeep.dh |
169 |
log.error(errorString, e);
|
|
|
170 |
addActionError(errorString);
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
return INDEX;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public String getAllOpenTickets() {
|
|
|
177 |
try {
|
| 3390 |
mandeep.dh |
178 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
179 |
searchFilter.setTicketAssigneeIds(Collections.singletonList(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId()));
|
|
|
180 |
crmServiceClient = new CRMClient().getClient();
|
|
|
181 |
for (Ticket ticket : crmServiceClient.getTickets(searchFilter)) {
|
| 3137 |
mandeep.dh |
182 |
if (TicketStatus.OPEN.equals(ticket.getStatus())) {
|
|
|
183 |
tickets.add(ticket);
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
} catch (TException e) {
|
| 3339 |
mandeep.dh |
187 |
String errorString = "Error getting tickets for "
|
|
|
188 |
+ currentAgentEmailId;
|
| 3137 |
mandeep.dh |
189 |
log.error(errorString, e);
|
|
|
190 |
addActionError(errorString);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
return INDEX;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
public User getUser(Long userId) {
|
|
|
197 |
User user = null;
|
|
|
198 |
|
|
|
199 |
try {
|
| 3390 |
mandeep.dh |
200 |
userContextServiceClient = new UserClient().getClient();
|
| 3137 |
mandeep.dh |
201 |
user = userContextServiceClient.getUserById(userId);
|
|
|
202 |
} catch (UserContextException e) {
|
|
|
203 |
String errorString = "Could not fetch user for " + userId;
|
|
|
204 |
log.error(errorString, e);
|
|
|
205 |
addActionError(errorString);
|
|
|
206 |
} catch (TException e) {
|
|
|
207 |
String errorString = "Could not create client";
|
|
|
208 |
log.error(errorString, e);
|
|
|
209 |
addActionError(errorString);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
return user;
|
|
|
213 |
}
|
|
|
214 |
|
| 3390 |
mandeep.dh |
215 |
public Agent getAgent(long agentId) throws TException {
|
|
|
216 |
return CRMAuthorizingRealm.getAgent(agentId);
|
| 3137 |
mandeep.dh |
217 |
}
|
|
|
218 |
|
| 3339 |
mandeep.dh |
219 |
public List<Agent> getAllAgents() {
|
| 3390 |
mandeep.dh |
220 |
return CRMAuthorizingRealm.getAgents();
|
| 3339 |
mandeep.dh |
221 |
}
|
|
|
222 |
|
|
|
223 |
public TicketCategory[] getTicketCategories() {
|
|
|
224 |
return TicketCategory.values();
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
public TicketPriority[] getTicketPriorities() {
|
|
|
228 |
return TicketPriority.values();
|
|
|
229 |
}
|
|
|
230 |
|
| 3137 |
mandeep.dh |
231 |
public List<Ticket> getTickets() {
|
|
|
232 |
return tickets;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
public void setTickets(List<Ticket> tickets) {
|
|
|
236 |
this.tickets = tickets;
|
|
|
237 |
}
|
| 3339 |
mandeep.dh |
238 |
|
|
|
239 |
public String getUserEmailId() {
|
|
|
240 |
return userEmailId;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
public void setUserEmailId(String userEmailId) {
|
|
|
244 |
this.userEmailId = userEmailId;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
public String getDescription() {
|
|
|
248 |
return description;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
public void setDescription(String description) {
|
|
|
252 |
this.description = description;
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
public String getAssigneeEmailId() {
|
|
|
256 |
return assigneeEmailId;
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
public void setAssigneeEmailId(String assigneeEmailId) {
|
|
|
260 |
this.assigneeEmailId = assigneeEmailId;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
public String getPriority() {
|
|
|
264 |
return priority;
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public void setPriority(String priority) {
|
|
|
268 |
this.priority = priority;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
public String getCategory() {
|
|
|
272 |
return category;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
public void setCategory(String category) {
|
|
|
276 |
this.category = category;
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
public String getOrderId() {
|
|
|
280 |
return orderId;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
public void setOrderId(String orderId) {
|
|
|
284 |
this.orderId = orderId;
|
|
|
285 |
}
|
| 3137 |
mandeep.dh |
286 |
}
|