Subversion Repositories SmartDukaan

Rev

Rev 3339 | 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;
9
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.TicketPriority;
11
import in.shop2020.crm.TicketPriority;
11
import in.shop2020.crm.TicketStatus;
12
import in.shop2020.crm.TicketStatus;
12
import in.shop2020.model.v1.user.User;
13
import in.shop2020.model.v1.user.User;
13
import in.shop2020.model.v1.user.UserContextException;
14
import in.shop2020.model.v1.user.UserContextException;
-
 
15
import in.shop2020.serving.auth.CRMAuthorizingRealm;
-
 
16
import in.shop2020.thrift.clients.CRMClient;
14
import in.shop2020.thrift.clients.HelperClient;
17
import in.shop2020.thrift.clients.HelperClient;
-
 
18
import in.shop2020.thrift.clients.UserClient;
15
import in.shop2020.util.CRMConstants;
19
import in.shop2020.util.CRMConstants;
16
import in.shop2020.utils.HelperService.Client;
20
import in.shop2020.utils.HelperService.Client;
17
 
21
 
18
import java.util.LinkedHashMap;
22
import java.util.LinkedHashMap;
19
import java.util.List;
23
import java.util.List;
20
import java.util.Map;
24
import java.util.Map;
21
 
25
 
-
 
26
import org.apache.shiro.SecurityUtils;
22
import org.apache.thrift.TException;
27
import org.apache.thrift.TException;
23
 
28
 
24
/**
29
/**
25
 * Action class for activity pages in CRM.
30
 * Action class for activity pages in CRM.
26
 * 
31
 * 
Line 41... Line 46...
41
    private String              subject;
46
    private String              subject;
42
    private String              body;
47
    private String              body;
43
    private String              userEmailId;
48
    private String              userEmailId;
44
 
49
 
45
    public String index() throws TException, UserContextException {
50
    public String index() throws TException, UserContextException {
46
        createServiceClients();
51
        SearchFilter searchFilter = new SearchFilter();
-
 
52
        searchFilter.setCustomerId(Long.parseLong(userId));
-
 
53
        crmServiceClient         = new CRMClient().getClient();
-
 
54
 
47
        List<Activity> activityList = crmServiceClient.getActivities(Long.parseLong(userId));
55
        List<Activity> activityList = crmServiceClient.getActivities(searchFilter);
48
        if (activityList != null) {
56
        if (activityList != null) {
49
            for (Activity activity : activityList) {
57
            for (Activity activity : activityList) {
50
                activities.put(activity.getId(), activity);
58
                activities.put(activity.getId(), activity);
51
            }
59
            }
52
        }
60
        }
Line 55... Line 63...
55
 
63
 
56
        return INDEX;
64
        return INDEX;
57
    }
65
    }
58
 
66
 
59
    public String editNew() {
67
    public String editNew() {
60
        createServiceClients();
-
 
61
 
-
 
62
        try {
68
        try {
63
            if (user != null && !userId.isEmpty()) {
69
            if (userId != null && !userId.isEmpty()) {
-
 
70
                userContextServiceClient = new UserClient().getClient();
64
                user = userContextServiceClient.getUserById(Long.parseLong(userId));
71
                user = userContextServiceClient.getUserById(Long.parseLong(userId));
65
            }
72
            }
66
            subject = "";
73
            subject = "";
67
        } catch (UserContextException e) {
74
        } catch (UserContextException e) {
68
            String errorMessage = "Could not fetch user for " + userId;
75
            String errorMessage = "Could not fetch user for " + userId;
Line 98... Line 105...
98
    public User getUser() {
105
    public User getUser() {
99
        return user;
106
        return user;
100
    }
107
    }
101
 
108
 
102
    public Ticket getTicket(long activityId) throws TException {
109
    public Ticket getTicket(long activityId) throws TException {
-
 
110
        SearchFilter searchFilter = new SearchFilter();
-
 
111
        searchFilter.setActivityId(activityId);
-
 
112
        crmServiceClient         = new CRMClient().getClient();
-
 
113
 
103
        Ticket ticket = null;
114
        Ticket ticket = null;
-
 
115
        Activity activity = null;
104
        Activity activity = crmServiceClient.getActivity(activityId);
116
        List<Activity> activities = crmServiceClient.getActivities(searchFilter);
105
        if (activity != null && activity.getTicketId() != 0) {
117
        if (activities != null && !activities.isEmpty()) {
106
            ticket = crmServiceClient.getTicket(activity.getTicketId());
118
            activity = activities.get(0);
107
        } else {
119
        }
-
 
120
 
-
 
121
        if (activity != null && activity.isSetTicketId()) {
-
 
122
            searchFilter.setTicketId(activity.getTicketId());
-
 
123
            List<Ticket> tickets = crmServiceClient.getTickets(searchFilter);
-
 
124
            if (tickets != null && !tickets.isEmpty()) {
108
            ticket = new Ticket();
125
                ticket = tickets.get(0);
-
 
126
            }
109
        }
127
        }
110
 
128
 
111
        return ticket;
129
        return ticket;
112
    }
130
    }
113
 
131
 
114
    public String create() throws Exception {
132
    public String create() throws Exception {
115
        createServiceClients();
-
 
116
 
-
 
117
        Activity activity = new Activity();
133
        Activity activity = new Activity();
118
        activity.setDescription(description);
134
        activity.setDescription(description);
119
        activity.setType(ActivityType.valueOf(type));
135
        activity.setType(ActivityType.valueOf(type));
120
        activity.setCreatorId(crmServiceClient.getAgentByEmailId(
136
        activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
121
                currentAgentEmailId).getId());
-
 
122
 
137
 
123
        if (userId != null && !userId.isEmpty()) {
138
        if (userId != null && !userId.isEmpty()) {
124
            activity.setCustomerId(Long.parseLong(userId));
139
            activity.setCustomerId(Long.parseLong(userId));
125
        }
140
        }
126
 
141
 
127
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
142
        if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
128
            log.info("Sending mail");
143
            log.info("Sending mail");
129
            Client helperClient = new HelperClient().getClient();
144
            Client helperClient = new HelperClient().getClient();
130
            activity.setEmailId(helperClient.saveUserEmailForSending(
145
            activity.setUserEmailId(helperClient.saveUserEmailForSending(
131
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
146
                    userEmailId, CRMConstants.CRM_EMAIL_SENDOR, subject,
132
                    body, null, CRMConstants.CRM_EMAIL_TYPE));
147
                    body, null, CRMConstants.CRM_EMAIL_TYPE));
133
 
148
 
134
            // We change activityType to OTHER when pop up box for email
149
            // We change activityType to OTHER when pop up box for email
135
            // closes
150
            // closes
136
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: " + body);
151
            activity.setDescription("Subject: " + subject + "\n\n" + "Body: " + body);
137
        }
152
        }
138
 
153
 
-
 
154
        crmServiceClient         = new CRMClient().getClient();
139
        crmServiceClient.insertActivity(activity);
155
        crmServiceClient.insertActivity(activity);
140
 
156
 
141
        return index();
157
        return index();
142
    }
158
    }
143
 
159
 
144
    public String getLoggerRole() throws TException {
160
    public boolean isAssigneeEditable() {
145
        createServiceClients();
-
 
146
        return crmServiceClient.getRoleNamesForAgent(currentAgentEmailId)
161
        return SecurityUtils.getSubject().hasRole("TeamLead");
147
                .get(0);
-
 
148
    }
162
    }
149
 
163
 
150
    public List<Agent> getAllAgents() throws TException {
164
    public List<Agent> getAllAgents() throws TException {
151
        createServiceClients();
-
 
152
        return crmServiceClient.getAllAgents();
165
        return CRMAuthorizingRealm.getAgents();
153
    }
166
    }
154
 
167
 
155
    public Agent getAgent(long agentId) throws TException {
168
    public Agent getAgent(long agentId) throws TException {
156
        return crmServiceClient.getAgent(agentId);
169
        return CRMAuthorizingRealm.getAgent(agentId);
157
    }
170
    }
158
 
171
 
159
    public void setDescription(String description) {
172
    public void setDescription(String description) {
160
        this.description = description;
173
        this.description = description;
161
    }
174
    }