| 3339 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.crm.Activity;
|
|
|
7 |
import in.shop2020.crm.ActivityType;
|
|
|
8 |
import in.shop2020.crm.Agent;
|
| 3390 |
mandeep.dh |
9 |
import in.shop2020.crm.SearchFilter;
|
| 4142 |
mandeep.dh |
10 |
import in.shop2020.crm.TicketCategory;
|
| 3405 |
mandeep.dh |
11 |
import in.shop2020.model.v1.user.User;
|
|
|
12 |
import in.shop2020.model.v1.user.UserContextException;
|
| 3390 |
mandeep.dh |
13 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
|
|
14 |
import in.shop2020.thrift.clients.CRMClient;
|
| 3405 |
mandeep.dh |
15 |
import in.shop2020.thrift.clients.UserClient;
|
| 3339 |
mandeep.dh |
16 |
import in.shop2020.util.CRMConstants;
|
| 5203 |
amar.kumar |
17 |
import in.shop2020.util.CRMConstants.ActivityCommonDescriptionMatrix;
|
| 16208 |
manish.sha |
18 |
import in.shop2020.util.CRMConstants.ActivityPMCommonDescriptionMatrix;
|
| 3339 |
mandeep.dh |
19 |
|
| 3397 |
mandeep.dh |
20 |
import java.text.ParseException;
|
|
|
21 |
import java.util.ArrayList;
|
| 3390 |
mandeep.dh |
22 |
import java.util.Collections;
|
| 3339 |
mandeep.dh |
23 |
import java.util.List;
|
|
|
24 |
|
| 16092 |
amit.gupta |
25 |
import org.apache.commons.lang.StringEscapeUtils;
|
| 3339 |
mandeep.dh |
26 |
import org.apache.thrift.TException;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* @author mandeep
|
|
|
30 |
*
|
|
|
31 |
*/
|
|
|
32 |
public class ActivityController extends BaseController {
|
|
|
33 |
/**
|
|
|
34 |
*
|
|
|
35 |
*/
|
|
|
36 |
private static final long serialVersionUID = 1L;
|
|
|
37 |
private List<Activity> activities;
|
| 3390 |
mandeep.dh |
38 |
private String activityId;
|
| 3339 |
mandeep.dh |
39 |
private String description;
|
| 5203 |
amar.kumar |
40 |
private String commonDescription;
|
| 3339 |
mandeep.dh |
41 |
private String type;
|
| 4142 |
mandeep.dh |
42 |
private String category;
|
| 3339 |
mandeep.dh |
43 |
private String customerMobileNumber;
|
|
|
44 |
private String creatorId;
|
| 3397 |
mandeep.dh |
45 |
private String[] agentIds;
|
|
|
46 |
private String startTimestamp;
|
|
|
47 |
private String endTimestamp;
|
| 3405 |
mandeep.dh |
48 |
private String customerEmailId;
|
|
|
49 |
private String customerName;
|
|
|
50 |
private String userId;
|
| 14898 |
manish.sha |
51 |
private String notShowPmTickets;
|
| 3339 |
mandeep.dh |
52 |
|
|
|
53 |
public String index() {
|
|
|
54 |
try {
|
| 3390 |
mandeep.dh |
55 |
SearchFilter searchFilter = new SearchFilter();
|
| 16208 |
manish.sha |
56 |
if(isProfitMandiAgent()){
|
|
|
57 |
searchFilter.setNotShowPmTickets(false);
|
| 14911 |
manish.sha |
58 |
searchFilter.setTicketCategoryList(new ArrayList<TicketCategory>());
|
|
|
59 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_CASHBACK);
|
|
|
60 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_FEEDBACK);
|
|
|
61 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_ORDER_NOT_SEEN);
|
|
|
62 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_OTHER);
|
|
|
63 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_RECHARGE_ISSUE);
|
| 16208 |
manish.sha |
64 |
}else{
|
|
|
65 |
if(notShowPmTickets!=null && !notShowPmTickets.isEmpty() && "yes".equalsIgnoreCase(notShowPmTickets)){
|
|
|
66 |
searchFilter.setNotShowPmTickets(true);
|
|
|
67 |
searchFilter.setTicketCategoryList(new ArrayList<TicketCategory>());
|
|
|
68 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_CASHBACK);
|
|
|
69 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_FEEDBACK);
|
|
|
70 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_ORDER_NOT_SEEN);
|
|
|
71 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_OTHER);
|
|
|
72 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_RECHARGE_ISSUE);
|
|
|
73 |
}
|
| 14898 |
manish.sha |
74 |
}
|
| 3405 |
mandeep.dh |
75 |
if (activityId != null && !activityId.isEmpty()) {
|
|
|
76 |
searchFilter.setActivityId(Long.parseLong(activityId));
|
|
|
77 |
} else if (userId != null && !userId.isEmpty()) {
|
|
|
78 |
searchFilter.setCustomerId(Long.parseLong(userId));
|
|
|
79 |
} else if (creatorId != null && !creatorId.isEmpty()) {
|
|
|
80 |
searchFilter.setActivityCreatorIds(Collections
|
|
|
81 |
.singletonList(Long.parseLong(creatorId)));
|
| 3390 |
mandeep.dh |
82 |
searchFilter.setIsActivityRead(false);
|
| 3405 |
mandeep.dh |
83 |
} else if (agentIds != null && agentIds.length != 0) {
|
| 3397 |
mandeep.dh |
84 |
searchFilter.setActivityCreatorIds(new ArrayList<Long>());
|
|
|
85 |
for (String agentId : agentIds) {
|
| 3405 |
mandeep.dh |
86 |
searchFilter.getActivityCreatorIds().add(
|
|
|
87 |
CRMAuthorizingRealm.getAgent(agentId).getId());
|
| 3397 |
mandeep.dh |
88 |
}
|
|
|
89 |
|
| 4142 |
mandeep.dh |
90 |
if (type != null && !type.isEmpty()) {
|
|
|
91 |
searchFilter.setActivityType(ActivityType.valueOf(type));
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
if (category != null && !category.isEmpty()) {
|
|
|
95 |
searchFilter.setTicketCategory(TicketCategory.valueOf(category));
|
|
|
96 |
}
|
| 7595 |
kshitij.so |
97 |
|
|
|
98 |
//Start:- Added By Manish Sharma for Searching Tickets/Activities using Mobile No. on 21-Jun-2013
|
|
|
99 |
if(customerMobileNumber!=null && !customerMobileNumber.isEmpty()){
|
|
|
100 |
searchFilter.setCustomerMobileNumber(customerMobileNumber);
|
|
|
101 |
}
|
|
|
102 |
//End:- Added By Manish Sharma for Searching Tickets/Activities using Mobile No. on 21-Jun-2013
|
| 4142 |
mandeep.dh |
103 |
|
| 3397 |
mandeep.dh |
104 |
try {
|
|
|
105 |
if (startTimestamp != null && !startTimestamp.isEmpty()) {
|
| 3405 |
mandeep.dh |
106 |
searchFilter.setStartTimestamp(SDF
|
|
|
107 |
.parse(startTimestamp).getTime());
|
| 3397 |
mandeep.dh |
108 |
}
|
|
|
109 |
|
|
|
110 |
if (endTimestamp != null && !endTimestamp.isEmpty()) {
|
| 3405 |
mandeep.dh |
111 |
searchFilter.setEndTimestamp(SDF.parse(endTimestamp)
|
|
|
112 |
.getTime());
|
| 3397 |
mandeep.dh |
113 |
}
|
| 3405 |
mandeep.dh |
114 |
} catch (ParseException e) {
|
| 3397 |
mandeep.dh |
115 |
log.error("Error parsing timestamps", e);
|
|
|
116 |
}
|
| 3405 |
mandeep.dh |
117 |
} else {
|
|
|
118 |
searchFilter.setActivityCreatorIds(Collections
|
|
|
119 |
.singletonList(CRMAuthorizingRealm.getAgent(
|
|
|
120 |
currentAgentEmailId).getId()));
|
| 3397 |
mandeep.dh |
121 |
}
|
|
|
122 |
|
| 3405 |
mandeep.dh |
123 |
crmServiceClient = new CRMClient().getClient();
|
| 3397 |
mandeep.dh |
124 |
activities = crmServiceClient.getActivities(searchFilter);
|
| 3339 |
mandeep.dh |
125 |
} catch (TException e) {
|
|
|
126 |
log.error("Error while retrieving activities for "
|
|
|
127 |
+ currentAgentEmailId, e);
|
| 3405 |
mandeep.dh |
128 |
} catch (NumberFormatException e) {
|
|
|
129 |
log.error("Error parsing userId: " + userId, e);
|
| 3339 |
mandeep.dh |
130 |
}
|
|
|
131 |
|
|
|
132 |
return INDEX;
|
|
|
133 |
}
|
|
|
134 |
|
| 3405 |
mandeep.dh |
135 |
public String editNew() {
|
|
|
136 |
return EDIT_NEW;
|
|
|
137 |
}
|
|
|
138 |
|
| 3339 |
mandeep.dh |
139 |
public String create() throws Exception {
|
|
|
140 |
Activity activity = new Activity();
|
| 5203 |
amar.kumar |
141 |
if(commonDescription!=null && !commonDescription.isEmpty()){
|
|
|
142 |
if(description!=null) {
|
|
|
143 |
description = commonDescription + " " +description;
|
|
|
144 |
} else {
|
|
|
145 |
description = commonDescription;
|
|
|
146 |
}
|
|
|
147 |
}
|
| 3339 |
mandeep.dh |
148 |
activity.setDescription(description);
|
|
|
149 |
activity.setType(ActivityType.valueOf(type));
|
| 3405 |
mandeep.dh |
150 |
activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
|
|
151 |
.getId());
|
| 3339 |
mandeep.dh |
152 |
|
| 3405 |
mandeep.dh |
153 |
if (userId != null && !userId.isEmpty()) {
|
|
|
154 |
activity.setCustomerId(Long.parseLong(userId));
|
| 5224 |
amar.kumar |
155 |
if(customerMobileNumber != null
|
|
|
156 |
&& !customerMobileNumber.isEmpty()) {
|
|
|
157 |
activity.setCustomerMobileNumber(customerMobileNumber);
|
|
|
158 |
}
|
| 3405 |
mandeep.dh |
159 |
} else {
|
|
|
160 |
User user = null;
|
|
|
161 |
userContextServiceClient = new UserClient().getClient();
|
|
|
162 |
|
|
|
163 |
try {
|
|
|
164 |
if (customerName != null && !customerName.isEmpty()) {
|
|
|
165 |
activity.setCustomerName(customerName);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
if (customerEmailId != null && !customerEmailId.isEmpty()) {
|
|
|
169 |
activity.setCustomerEmailId(customerEmailId);
|
|
|
170 |
user = userContextServiceClient
|
|
|
171 |
.getUserByEmail(customerEmailId);
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
if ((user == null || user.getUserId() == -1)
|
|
|
175 |
&& customerMobileNumber != null
|
|
|
176 |
&& !customerMobileNumber.isEmpty()) {
|
|
|
177 |
activity.setCustomerMobileNumber(customerMobileNumber);
|
|
|
178 |
user = userContextServiceClient.getUserByMobileNumber(Long
|
|
|
179 |
.parseLong(customerMobileNumber));
|
|
|
180 |
}
|
|
|
181 |
} catch (UserContextException e) {
|
|
|
182 |
log.error("Could not fetch user for: " + customerEmailId + " "
|
|
|
183 |
+ customerMobileNumber + " " + customerName, e);
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
if (user != null && user.getUserId() != -1) {
|
|
|
187 |
activity.setCustomerId(user.getUserId());
|
|
|
188 |
}
|
| 3339 |
mandeep.dh |
189 |
}
|
| 14898 |
manish.sha |
190 |
|
| 3339 |
mandeep.dh |
191 |
|
| 3405 |
mandeep.dh |
192 |
crmServiceClient = new CRMClient().getClient();
|
|
|
193 |
activityId = String.valueOf(crmServiceClient.insertActivity(activity));
|
| 3339 |
mandeep.dh |
194 |
|
|
|
195 |
return index();
|
|
|
196 |
}
|
|
|
197 |
|
| 3405 |
mandeep.dh |
198 |
public String markAsRead() {
|
| 3390 |
mandeep.dh |
199 |
try {
|
| 3405 |
mandeep.dh |
200 |
crmServiceClient = new CRMClient().getClient();
|
|
|
201 |
crmServiceClient.markAsRead(Long.parseLong(activityId),
|
|
|
202 |
CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
|
| 3390 |
mandeep.dh |
203 |
} catch (NumberFormatException e) {
|
|
|
204 |
log.error("Could not parse activity id from" + activityId, e);
|
|
|
205 |
} catch (TException e) {
|
| 3405 |
mandeep.dh |
206 |
log.error("Could not mark the activityId: " + activityId
|
|
|
207 |
+ " as read", e);
|
| 3390 |
mandeep.dh |
208 |
}
|
|
|
209 |
|
| 3405 |
mandeep.dh |
210 |
return index();
|
| 3390 |
mandeep.dh |
211 |
}
|
|
|
212 |
|
| 3711 |
mandeep.dh |
213 |
public String getUnreadActivities() {
|
|
|
214 |
try {
|
|
|
215 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
216 |
searchFilter.setIsActivityRead(false);
|
|
|
217 |
searchFilter.setActivityCreatorIds(Collections.singletonList(CRMConstants.ADMIN_AGENT_ID));
|
|
|
218 |
|
| 14906 |
manish.sha |
219 |
if(notShowPmTickets!=null && !notShowPmTickets.isEmpty() && "yes".equalsIgnoreCase(notShowPmTickets)){
|
|
|
220 |
searchFilter.setNotShowPmTickets(true);
|
| 14911 |
manish.sha |
221 |
searchFilter.setTicketCategoryList(new ArrayList<TicketCategory>());
|
|
|
222 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_CASHBACK);
|
|
|
223 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_FEEDBACK);
|
|
|
224 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_ORDER_NOT_SEEN);
|
|
|
225 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_OTHER);
|
|
|
226 |
searchFilter.getTicketCategoryList().add(TicketCategory.PROFITMANDI_RECHARGE_ISSUE);
|
| 14903 |
manish.sha |
227 |
}
|
|
|
228 |
|
| 3711 |
mandeep.dh |
229 |
searchFilter.setTicketAssigneeIds(Collections
|
|
|
230 |
.singletonList(CRMAuthorizingRealm.getAgent(
|
|
|
231 |
currentAgentEmailId).getId()));
|
|
|
232 |
|
|
|
233 |
crmServiceClient = new CRMClient().getClient();
|
|
|
234 |
activities = crmServiceClient.getActivities(searchFilter);
|
|
|
235 |
} catch (TException e) {
|
|
|
236 |
log.error("Could not get agentId for: " + currentAgentEmailId, e);
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
return INDEX;
|
|
|
240 |
}
|
|
|
241 |
|
| 3339 |
mandeep.dh |
242 |
public ActivityType[] getActivityTypes() {
|
|
|
243 |
return ActivityType.values();
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
public Agent getAgent(long agentId) throws TException {
|
| 3390 |
mandeep.dh |
247 |
return CRMAuthorizingRealm.getAgent(agentId);
|
| 3339 |
mandeep.dh |
248 |
}
|
|
|
249 |
|
| 5203 |
amar.kumar |
250 |
public ActivityCommonDescriptionMatrix[] getActivityCommonDescriptionMatrix () {
|
|
|
251 |
return CRMConstants.ActivityCommonDescriptionMatrix.values();
|
|
|
252 |
}
|
|
|
253 |
|
| 16208 |
manish.sha |
254 |
public ActivityPMCommonDescriptionMatrix[] getPMActivityCommonDescriptionMatrix(){
|
|
|
255 |
return CRMConstants.ActivityPMCommonDescriptionMatrix.values();
|
|
|
256 |
}
|
|
|
257 |
|
| 3339 |
mandeep.dh |
258 |
public String getDescription() {
|
|
|
259 |
return description;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
public void setDescription(String description) {
|
|
|
263 |
this.description = description;
|
|
|
264 |
}
|
|
|
265 |
|
| 5203 |
amar.kumar |
266 |
public String getCommonDescription() {
|
|
|
267 |
return commonDescription;
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
public void setCommonDescription(String commonDescription) {
|
|
|
271 |
this.commonDescription = commonDescription;
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
public String getType() {
|
| 3339 |
mandeep.dh |
275 |
return type;
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
public void setType(String type) {
|
|
|
279 |
this.type = type;
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
public String getCustomerMobileNumber() {
|
|
|
283 |
return customerMobileNumber;
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
public void setCustomerMobileNumber(String customerMobileNumber) {
|
|
|
287 |
this.customerMobileNumber = customerMobileNumber;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
public List<Activity> getActivities() {
|
|
|
291 |
return activities;
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
public String getCreatorId() {
|
|
|
295 |
return creatorId;
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
public void setCreatorId(String creatorId) {
|
|
|
299 |
this.creatorId = creatorId;
|
|
|
300 |
}
|
| 3390 |
mandeep.dh |
301 |
|
|
|
302 |
public String getActivityId() {
|
|
|
303 |
return activityId;
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
public void setActivityId(String activityId) {
|
|
|
307 |
this.activityId = activityId;
|
|
|
308 |
}
|
| 3397 |
mandeep.dh |
309 |
|
|
|
310 |
public String[] getAgentIds() {
|
|
|
311 |
return agentIds;
|
|
|
312 |
}
|
|
|
313 |
|
|
|
314 |
public void setAgentIds(String[] agentIds) {
|
|
|
315 |
this.agentIds = agentIds;
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
public String getStartTimestamp() {
|
|
|
319 |
return startTimestamp;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
public void setStartTimestamp(String startTimestamp) {
|
|
|
323 |
this.startTimestamp = startTimestamp;
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
public String getEndTimestamp() {
|
|
|
327 |
return endTimestamp;
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
public void setEndTimestamp(String endTimestamp) {
|
|
|
331 |
this.endTimestamp = endTimestamp;
|
|
|
332 |
}
|
|
|
333 |
|
|
|
334 |
public void setActivities(List<Activity> activities) {
|
|
|
335 |
this.activities = activities;
|
|
|
336 |
}
|
| 3405 |
mandeep.dh |
337 |
|
|
|
338 |
public String getCustomerEmailId() {
|
|
|
339 |
return customerEmailId;
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
public void setCustomerEmailId(String customerEmailId) {
|
|
|
343 |
this.customerEmailId = customerEmailId;
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
public String getUserId() {
|
|
|
347 |
return userId;
|
|
|
348 |
}
|
|
|
349 |
|
|
|
350 |
public void setUserId(String userId) {
|
|
|
351 |
this.userId = userId;
|
|
|
352 |
}
|
|
|
353 |
|
|
|
354 |
public User getUser(Long userId) {
|
|
|
355 |
User user = null;
|
|
|
356 |
|
|
|
357 |
try {
|
|
|
358 |
userContextServiceClient = new UserClient().getClient();
|
|
|
359 |
user = userContextServiceClient.getUserById(userId);
|
|
|
360 |
} catch (UserContextException e) {
|
|
|
361 |
String errorString = "Could not fetch user for " + userId;
|
|
|
362 |
log.error(errorString, e);
|
|
|
363 |
addActionError(errorString);
|
|
|
364 |
} catch (TException e) {
|
|
|
365 |
String errorString = "Could not create client";
|
|
|
366 |
log.error(errorString, e);
|
|
|
367 |
addActionError(errorString);
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
return user;
|
|
|
371 |
}
|
|
|
372 |
|
|
|
373 |
public String getCustomerName() {
|
|
|
374 |
return customerName;
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
public void setCustomerName(String customerName) {
|
|
|
378 |
this.customerName = customerName;
|
|
|
379 |
}
|
| 4142 |
mandeep.dh |
380 |
|
|
|
381 |
public String getCategory() {
|
|
|
382 |
return category;
|
|
|
383 |
}
|
|
|
384 |
|
|
|
385 |
public void setCategory(String category) {
|
|
|
386 |
this.category = category;
|
|
|
387 |
}
|
| 14898 |
manish.sha |
388 |
|
|
|
389 |
public String getNotShowPmTickets() {
|
|
|
390 |
return notShowPmTickets;
|
|
|
391 |
}
|
|
|
392 |
|
| 14904 |
manish.sha |
393 |
public void setNotShowPmTickets(String notShowPmTickets) {
|
| 14898 |
manish.sha |
394 |
this.notShowPmTickets = notShowPmTickets;
|
|
|
395 |
}
|
| 16092 |
amit.gupta |
396 |
|
|
|
397 |
public String safeHtml(String htmlString){
|
|
|
398 |
try{
|
|
|
399 |
return StringEscapeUtils.escapeHtml(htmlString);
|
|
|
400 |
}catch (Exception e){
|
|
|
401 |
return "This ticket need to be ignored";
|
|
|
402 |
}
|
|
|
403 |
}
|
| 3339 |
mandeep.dh |
404 |
}
|