Subversion Repositories SmartDukaan

Rev

Rev 3339 | Rev 3397 | 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;
10
import in.shop2020.serving.auth.CRMAuthorizingRealm;
11
import in.shop2020.thrift.clients.CRMClient;
3339 mandeep.dh 12
import in.shop2020.thrift.clients.HelperClient;
13
import in.shop2020.util.CRMConstants;
14
import in.shop2020.utils.HelperService.Client;
15
 
3390 mandeep.dh 16
import java.util.Collections;
3339 mandeep.dh 17
import java.util.List;
18
 
19
import org.apache.thrift.TException;
20
 
21
/**
22
 * @author mandeep
23
 * 
24
 */
25
public class ActivityController extends BaseController {
26
    /**
27
     * 
28
     */
29
    private static final long serialVersionUID = 1L;
30
    private List<Activity>    activities;
3390 mandeep.dh 31
    private String            activityId;
3339 mandeep.dh 32
    private String            description;
33
    private String            type;
34
    private String            subject;
35
    private String            body;
36
    private String            userEmailId;
37
    private String            customerMobileNumber;
38
    private String            creatorId;
39
 
40
    public String index() {
41
        try {
3390 mandeep.dh 42
            SearchFilter searchFilter = new SearchFilter();
43
            crmServiceClient         = new CRMClient().getClient();
44
 
3339 mandeep.dh 45
            if (creatorId != null && !creatorId.isEmpty()) {
3390 mandeep.dh 46
                searchFilter.setActivityCreatorIds(Collections.singletonList(Long.parseLong(creatorId)));
47
                searchFilter.setIsActivityRead(false);
48
                activities = crmServiceClient.getActivities(searchFilter);
3339 mandeep.dh 49
            } else {
3390 mandeep.dh 50
                searchFilter.setActivityCreatorIds(Collections.singletonList(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId()));
51
                activities = crmServiceClient.getActivities(searchFilter);
3339 mandeep.dh 52
            }
53
        } catch (TException e) {
54
            log.error("Error while retrieving activities for "
55
                    + currentAgentEmailId, e);
56
        }
57
 
58
        return INDEX;
59
    }
60
 
61
    public String create() throws Exception {
62
        Activity activity = new Activity();
63
        activity.setDescription(description);
64
        activity.setType(ActivityType.valueOf(type));
3390 mandeep.dh 65
        activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
3339 mandeep.dh 66
 
67
        if (customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
68
            activity.setCustomerMobileNumber(customerMobileNumber);
69
        }
70
 
71
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
72
            log.info("Sending mail");
73
            Client helperClient = new HelperClient().getClient();
3390 mandeep.dh 74
            activity.setUserEmailId(helperClient.saveUserEmailForSending(
3339 mandeep.dh 75
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject, body,
76
                    null, CRMConstants.CRM_EMAIL_TYPE));
77
 
78
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: "
79
                    + body);
80
        }
81
 
3390 mandeep.dh 82
        crmServiceClient         = new CRMClient().getClient();
3339 mandeep.dh 83
        crmServiceClient.insertActivity(activity);
84
 
85
        return index();
86
    }
87
 
3390 mandeep.dh 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
 
3339 mandeep.dh 102
    public ActivityType[] getActivityTypes() {
103
        return ActivityType.values();
104
    }
105
 
106
    public Agent getAgent(long agentId) throws TException {
3390 mandeep.dh 107
        return CRMAuthorizingRealm.getAgent(agentId);
3339 mandeep.dh 108
    }
109
 
110
    public String getDescription() {
111
        return description;
112
    }
113
 
114
    public void setDescription(String description) {
115
        this.description = description;
116
    }
117
 
118
    public String getType() {
119
        return type;
120
    }
121
 
122
    public void setType(String type) {
123
        this.type = type;
124
    }
125
 
126
    public String getSubject() {
127
        return subject;
128
    }
129
 
130
    public void setSubject(String subject) {
131
        this.subject = subject;
132
    }
133
 
134
    public String getBody() {
135
        return body;
136
    }
137
 
138
    public void setBody(String body) {
139
        this.body = body;
140
    }
141
 
142
    public String getUserEmailId() {
143
        return userEmailId;
144
    }
145
 
146
    public void setUserEmailId(String userEmailId) {
147
        this.userEmailId = userEmailId;
148
    }
149
 
150
    public String getCustomerMobileNumber() {
151
        return customerMobileNumber;
152
    }
153
 
154
    public void setCustomerMobileNumber(String customerMobileNumber) {
155
        this.customerMobileNumber = customerMobileNumber;
156
    }
157
 
158
    public List<Activity> getActivities() {
159
        return activities;
160
    }
161
 
162
    public String getCreatorId() {
163
        return creatorId;
164
    }
165
 
166
    public void setCreatorId(String creatorId) {
167
        this.creatorId = creatorId;
168
    }
3390 mandeep.dh 169
 
170
    public String getActivityId() {
171
        return activityId;
172
    }
173
 
174
    public void setActivityId(String activityId) {
175
        this.activityId = activityId;
176
    }
3339 mandeep.dh 177
}