Subversion Repositories SmartDukaan

Rev

Rev 14906 | Rev 16092 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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