Subversion Repositories SmartDukaan

Rev

Rev 3269 | Rev 3390 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3137 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
3339 mandeep.dh 6
import in.shop2020.crm.Activity;
7
import in.shop2020.crm.ActivityType;
3137 mandeep.dh 8
import in.shop2020.crm.Agent;
9
import in.shop2020.crm.Ticket;
3339 mandeep.dh 10
import in.shop2020.crm.TicketCategory;
11
import in.shop2020.crm.TicketPriority;
3137 mandeep.dh 12
import in.shop2020.crm.TicketStatus;
13
import in.shop2020.model.v1.user.User;
14
import in.shop2020.model.v1.user.UserContextException;
15
 
16
import java.util.ArrayList;
17
import java.util.List;
18
 
19
import org.apache.thrift.TException;
20
 
21
/**
22
 * @author mandeep
23
 * 
24
 */
25
public class TicketsController extends BaseController {
26
 
27
    /**
28
     * 
29
     */
30
    private static final long serialVersionUID = 1L;
31
 
32
    List<Ticket>              tickets          = new ArrayList<Ticket>();
3339 mandeep.dh 33
    private String            userEmailId;
34
    private String            description;
35
    private String            assigneeEmailId;
36
    private String            priority;
37
    private String            category;
38
    private String            orderId;
3137 mandeep.dh 39
 
3339 mandeep.dh 40
    public String create() {
41
        try {
42
            createServiceClients();
43
            long creatorId = crmServiceClient.getAgentByEmailId(
44
                    currentAgentEmailId).getId();
45
            Ticket ticket = new Ticket();
46
            ticket.setDescription(description);
47
            ticket.setCreatorId(creatorId);
48
            ticket.setStatus(TicketStatus.OPEN);
49
            ticket.setPriority(TicketPriority.valueOf(priority));
50
            ticket.setCategory(TicketCategory.valueOf(category));
51
 
52
            Activity activity = new Activity();
53
            // At creation of ticket activity's description is same as that of
54
            // ticket
55
            activity.setDescription("Creating Ticket");
56
            activity.setType(ActivityType.OTHER);
57
            activity.setTicketPriority(TicketPriority.valueOf(priority));
58
            activity.setTicketStatus(TicketStatus.OPEN);
59
            activity.setCreatorId(creatorId);
60
            activity.setTicketCategory(TicketCategory.valueOf(category));
61
            activity.setTicketDescription(description);
62
 
63
            if (orderId != null && !orderId.isEmpty()) {
64
                ticket.setOrderId(Long.parseLong(orderId));
65
            }
66
 
67
            if (userEmailId != null && !userEmailId.isEmpty()) {
68
                ticket.setCustomerEmailId(userEmailId);
69
            }
70
 
71
            // handling null values appropriately
72
            if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
73
                long assigneeId = crmServiceClient.getAgentByEmailId(
74
                        assigneeEmailId).getId();
75
                ticket.setAssigneeId(assigneeId);
76
                activity.setTicketAssigneeId(assigneeId);
77
            }
78
 
79
            crmServiceClient.insertTicket(ticket, activity);
80
        } catch (TException e) {
81
            log.error("Error while creating ticket", e);
82
            return EXCEPTION;
83
        }
84
 
85
        return getMyOpenTickets();
86
    }
87
 
3137 mandeep.dh 88
    public String getMyOpenTickets() {
89
        try {
90
            createServiceClients();
3339 mandeep.dh 91
            Agent agent = crmServiceClient
92
                    .getAgentByEmailId(currentAgentEmailId);
3137 mandeep.dh 93
 
3339 mandeep.dh 94
            for (Ticket ticket : crmServiceClient.getAssignedTickets(agent
95
                    .getId())) {
3137 mandeep.dh 96
                if (TicketStatus.OPEN.equals(ticket.getStatus())) {
97
                    tickets.add(ticket);
98
                }
99
            }
100
        } catch (TException e) {
101
            String errorString = "Error getting tickets for "
102
                    + currentAgentEmailId;
103
            log.error(errorString, e);
104
            addActionError(errorString);
105
        }
106
 
107
        return INDEX;
108
    }
109
 
110
    public String getMyTickets() {
111
        try {
112
            createServiceClients();
3339 mandeep.dh 113
            Agent agent = crmServiceClient
114
                    .getAgentByEmailId(currentAgentEmailId);
3137 mandeep.dh 115
            tickets = crmServiceClient.getAssignedTickets(agent.getId());
116
        } catch (TException e) {
3339 mandeep.dh 117
            String errorString = "Error getting tickets for "
118
                    + currentAgentEmailId;
3137 mandeep.dh 119
            log.error(errorString, e);
120
            addActionError(errorString);
121
        }
122
 
123
        return INDEX;
124
    }
125
 
126
    public String getUnassignedTickets() {
127
        try {
128
            createServiceClients();
129
            tickets = crmServiceClient.getUnassignedTickets();
130
        } catch (TException e) {
3339 mandeep.dh 131
            String errorString = "Error getting tickets for "
132
                    + currentAgentEmailId;
3137 mandeep.dh 133
            log.error(errorString, e);
134
            addActionError(errorString);
135
        }
136
 
137
        return INDEX;
138
    }
139
 
140
    public String getAllTickets() {
141
        try {
142
            createServiceClients();
3339 mandeep.dh 143
            Agent agent = crmServiceClient
144
                    .getAgentByEmailId(currentAgentEmailId);
3137 mandeep.dh 145
            tickets = crmServiceClient.getAllTickets(agent.getId());
146
        } catch (TException e) {
3339 mandeep.dh 147
            String errorString = "Error getting tickets for "
148
                    + currentAgentEmailId;
3137 mandeep.dh 149
            log.error(errorString, e);
150
            addActionError(errorString);
151
        }
152
 
153
        return INDEX;
154
    }
155
 
156
    public String getAllOpenTickets() {
157
        try {
158
            createServiceClients();
3339 mandeep.dh 159
            Agent agent = crmServiceClient
160
                    .getAgentByEmailId(currentAgentEmailId);
3137 mandeep.dh 161
            for (Ticket ticket : crmServiceClient.getAllTickets(agent.getId())) {
162
                if (TicketStatus.OPEN.equals(ticket.getStatus())) {
163
                    tickets.add(ticket);
164
                }
165
            }
166
        } catch (TException e) {
3339 mandeep.dh 167
            String errorString = "Error getting tickets for "
168
                    + currentAgentEmailId;
3137 mandeep.dh 169
            log.error(errorString, e);
170
            addActionError(errorString);
171
        }
172
 
173
        return INDEX;
174
    }
175
 
176
    public User getUser(Long userId) {
177
        User user = null;
178
 
179
        try {
180
            createServiceClients();
181
            user = userContextServiceClient.getUserById(userId);
182
        } catch (UserContextException e) {
183
            String errorString = "Could not fetch user for " + userId;
184
            log.error(errorString, e);
185
            addActionError(errorString);
186
        } catch (TException e) {
187
            String errorString = "Could not create client";
188
            log.error(errorString, e);
189
            addActionError(errorString);
190
        }
191
 
192
        return user;
193
    }
194
 
195
    public Agent getAgent(long agentId) {
196
        Agent agent = null;
197
 
198
        try {
199
            agent = crmServiceClient.getAgent(agentId);
200
        } catch (TException e) {
201
            String errorString = "Could not get agent for " + agentId;
202
            log.error(errorString, e);
203
            addActionError(errorString);
204
        }
205
 
206
        return agent;
207
    }
208
 
3339 mandeep.dh 209
    public List<Agent> getAllAgents() {
210
        List<Agent> agents = null;
211
 
212
        try {
213
            createServiceClients();
214
            agents = crmServiceClient.getAllAgents();
215
        } catch (TException e) {
216
            String errorString = "Error while getting roles";
217
            log.error(errorString, e);
218
            addActionError(errorString);
219
        }
220
 
221
        return agents;
222
    }
223
 
224
    public TicketCategory[] getTicketCategories() {
225
        return TicketCategory.values();
226
    }
227
 
228
    public TicketPriority[] getTicketPriorities() {
229
        return TicketPriority.values();
230
    }
231
 
3137 mandeep.dh 232
    public List<Ticket> getTickets() {
233
        return tickets;
234
    }
235
 
236
    public void setTickets(List<Ticket> tickets) {
237
        this.tickets = tickets;
238
    }
3339 mandeep.dh 239
 
240
    public String getUserEmailId() {
241
        return userEmailId;
242
    }
243
 
244
    public void setUserEmailId(String userEmailId) {
245
        this.userEmailId = userEmailId;
246
    }
247
 
248
    public String getDescription() {
249
        return description;
250
    }
251
 
252
    public void setDescription(String description) {
253
        this.description = description;
254
    }
255
 
256
    public String getAssigneeEmailId() {
257
        return assigneeEmailId;
258
    }
259
 
260
    public void setAssigneeEmailId(String assigneeEmailId) {
261
        this.assigneeEmailId = assigneeEmailId;
262
    }
263
 
264
    public String getPriority() {
265
        return priority;
266
    }
267
 
268
    public void setPriority(String priority) {
269
        this.priority = priority;
270
    }
271
 
272
    public String getCategory() {
273
        return category;
274
    }
275
 
276
    public void setCategory(String category) {
277
        this.category = category;
278
    }
279
 
280
    public String getOrderId() {
281
        return orderId;
282
    }
283
 
284
    public void setOrderId(String orderId) {
285
        this.orderId = orderId;
286
    }
3137 mandeep.dh 287
}