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;
3090 mandeep.dh 44
 
45
    public String index() throws TException, UserContextException {
46
        createServiceClients();
3269 mandeep.dh 47
        List<Activity> activityList = crmServiceClient.getActivities(Long.parseLong(userId));
3090 mandeep.dh 48
        if (activityList != null) {
49
            for (Activity activity : activityList) {
50
                activities.put(activity.getId(), activity);
51
            }
52
        }
53
 
3269 mandeep.dh 54
        user = userContextServiceClient.getUserById(Long.parseLong(userId));
3090 mandeep.dh 55
 
56
        return INDEX;
57
    }
58
 
3106 mandeep.dh 59
    public String editNew() {
3228 mandeep.dh 60
        createServiceClients();
61
 
62
        try {
3269 mandeep.dh 63
            if (user != null && !userId.isEmpty()) {
64
                user = userContextServiceClient.getUserById(Long.parseLong(userId));
65
            }
3228 mandeep.dh 66
            subject = "";
67
        } catch (UserContextException e) {
68
            String errorMessage = "Could not fetch user for " + userId;
69
            addActionError(errorMessage);
70
            log.error(errorMessage, e);
71
            return EXCEPTION;
72
        } catch (TException e) {
73
            String errorMessage = "Could not fetch user for " + userId;
74
            addActionError(errorMessage);
75
            log.error(errorMessage, e);
76
            return EXCEPTION;
77
        }
78
 
3090 mandeep.dh 79
        return EDIT_NEW;
80
    }
81
 
82
    public Map<Long, Activity> getActivities() {
83
        return activities;
84
    }
85
 
86
    public TicketStatus[] getTicketStatuses() {
87
        return TicketStatus.values();
88
    }
89
 
90
    public TicketPriority[] getTicketPriorities() {
91
        return TicketPriority.values();
92
    }
93
 
3106 mandeep.dh 94
    public ActivityType[] getActivityTypes() {
95
        return ActivityType.values();
3090 mandeep.dh 96
    }
97
 
98
    public User getUser() {
99
        return user;
100
    }
101
 
102
    public Ticket getTicket(long activityId) throws TException {
103
        Ticket ticket = null;
104
        Activity activity = crmServiceClient.getActivity(activityId);
105
        if (activity != null && activity.getTicketId() != 0) {
106
            ticket = crmServiceClient.getTicket(activity.getTicketId());
3106 mandeep.dh 107
        } else {
3090 mandeep.dh 108
            ticket = new Ticket();
109
        }
110
 
111
        return ticket;
112
    }
113
 
114
    public String create() throws Exception {
115
        createServiceClients();
3228 mandeep.dh 116
 
3090 mandeep.dh 117
        Activity activity = new Activity();
3106 mandeep.dh 118
        activity.setDescription(description);
119
        activity.setType(ActivityType.valueOf(type));
120
        activity.setCreatorId(crmServiceClient.getAgentByEmailId(
3090 mandeep.dh 121
                currentAgentEmailId).getId());
122
 
3269 mandeep.dh 123
        if (userId != null && !userId.isEmpty()) {
124
            activity.setCustomerId(Long.parseLong(userId));
125
        }
126
 
127
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
3228 mandeep.dh 128
            log.info("Sending mail");
129
            Client helperClient = new HelperClient().getClient();
130
            activity.setEmailId(helperClient.saveUserEmailForSending(
131
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
132
                    body, null, CRMConstants.CRM_EMAIL_TYPE));
133
 
134
            // We change activityType to OTHER when pop up box for email
135
            // closes
3234 mandeep.dh 136
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: " + body);
3228 mandeep.dh 137
        }
138
 
3090 mandeep.dh 139
        crmServiceClient.insertActivity(activity);
140
 
141
        return index();
142
    }
143
 
3106 mandeep.dh 144
    public String getLoggerRole() throws TException {
3090 mandeep.dh 145
        createServiceClients();
3106 mandeep.dh 146
        return crmServiceClient.getRoleNamesForAgent(currentAgentEmailId)
147
                .get(0);
148
    }
149
 
150
    public List<Agent> getAllAgents() throws TException {
151
        createServiceClients();
3090 mandeep.dh 152
        return crmServiceClient.getAllAgents();
153
    }
154
 
155
    public Agent getAgent(long agentId) throws TException {
156
        return crmServiceClient.getAgent(agentId);
157
    }
158
 
159
    public void setDescription(String description) {
160
        this.description = description;
161
    }
162
 
3269 mandeep.dh 163
    public String getUserId() {
3106 mandeep.dh 164
        return userId;
3090 mandeep.dh 165
    }
166
 
3106 mandeep.dh 167
    public String getType() {
168
        return type;
3090 mandeep.dh 169
    }
170
 
3106 mandeep.dh 171
    public void setType(String type) {
172
        this.type = type;
3090 mandeep.dh 173
    }
174
 
3106 mandeep.dh 175
    public String getDescription() {
176
        return description;
3090 mandeep.dh 177
    }
178
 
3106 mandeep.dh 179
    public void setActivities(Map<Long, Activity> activities) {
180
        this.activities = activities;
3090 mandeep.dh 181
    }
182
 
3269 mandeep.dh 183
    public void setUserId(String userId) {
3106 mandeep.dh 184
        this.userId = userId;
3090 mandeep.dh 185
    }
3228 mandeep.dh 186
 
187
    public String getSubject() {
188
        return subject;
189
    }
190
 
191
    public void setSubject(String subject) {
192
        this.subject = subject;
193
    }
194
 
195
    public String getBody() {
196
        return body;
197
    }
198
 
199
    public void setBody(String body) {
200
        this.body = body;
201
    }
202
 
203
    public String getUserEmailId() {
204
        return userEmailId;
205
    }
206
 
207
    public void setUserEmailId(String userEmailId) {
208
        this.userEmailId = userEmailId;
209
    }
3090 mandeep.dh 210
}