Subversion Repositories SmartDukaan

Rev

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

Rev 3339 Rev 3390
Line 4... Line 4...
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
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;
-
 
10
import in.shop2020.serving.auth.CRMAuthorizingRealm;
-
 
11
import in.shop2020.thrift.clients.CRMClient;
9
import in.shop2020.thrift.clients.HelperClient;
12
import in.shop2020.thrift.clients.HelperClient;
10
import in.shop2020.util.CRMConstants;
13
import in.shop2020.util.CRMConstants;
11
import in.shop2020.utils.HelperService.Client;
14
import in.shop2020.utils.HelperService.Client;
12
 
15
 
-
 
16
import java.util.Collections;
13
import java.util.List;
17
import java.util.List;
14
 
18
 
15
import org.apache.thrift.TException;
19
import org.apache.thrift.TException;
16
 
20
 
17
/**
21
/**
Line 22... Line 26...
22
    /**
26
    /**
23
     * 
27
     * 
24
     */
28
     */
25
    private static final long serialVersionUID = 1L;
29
    private static final long serialVersionUID = 1L;
26
    private List<Activity>    activities;
30
    private List<Activity>    activities;
-
 
31
    private String            activityId;
27
    private String            description;
32
    private String            description;
28
    private String            type;
33
    private String            type;
29
    private String            subject;
34
    private String            subject;
30
    private String            body;
35
    private String            body;
31
    private String            userEmailId;
36
    private String            userEmailId;
32
    private String            customerMobileNumber;
37
    private String            customerMobileNumber;
33
    private String            creatorId;
38
    private String            creatorId;
34
 
39
 
35
    public String index() {
40
    public String index() {
36
        createServiceClients();
-
 
37
        try {
41
        try {
-
 
42
            SearchFilter searchFilter = new SearchFilter();
-
 
43
            crmServiceClient         = new CRMClient().getClient();
-
 
44
 
38
            if (creatorId != null && !creatorId.isEmpty()) {
45
            if (creatorId != null && !creatorId.isEmpty()) {
39
                activities = crmServiceClient.getActivitiesByCreator(Long
46
                searchFilter.setActivityCreatorIds(Collections.singletonList(Long.parseLong(creatorId)));
40
                        .parseLong(creatorId));
47
                searchFilter.setIsActivityRead(false);
-
 
48
                activities = crmServiceClient.getActivities(searchFilter);
41
            } else {
49
            } else {
42
                activities = crmServiceClient
-
 
43
                        .getActivitiesByCreator(crmServiceClient
50
                searchFilter.setActivityCreatorIds(Collections.singletonList(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId()));
44
                                .getAgentByEmailId(currentAgentEmailId).getId());
51
                activities = crmServiceClient.getActivities(searchFilter);
45
            }
52
            }
46
        } catch (TException e) {
53
        } catch (TException e) {
47
            log.error("Error while retrieving activities for "
54
            log.error("Error while retrieving activities for "
48
                    + currentAgentEmailId, e);
55
                    + currentAgentEmailId, e);
49
        }
56
        }
50
 
57
 
51
        return INDEX;
58
        return INDEX;
52
    }
59
    }
53
 
60
 
54
    public String create() throws Exception {
61
    public String create() throws Exception {
55
        createServiceClients();
-
 
56
 
-
 
57
        Activity activity = new Activity();
62
        Activity activity = new Activity();
58
        activity.setDescription(description);
63
        activity.setDescription(description);
59
        activity.setType(ActivityType.valueOf(type));
64
        activity.setType(ActivityType.valueOf(type));
60
        activity.setCreatorId(crmServiceClient.getAgentByEmailId(
65
        activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
61
                currentAgentEmailId).getId());
-
 
62
 
66
 
63
        if (customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
67
        if (customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
64
            activity.setCustomerMobileNumber(customerMobileNumber);
68
            activity.setCustomerMobileNumber(customerMobileNumber);
65
        }
69
        }
66
 
70
 
67
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
71
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
68
            log.info("Sending mail");
72
            log.info("Sending mail");
69
            Client helperClient = new HelperClient().getClient();
73
            Client helperClient = new HelperClient().getClient();
70
            activity.setEmailId(helperClient.saveUserEmailForSending(
74
            activity.setUserEmailId(helperClient.saveUserEmailForSending(
71
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject, body,
75
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject, body,
72
                    null, CRMConstants.CRM_EMAIL_TYPE));
76
                    null, CRMConstants.CRM_EMAIL_TYPE));
73
 
77
 
74
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: "
78
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: "
75
                    + body);
79
                    + body);
76
        }
80
        }
77
 
81
 
-
 
82
        crmServiceClient         = new CRMClient().getClient();
78
        crmServiceClient.insertActivity(activity);
83
        crmServiceClient.insertActivity(activity);
79
 
84
 
80
        return index();
85
        return index();
81
    }
86
    }
82
 
87
 
-
 
88
    public String markAsRead()
-
 
89
    {
-
 
90
        try {
-
 
91
            crmServiceClient         = new CRMClient().getClient();
-
 
92
            crmServiceClient.markAsRead(Long.parseLong(activityId), CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
-
 
93
        } catch (NumberFormatException e) {
-
 
94
            log.error("Could not parse activity id from" + activityId, e);
-
 
95
        } catch (TException e) {
-
 
96
            log.error("Could not mark the activityId: " + activityId + " as read", e);
-
 
97
        }
-
 
98
 
-
 
99
        return INDEX;
-
 
100
    }
-
 
101
 
83
    public ActivityType[] getActivityTypes() {
102
    public ActivityType[] getActivityTypes() {
84
        return ActivityType.values();
103
        return ActivityType.values();
85
    }
104
    }
86
 
105
 
87
    public Agent getAgent(long agentId) throws TException {
106
    public Agent getAgent(long agentId) throws TException {
88
        return crmServiceClient.getAgent(agentId);
107
        return CRMAuthorizingRealm.getAgent(agentId);
89
    }
108
    }
90
 
109
 
91
    public String getDescription() {
110
    public String getDescription() {
92
        return description;
111
        return description;
93
    }
112
    }
Line 145... Line 164...
145
    }
164
    }
146
 
165
 
147
    public void setCreatorId(String creatorId) {
166
    public void setCreatorId(String creatorId) {
148
        this.creatorId = creatorId;
167
        this.creatorId = creatorId;
149
    }
168
    }
-
 
169
 
-
 
170
    public String getActivityId() {
-
 
171
        return activityId;
-
 
172
    }
-
 
173
 
-
 
174
    public void setActivityId(String activityId) {
-
 
175
        this.activityId = activityId;
-
 
176
    }
150
}
177
}