Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
3024 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.crm.service.handler;
5
 
6
import in.shop2020.crm.Activity;
7
import in.shop2020.crm.Agent;
8
import in.shop2020.crm.CRMService.Iface;
9
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.handler.ActivityHandler;
11
import in.shop2020.crm.handler.AgentHandler;
12
import in.shop2020.crm.handler.TicketHandler;
13
 
14
import java.text.ParseException;
15
import java.util.ArrayList;
16
import java.util.List;
17
 
18
import org.apache.thrift.TException;
19
import org.springframework.context.ApplicationContext;
20
import org.springframework.context.support.ClassPathXmlApplicationContext;
21
import org.springframework.stereotype.Service;
3206 mandeep.dh 22
import org.springframework.transaction.annotation.Transactional;
3024 mandeep.dh 23
 
24
/**
25
 * Implementation of the interface/services exposed by thrift to clients!
26
 * 
27
 * @author mandeep
28
 */
29
@Service
30
public class CRMServiceHandler implements Iface {
3168 mandeep.dh 31
    ApplicationContext context         = new ClassPathXmlApplicationContext(
32
                                               "context.xml");
3024 mandeep.dh 33
    TicketHandler      ticketHandler   = context.getBean(TicketHandler.class);
34
    ActivityHandler    activityHandler = context.getBean(ActivityHandler.class);
35
    AgentHandler       agentHandler    = context.getBean(AgentHandler.class);
36
 
37
    public List<Ticket> getTickets(long customerId) throws TException {
38
        List<Ticket> ttickets = new ArrayList<Ticket>();
3206 mandeep.dh 39
        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler.getTickets(customerId)) {
3024 mandeep.dh 40
            ttickets.add(ticket.getThriftTicket());
41
        }
42
 
43
        return ttickets;
44
    }
45
 
3206 mandeep.dh 46
    @Transactional
47
    public void updateTicket(Ticket ticket, Activity activity) throws TException {
3024 mandeep.dh 48
        try {
49
            ticketHandler.updateTicket(in.shop2020.crm.domain.Ticket
50
                    .create(ticket));
3206 mandeep.dh 51
            activity.setTicketId(ticket.getId());
52
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity.create(activity));
3024 mandeep.dh 53
        } catch (ParseException e) {
54
            throw new TException("Could not update " + ticket, e);
55
        }
56
    }
57
 
3206 mandeep.dh 58
    @Transactional
59
    public long insertTicket(Ticket ticket, Activity activity) throws TException {
3024 mandeep.dh 60
        try {
3206 mandeep.dh 61
            long ticketId = ticketHandler.insertTicket(in.shop2020.crm.domain.Ticket
3024 mandeep.dh 62
                    .create(ticket));
3206 mandeep.dh 63
            activity.setTicketId(ticketId);
64
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity.create(activity));
65
            return ticketId;
3024 mandeep.dh 66
        } catch (ParseException e) {
67
            throw new TException("Could not insert " + ticket, e);
68
        }
69
    }
70
 
71
    public List<Activity> getActivities(long customerId) throws TException {
72
        List<Activity> tactivities = new ArrayList<Activity>();
3168 mandeep.dh 73
        List<in.shop2020.crm.domain.Activity> activities = activityHandler
74
                .getActivities(customerId);
75
        if (activities != null) {
76
            for (in.shop2020.crm.domain.Activity ticket : activities) {
77
                tactivities.add(ticket.getThriftActivity());
78
            }
3024 mandeep.dh 79
        }
80
        return tactivities;
81
    }
82
 
83
    public void insertActivity(Activity activity) throws TException {
84
        try {
85
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
86
                    .create(activity));
87
        } catch (ParseException e) {
88
            throw new TException("Could not insert " + activity, e);
89
        }
90
    }
91
 
92
    public Ticket getTicket(long ticketId) throws TException {
3168 mandeep.dh 93
        Ticket thriftTicket = null;
94
 
95
        in.shop2020.crm.domain.Ticket ticket = ticketHandler
96
                .getTicket(ticketId);
97
 
98
        if (ticket != null) {
99
            thriftTicket = ticket.getThriftTicket();
100
        }
101
 
102
        return thriftTicket;
3024 mandeep.dh 103
    }
104
 
105
    public Activity getActivity(long activityId) throws TException {
3168 mandeep.dh 106
        in.shop2020.crm.domain.Activity activity = activityHandler
107
                .getActivity(activityId);
108
        Activity thriftActivity = null;
109
 
110
        if (activity != null) {
111
            thriftActivity = activity.getThriftActivity();
112
        }
113
 
114
        return thriftActivity;
3024 mandeep.dh 115
    }
116
 
117
    public Activity getLastActivity(long ticketId) throws TException {
118
        in.shop2020.crm.domain.Activity lastActivity = activityHandler
119
                .getLastActivity(ticketId);
120
        Activity lastThriftActivity = null;
121
 
122
        if (lastActivity != null) {
123
            lastThriftActivity = lastActivity.getThriftActivity();
124
        }
125
 
126
        return lastThriftActivity;
127
    }
128
 
129
    public List<Activity> getActivitiesForTicket(long ticketId)
130
            throws TException {
131
        List<Activity> tactivities = new ArrayList<Activity>();
132
 
133
        for (in.shop2020.crm.domain.Activity ticket : activityHandler
134
                .getActivitiesForTicket(ticketId)) {
135
            tactivities.add(ticket.getThriftActivity());
136
        }
137
 
138
        return tactivities;
139
    }
140
 
141
    public Agent getAgent(long agentId) throws TException {
3168 mandeep.dh 142
        in.shop2020.crm.domain.Agent agent = agentHandler.getAgent(agentId);
143
        Agent thriftAgent = null;
144
 
145
        if (agent != null) {
146
            thriftAgent = agent.getThriftAgent();
147
        }
148
 
149
        return thriftAgent;
3024 mandeep.dh 150
    }
151
 
152
    public Agent getAgentByEmailId(String agentEmailId) throws TException {
3168 mandeep.dh 153
        in.shop2020.crm.domain.Agent agentByEmail = agentHandler.getAgentByEmail(agentEmailId);
154
        Agent thriftAgent = null;
155
 
156
        if (agentByEmail != null) {
157
            thriftAgent = agentByEmail.getThriftAgent();
158
        }
159
 
160
        return thriftAgent;
3024 mandeep.dh 161
    }
3088 mandeep.dh 162
 
163
    public List<String> getRoleNamesForAgent(String agentEmailId)
3168 mandeep.dh 164
            throws TException {
3088 mandeep.dh 165
        return agentHandler.getRoleNamesForAgent(agentEmailId);
166
    }
167
 
168
    public List<String> getPermissionsForRoleName(String roleName)
3168 mandeep.dh 169
            throws TException {
3088 mandeep.dh 170
        return agentHandler.getPermissionsForRoleName(roleName);
171
    }
172
 
173
    public List<Ticket> getAssignedTickets(long agentId) throws TException {
3137 mandeep.dh 174
        List<Ticket> tickets = new ArrayList<Ticket>();
3088 mandeep.dh 175
 
3168 mandeep.dh 176
        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler
177
                .getAssignedTickets(agentId)) {
3137 mandeep.dh 178
            tickets.add(ticket.getThriftTicket());
179
        }
180
 
181
        return tickets;
3088 mandeep.dh 182
    }
183
 
184
    public List<Agent> getAllAgents() throws TException {
185
        List<Agent> agents = new ArrayList<Agent>();
186
 
187
        for (in.shop2020.crm.domain.Agent agent : agentHandler.getAllAgents()) {
188
            agents.add(agent.getThriftAgent());
189
        }
190
 
191
        return agents;
192
    }
193
 
194
    public void updatePasswordForAgent(String agentEmailId, String password)
3168 mandeep.dh 195
            throws TException {
3088 mandeep.dh 196
        agentHandler.updatePasswordForAgent(agentEmailId, password);
197
    }
3137 mandeep.dh 198
 
199
    public List<Ticket> getUnassignedTickets() throws TException {
200
        List<Ticket> tickets = new ArrayList<Ticket>();
201
 
3168 mandeep.dh 202
        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler
203
                .getUnassignedTickets()) {
3137 mandeep.dh 204
            tickets.add(ticket.getThriftTicket());
205
        }
206
 
207
        return tickets;
208
    }
209
 
210
    public List<Ticket> getAllTickets(long agentId) throws TException {
3168 mandeep.dh 211
        List<in.shop2020.crm.domain.Ticket> tickets = ticketHandler
212
                .getAssignedTickets(agentId);
3137 mandeep.dh 213
 
3168 mandeep.dh 214
        for (in.shop2020.crm.domain.Agent agent : agentHandler
215
                .getReportees(agentId)) {
3137 mandeep.dh 216
            tickets.addAll(ticketHandler.getAssignedTickets(agent.getId()));
217
        }
218
 
219
        List<Ticket> ttickets = new ArrayList<Ticket>();
220
 
221
        for (in.shop2020.crm.domain.Ticket ticket : tickets) {
222
            ttickets.add(ticket.getThriftTicket());
223
        }
224
 
225
        return ttickets;
226
    }
3024 mandeep.dh 227
}