Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3090 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
6
import in.shop2020.crm.Activity;
3106 mandeep.dh 7
import in.shop2020.crm.ActivityType;
3090 mandeep.dh 8
import in.shop2020.crm.Agent;
9
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.TicketPriority;
11
import in.shop2020.crm.TicketStatus;
12
import in.shop2020.model.v1.user.User;
13
import in.shop2020.model.v1.user.UserContextException;
3228 mandeep.dh 14
import in.shop2020.thrift.clients.HelperClient;
15
import in.shop2020.util.CRMConstants;
16
import in.shop2020.utils.HelperService.Client;
3090 mandeep.dh 17
 
18
import java.util.LinkedHashMap;
19
import java.util.List;
20
import java.util.Map;
21
 
22
import org.apache.thrift.TException;
23
 
24
/**
25
 * Action class for activity pages in CRM.
3106 mandeep.dh 26
 * 
3090 mandeep.dh 27
 * @author mandeep
28
 */
29
public class UserActivityController extends BaseController {
30
    /**
31
     * 
32
     */
33
    private static final long   serialVersionUID = 1L;
34
 
35
    private Map<Long, Activity> activities       = new LinkedHashMap<Long, Activity>();
3269 mandeep.dh 36
 
37
    private String              userId;
3090 mandeep.dh 38
    private String              description;
39
    private User                user;
3106 mandeep.dh 40
    private String              type;
3228 mandeep.dh 41
    private String              subject;
42
    private String              body;
43
    private String              userEmailId;
3269 mandeep.dh 44
    private String              customerMobileNumber;
3090 mandeep.dh 45
 
46
    public String index() throws TException, UserContextException {
47
        createServiceClients();
3269 mandeep.dh 48
        List<Activity> activityList = crmServiceClient.getActivities(Long.parseLong(userId));
3090 mandeep.dh 49
        if (activityList != null) {
50
            for (Activity activity : activityList) {
51
                activities.put(activity.getId(), activity);
52
            }
53
        }
54
 
3269 mandeep.dh 55
        user = userContextServiceClient.getUserById(Long.parseLong(userId));
3090 mandeep.dh 56
 
57
        return INDEX;
58
    }
59
 
3106 mandeep.dh 60
    public String editNew() {
3228 mandeep.dh 61
        createServiceClients();
62
 
63
        try {
3269 mandeep.dh 64
            if (user != null && !userId.isEmpty()) {
65
                user = userContextServiceClient.getUserById(Long.parseLong(userId));
66
            }
3228 mandeep.dh 67
            subject = "";
68
        } catch (UserContextException e) {
69
            String errorMessage = "Could not fetch user for " + userId;
70
            addActionError(errorMessage);
71
            log.error(errorMessage, e);
72
            return EXCEPTION;
73
        } catch (TException e) {
74
            String errorMessage = "Could not fetch user for " + userId;
75
            addActionError(errorMessage);
76
            log.error(errorMessage, e);
77
            return EXCEPTION;
78
        }
79
 
3090 mandeep.dh 80
        return EDIT_NEW;
81
    }
82
 
83
    public Map<Long, Activity> getActivities() {
84
        return activities;
85
    }
86
 
87
    public TicketStatus[] getTicketStatuses() {
88
        return TicketStatus.values();
89
    }
90
 
91
    public TicketPriority[] getTicketPriorities() {
92
        return TicketPriority.values();
93
    }
94
 
3106 mandeep.dh 95
    public ActivityType[] getActivityTypes() {
96
        return ActivityType.values();
3090 mandeep.dh 97
    }
98
 
99
    public User getUser() {
100
        return user;
101
    }
102
 
103
    public Ticket getTicket(long activityId) throws TException {
104
        Ticket ticket = null;
105
        Activity activity = crmServiceClient.getActivity(activityId);
106
        if (activity != null && activity.getTicketId() != 0) {
107
            ticket = crmServiceClient.getTicket(activity.getTicketId());
3106 mandeep.dh 108
        } else {
3090 mandeep.dh 109
            ticket = new Ticket();
110
        }
111
 
112
        return ticket;
113
    }
114
 
115
    public String create() throws Exception {
116
        createServiceClients();
3228 mandeep.dh 117
 
3090 mandeep.dh 118
        Activity activity = new Activity();
3106 mandeep.dh 119
        activity.setDescription(description);
120
        activity.setType(ActivityType.valueOf(type));
121
        activity.setCreatorId(crmServiceClient.getAgentByEmailId(
3090 mandeep.dh 122
                currentAgentEmailId).getId());
123
 
3269 mandeep.dh 124
        if (userId != null && !userId.isEmpty()) {
125
            activity.setCustomerId(Long.parseLong(userId));
126
        }
127
 
128
        if (customerMobileNumber != null && !customerMobileNumber.isEmpty()) {
129
            activity.setCustomerMobileNumber(customerMobileNumber);
130
        }
131
 
132
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
3228 mandeep.dh 133
            log.info("Sending mail");
134
            Client helperClient = new HelperClient().getClient();
135
            activity.setEmailId(helperClient.saveUserEmailForSending(
136
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
137
                    body, null, CRMConstants.CRM_EMAIL_TYPE));
138
 
139
            // We change activityType to OTHER when pop up box for email
140
            // closes
3234 mandeep.dh 141
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: " + body);
3228 mandeep.dh 142
        }
143
 
3090 mandeep.dh 144
        crmServiceClient.insertActivity(activity);
145
 
146
        return index();
147
    }
148
 
3106 mandeep.dh 149
    public String getLoggerRole() throws TException {
3090 mandeep.dh 150
        createServiceClients();
3106 mandeep.dh 151
        return crmServiceClient.getRoleNamesForAgent(currentAgentEmailId)
152
                .get(0);
153
    }
154
 
155
    public List<Agent> getAllAgents() throws TException {
156
        createServiceClients();
3090 mandeep.dh 157
        return crmServiceClient.getAllAgents();
158
    }
159
 
160
    public Agent getAgent(long agentId) throws TException {
161
        return crmServiceClient.getAgent(agentId);
162
    }
163
 
164
    public void setDescription(String description) {
165
        this.description = description;
166
    }
167
 
3269 mandeep.dh 168
    public String getUserId() {
3106 mandeep.dh 169
        return userId;
3090 mandeep.dh 170
    }
171
 
3106 mandeep.dh 172
    public String getType() {
173
        return type;
3090 mandeep.dh 174
    }
175
 
3106 mandeep.dh 176
    public void setType(String type) {
177
        this.type = type;
3090 mandeep.dh 178
    }
179
 
3106 mandeep.dh 180
    public String getDescription() {
181
        return description;
3090 mandeep.dh 182
    }
183
 
3106 mandeep.dh 184
    public void setActivities(Map<Long, Activity> activities) {
185
        this.activities = activities;
3090 mandeep.dh 186
    }
187
 
3269 mandeep.dh 188
    public void setUserId(String userId) {
3106 mandeep.dh 189
        this.userId = userId;
3090 mandeep.dh 190
    }
3228 mandeep.dh 191
 
192
    public String getSubject() {
193
        return subject;
194
    }
195
 
196
    public void setSubject(String subject) {
197
        this.subject = subject;
198
    }
199
 
200
    public String getBody() {
201
        return body;
202
    }
203
 
204
    public void setBody(String body) {
205
        this.body = body;
206
    }
207
 
208
    public String getUserEmailId() {
209
        return userEmailId;
210
    }
211
 
212
    public void setUserEmailId(String userEmailId) {
213
        this.userEmailId = userEmailId;
214
    }
3269 mandeep.dh 215
 
216
    public String getCustomerMobileNumber() {
217
        return customerMobileNumber;
218
    }
219
 
220
    public void setCustomerMobileNumber(String customerMobileNumber) {
221
        this.customerMobileNumber = customerMobileNumber;
222
    }
3090 mandeep.dh 223
}