Subversion Repositories SmartDukaan

Rev

Rev 3088 | Rev 3168 | 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 {
30
    ApplicationContext context         = new ClassPathXmlApplicationContext("context.xml");
31
    TicketHandler      ticketHandler   = context.getBean(TicketHandler.class);
32
    ActivityHandler    activityHandler = context.getBean(ActivityHandler.class);
33
    AgentHandler       agentHandler    = context.getBean(AgentHandler.class);
34
 
35
    public List<Ticket> getTickets(long customerId) throws TException {
36
        List<Ticket> ttickets = new ArrayList<Ticket>();
37
 
38
        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler
39
                .getTickets(customerId)) {
40
            ttickets.add(ticket.getThriftTicket());
41
        }
42
 
43
        return ttickets;
44
    }
45
 
46
    public void updateTicket(Ticket ticket) throws TException {
47
        try {
48
            ticketHandler.updateTicket(in.shop2020.crm.domain.Ticket
49
                    .create(ticket));
50
        } catch (ParseException e) {
51
            throw new TException("Could not update " + ticket, e);
52
        }
53
    }
54
 
55
    public long insertTicket(Ticket ticket) throws TException {
56
        try {
57
            return ticketHandler.insertTicket(in.shop2020.crm.domain.Ticket
58
                    .create(ticket));
59
        } catch (ParseException e) {
60
            throw new TException("Could not insert " + ticket, e);
61
        }
62
    }
63
 
64
    public List<Activity> getActivities(long customerId) throws TException {
65
        List<Activity> tactivities = new ArrayList<Activity>();
66
        for (in.shop2020.crm.domain.Activity ticket : activityHandler
67
                .getActivities(customerId)) {
68
            tactivities.add(ticket.getThriftActivity());
69
        }
70
        return tactivities;
71
    }
72
 
73
    public void insertActivity(Activity activity) throws TException {
74
        try {
75
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
76
                    .create(activity));
77
        } catch (ParseException e) {
78
            throw new TException("Could not insert " + activity, e);
79
        }
80
    }
81
 
82
    public Ticket getTicket(long ticketId) throws TException {
83
        return ticketHandler.getTicket(ticketId).getThriftTicket();
84
    }
85
 
86
    public Activity getActivity(long activityId) throws TException {
87
        return activityHandler.getActivity(activityId).getThriftActivity();
88
    }
89
 
90
    public Activity getLastActivity(long ticketId) throws TException {
91
        in.shop2020.crm.domain.Activity lastActivity = activityHandler
92
                .getLastActivity(ticketId);
93
        Activity lastThriftActivity = null;
94
 
95
        if (lastActivity != null) {
96
            lastThriftActivity = lastActivity.getThriftActivity();
97
        }
98
 
99
        return lastThriftActivity;
100
    }
101
 
102
    public List<Activity> getActivitiesForTicket(long ticketId)
103
            throws TException {
104
        List<Activity> tactivities = new ArrayList<Activity>();
105
 
106
        for (in.shop2020.crm.domain.Activity ticket : activityHandler
107
                .getActivitiesForTicket(ticketId)) {
108
            tactivities.add(ticket.getThriftActivity());
109
        }
110
 
111
        return tactivities;
112
    }
113
 
114
    public Agent getAgent(long agentId) throws TException {
115
        return agentHandler.getAgent(agentId).getThriftAgent();
116
    }
117
 
118
    public Agent getAgentByEmailId(String agentEmailId) throws TException {
119
        return agentHandler.getAgentByEmail(agentEmailId).getThriftAgent();
120
    }
3088 mandeep.dh 121
 
122
    public List<String> getRoleNamesForAgent(String agentEmailId)
123
            throws TException
124
    {
125
        return agentHandler.getRoleNamesForAgent(agentEmailId);
126
    }
127
 
128
    public List<String> getPermissionsForRoleName(String roleName)
129
            throws TException
130
    {
131
        return agentHandler.getPermissionsForRoleName(roleName);
132
    }
133
 
134
    public List<Ticket> getAssignedTickets(long agentId) throws TException {
3137 mandeep.dh 135
        List<Ticket> tickets = new ArrayList<Ticket>();
3088 mandeep.dh 136
 
3137 mandeep.dh 137
        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler.getAssignedTickets(agentId)) {
138
            tickets.add(ticket.getThriftTicket());
139
        }
140
 
141
        return tickets;
3088 mandeep.dh 142
    }
143
 
144
    public List<Agent> getAllAgents() throws TException {
145
        List<Agent> agents = new ArrayList<Agent>();
146
 
147
        for (in.shop2020.crm.domain.Agent agent : agentHandler.getAllAgents()) {
148
            agents.add(agent.getThriftAgent());
149
        }
150
 
151
        return agents;
152
    }
153
 
154
    public void updatePasswordForAgent(String agentEmailId, String password)
155
            throws TException
156
    {
157
        agentHandler.updatePasswordForAgent(agentEmailId, password);
158
    }
3137 mandeep.dh 159
 
160
    public List<Ticket> getUnassignedTickets() throws TException {
161
        List<Ticket> tickets = new ArrayList<Ticket>();
162
 
163
        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler.getUnassignedTickets()) {
164
            tickets.add(ticket.getThriftTicket());
165
        }
166
 
167
        return tickets;
168
    }
169
 
170
    public List<Ticket> getAllTickets(long agentId) throws TException {
171
        List<in.shop2020.crm.domain.Ticket> tickets = ticketHandler.getAssignedTickets(agentId);
172
 
173
        for (in.shop2020.crm.domain.Agent agent : agentHandler.getReportees(agentId)) {
174
            tickets.addAll(ticketHandler.getAssignedTickets(agent.getId()));
175
        }
176
 
177
        List<Ticket> ttickets = new ArrayList<Ticket>();
178
 
179
        for (in.shop2020.crm.domain.Ticket ticket : tickets) {
180
            ttickets.add(ticket.getThriftTicket());
181
        }
182
 
183
        return ttickets;
184
    }
3024 mandeep.dh 185
}