Subversion Repositories SmartDukaan

Rev

Rev 3397 | Rev 3519 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3397 Rev 3405
Line 5... Line 5...
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.ActivityType;
8
import in.shop2020.crm.Agent;
8
import in.shop2020.crm.Agent;
9
import in.shop2020.crm.SearchFilter;
9
import in.shop2020.crm.SearchFilter;
-
 
10
import in.shop2020.model.v1.user.User;
-
 
11
import in.shop2020.model.v1.user.UserContextException;
10
import in.shop2020.serving.auth.CRMAuthorizingRealm;
12
import in.shop2020.serving.auth.CRMAuthorizingRealm;
11
import in.shop2020.thrift.clients.CRMClient;
13
import in.shop2020.thrift.clients.CRMClient;
12
import in.shop2020.thrift.clients.HelperClient;
14
import in.shop2020.thrift.clients.HelperClient;
-
 
15
import in.shop2020.thrift.clients.UserClient;
13
import in.shop2020.util.CRMConstants;
16
import in.shop2020.util.CRMConstants;
14
import in.shop2020.utils.HelperService.Client;
17
import in.shop2020.utils.HelperService.Client;
15
 
18
 
16
import java.text.ParseException;
19
import java.text.ParseException;
17
import java.util.ArrayList;
20
import java.util.ArrayList;
Line 33... Line 36...
33
    private String            activityId;
36
    private String            activityId;
34
    private String            description;
37
    private String            description;
35
    private String            type;
38
    private String            type;
36
    private String            subject;
39
    private String            subject;
37
    private String            body;
40
    private String            body;
38
    private String            userEmailId;
-
 
39
    private String            customerMobileNumber;
41
    private String            customerMobileNumber;
40
    private String            creatorId;
42
    private String            creatorId;
41
    private String[]          agentIds;
43
    private String[]          agentIds;
42
    private String            startTimestamp;
44
    private String            startTimestamp;
43
    private String            endTimestamp;
45
    private String            endTimestamp;
-
 
46
    private String            customerEmailId;
-
 
47
    private String            customerName;
-
 
48
    private String            userId;
44
 
49
 
45
    public String index() {
50
    public String index() {
46
        try {
51
        try {
47
            SearchFilter searchFilter = new SearchFilter();
52
            SearchFilter searchFilter = new SearchFilter();
48
 
53
 
-
 
54
            if (activityId != null && !activityId.isEmpty()) {
-
 
55
                searchFilter.setActivityId(Long.parseLong(activityId));
-
 
56
            } else if (userId != null && !userId.isEmpty()) {
-
 
57
                searchFilter.setCustomerId(Long.parseLong(userId));
49
            if (creatorId != null && !creatorId.isEmpty()) {
58
            } else if (creatorId != null && !creatorId.isEmpty()) {
50
                searchFilter.setActivityCreatorIds(Collections.singletonList(Long.parseLong(creatorId)));
59
                searchFilter.setActivityCreatorIds(Collections
-
 
60
                        .singletonList(Long.parseLong(creatorId)));
51
                searchFilter.setIsActivityRead(false);
61
                searchFilter.setIsActivityRead(false);
52
            }
-
 
53
            else if (agentIds != null && agentIds.length != 0) {
62
            } else if (agentIds != null && agentIds.length != 0) {
54
                searchFilter.setActivityCreatorIds(new ArrayList<Long>());
63
                searchFilter.setActivityCreatorIds(new ArrayList<Long>());
55
                for (String agentId : agentIds) {
64
                for (String agentId : agentIds) {
-
 
65
                    searchFilter.getActivityCreatorIds().add(
56
                    searchFilter.getActivityCreatorIds().add(CRMAuthorizingRealm.getAgent(agentId).getId());
66
                            CRMAuthorizingRealm.getAgent(agentId).getId());
57
                }
67
                }
58
 
68
 
59
                try {
69
                try {
60
                    if (startTimestamp != null && !startTimestamp.isEmpty()) {
70
                    if (startTimestamp != null && !startTimestamp.isEmpty()) {
-
 
71
                        searchFilter.setStartTimestamp(SDF
61
                        searchFilter.setStartTimestamp(SDF.parse(startTimestamp).getTime());
72
                                .parse(startTimestamp).getTime());
62
                    }
73
                    }
63
 
74
 
64
                    if (endTimestamp != null && !endTimestamp.isEmpty()) {
75
                    if (endTimestamp != null && !endTimestamp.isEmpty()) {
65
                        searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());
76
                        searchFilter.setEndTimestamp(SDF.parse(endTimestamp)
-
 
77
                                .getTime());
66
                    }
78
                    }
67
                }
-
 
68
                catch (ParseException e) {
79
                } catch (ParseException e) {
69
                    log.error("Error parsing timestamps", e);
80
                    log.error("Error parsing timestamps", e);
70
                }
81
                }
71
            }
82
            } else {
72
            else {
83
                searchFilter.setActivityCreatorIds(Collections
73
                searchFilter.setActivityCreatorIds(Collections.singletonList(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId()));
84
                        .singletonList(CRMAuthorizingRealm.getAgent(
-
 
85
                                currentAgentEmailId).getId()));
74
            }
86
            }
75
 
87
 
76
            crmServiceClient         = new CRMClient().getClient();
88
            crmServiceClient = new CRMClient().getClient();
77
            activities = crmServiceClient.getActivities(searchFilter);
89
            activities = crmServiceClient.getActivities(searchFilter);
78
        } catch (TException e) {
90
        } catch (TException e) {
79
            log.error("Error while retrieving activities for "
91
            log.error("Error while retrieving activities for "
80
                    + currentAgentEmailId, e);
92
                    + currentAgentEmailId, e);
-
 
93
        } catch (NumberFormatException e) {
-
 
94
            log.error("Error parsing userId: " + userId, e);
81
        }
95
        }
82
 
96
 
83
        return INDEX;
97
        return INDEX;
84
    }
98
    }
85
 
99
 
-
 
100
    public String editNew() {
-
 
101
        subject = "";
-
 
102
        return EDIT_NEW;
-
 
103
    }
-
 
104
 
86
    public String create() throws Exception {
105
    public String create() throws Exception {
87
        Activity activity = new Activity();
106
        Activity activity = new Activity();
88
        activity.setDescription(description);
107
        activity.setDescription(description);
89
        activity.setType(ActivityType.valueOf(type));
108
        activity.setType(ActivityType.valueOf(type));
90
        activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
109
        activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId)
-
 
110
                .getId());
-
 
111
 
-
 
112
        if (userId != null && !userId.isEmpty()) {
-
 
113
            activity.setCustomerId(Long.parseLong(userId));
-
 
114
        } else {
-
 
115
            User user = null;
-
 
116
            userContextServiceClient = new UserClient().getClient();
-
 
117
 
-
 
118
            try {
-
 
119
                if (customerName != null && !customerName.isEmpty()) {
-
 
120
                    activity.setCustomerName(customerName);
-
 
121
                }
-
 
122
 
-
 
123
                if (customerEmailId != null && !customerEmailId.isEmpty()) {
-
 
124
                    activity.setCustomerEmailId(customerEmailId);
-
 
125
                    user = userContextServiceClient
-
 
126
                            .getUserByEmail(customerEmailId);
-
 
127
                }
91
 
128
 
-
 
129
                if ((user == null || user.getUserId() == -1)
-
 
130
                        && customerMobileNumber != null
92
        if (customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
131
                        && !customerMobileNumber.isEmpty()) {
93
            activity.setCustomerMobileNumber(customerMobileNumber);
132
                    activity.setCustomerMobileNumber(customerMobileNumber);
-
 
133
                    user = userContextServiceClient.getUserByMobileNumber(Long
-
 
134
                            .parseLong(customerMobileNumber));
-
 
135
                }
-
 
136
            } catch (UserContextException e) {
-
 
137
                log.error("Could not fetch user for: " + customerEmailId + " "
-
 
138
                        + customerMobileNumber + " " + customerName, e);
-
 
139
            }
-
 
140
 
-
 
141
            if (user != null && user.getUserId() != -1) {
-
 
142
                activity.setCustomerId(user.getUserId());
-
 
143
            }
94
        }
144
        }
95
 
145
 
96
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
146
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
97
            log.info("Sending mail");
147
            log.info("Sending mail");
98
            Client helperClient = new HelperClient().getClient();
148
            Client helperClient = new HelperClient().getClient();
99
            activity.setUserEmailId(helperClient.saveUserEmailForSending(
149
            activity.setUserEmailId(helperClient.saveUserEmailForSending(
100
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject, body,
150
                    customerEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
101
                    null, CRMConstants.CRM_EMAIL_TYPE));
151
                    "<pre>" + body + "</pre>", null, CRMConstants.CRM_EMAIL_TYPE));
102
 
152
 
103
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: "
153
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: "
104
                    + body);
154
                    + body);
105
        }
155
        }
106
 
156
 
107
        crmServiceClient         = new CRMClient().getClient();
157
        crmServiceClient = new CRMClient().getClient();
108
        crmServiceClient.insertActivity(activity);
158
        activityId = String.valueOf(crmServiceClient.insertActivity(activity));
109
 
159
 
110
        return index();
160
        return index();
111
    }
161
    }
112
 
162
 
113
    public String markAsRead()
163
    public String markAsRead() {
114
    {
-
 
115
        try {
164
        try {
116
            crmServiceClient         = new CRMClient().getClient();
165
            crmServiceClient = new CRMClient().getClient();
-
 
166
            crmServiceClient.markAsRead(Long.parseLong(activityId),
117
            crmServiceClient.markAsRead(Long.parseLong(activityId), CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
167
                    CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
118
        } catch (NumberFormatException e) {
168
        } catch (NumberFormatException e) {
119
            log.error("Could not parse activity id from" + activityId, e);
169
            log.error("Could not parse activity id from" + activityId, e);
120
        } catch (TException e) {
170
        } catch (TException e) {
121
            log.error("Could not mark the activityId: " + activityId + " as read", e);
171
            log.error("Could not mark the activityId: " + activityId
-
 
172
                    + " as read", e);
122
        }
173
        }
123
 
174
 
124
        return INDEX;
175
        return index();
125
    }
176
    }
126
 
177
 
127
    public ActivityType[] getActivityTypes() {
178
    public ActivityType[] getActivityTypes() {
128
        return ActivityType.values();
179
        return ActivityType.values();
129
    }
180
    }
Line 162... Line 213...
162
 
213
 
163
    public void setBody(String body) {
214
    public void setBody(String body) {
164
        this.body = body;
215
        this.body = body;
165
    }
216
    }
166
 
217
 
167
    public String getUserEmailId() {
-
 
168
        return userEmailId;
-
 
169
    }
-
 
170
 
-
 
171
    public void setUserEmailId(String userEmailId) {
-
 
172
        this.userEmailId = userEmailId;
-
 
173
    }
-
 
174
 
-
 
175
    public String getCustomerMobileNumber() {
218
    public String getCustomerMobileNumber() {
176
        return customerMobileNumber;
219
        return customerMobileNumber;
177
    }
220
    }
178
 
221
 
179
    public void setCustomerMobileNumber(String customerMobileNumber) {
222
    public void setCustomerMobileNumber(String customerMobileNumber) {
Line 225... Line 268...
225
    }
268
    }
226
 
269
 
227
    public void setActivities(List<Activity> activities) {
270
    public void setActivities(List<Activity> activities) {
228
        this.activities = activities;
271
        this.activities = activities;
229
    }
272
    }
-
 
273
 
-
 
274
    public String getCustomerEmailId() {
-
 
275
        return customerEmailId;
-
 
276
    }
-
 
277
 
-
 
278
    public void setCustomerEmailId(String customerEmailId) {
-
 
279
        this.customerEmailId = customerEmailId;
-
 
280
    }
-
 
281
 
-
 
282
    public String getUserId() {
-
 
283
        return userId;
-
 
284
    }
-
 
285
 
-
 
286
    public void setUserId(String userId) {
-
 
287
        this.userId = userId;
-
 
288
    }
-
 
289
 
-
 
290
    public User getUser(Long userId) {
-
 
291
        User user = null;
-
 
292
 
-
 
293
        try {
-
 
294
            userContextServiceClient = new UserClient().getClient();
-
 
295
            user = userContextServiceClient.getUserById(userId);
-
 
296
        } catch (UserContextException e) {
-
 
297
            String errorString = "Could not fetch user for " + userId;
-
 
298
            log.error(errorString, e);
-
 
299
            addActionError(errorString);
-
 
300
        } catch (TException e) {
-
 
301
            String errorString = "Could not create client";
-
 
302
            log.error(errorString, e);
-
 
303
            addActionError(errorString);
-
 
304
        }
-
 
305
 
-
 
306
        return user;
-
 
307
    }
-
 
308
 
-
 
309
    public String getCustomerName() {
-
 
310
        return customerName;
-
 
311
    }
-
 
312
 
-
 
313
    public void setCustomerName(String customerName) {
-
 
314
        this.customerName = customerName;
-
 
315
    }
230
}
316
}