Subversion Repositories SmartDukaan

Rev

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