Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
4793 amar.kumar 1
package in.shop2020.serving.controllers;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import in.shop2020.crm.Agent;
7
import in.shop2020.crm.SearchFilter;
8
import in.shop2020.serving.auth.CRMAuthorizingRealm;
9
import in.shop2020.thrift.clients.CRMClient;
10
 
11
import org.apache.shiro.crypto.hash.Sha256Hash;
12
import org.apache.thrift.TException;
5168 amar.kumar 13
import org.apache.thrift.transport.TTransportException;
4793 amar.kumar 14
 
15
public class AgentController extends BaseController {
16
 
17
	private List<Agent>  agents = new ArrayList<Agent>();
18
	private int id;
19
	private String name;
20
	private String emailId;
21
	private String password;
22
	private List<String> role;
23
	private String managerEmailId;
24
	private String newPassword;
25
	private int managerId;
26
 
27
	private static final long serialVersionUID = 7884813082235471597L;
28
 
29
	public AgentController()	{
30
		super();
31
	}
32
 
33
	public String index() {
34
		try {
35
        	SearchFilter searchFilter = new SearchFilter();
36
        	crmServiceClient = new CRMClient().getClient();
37
        	agents = crmServiceClient.getAgents(searchFilter);
38
        } catch (TException e) {
39
            log.error("Error while getting agents", e);
40
        }
41
        return INDEX;
42
    }
43
 
44
	public String createAgent(){
45
		try{
46
			Agent agent = new Agent();
47
			agent.setName(name);
48
			agent.setEmailId(emailId);
49
			agent.setManagerId(managerId);  
50
			agent.setPassword(new Sha256Hash(password).toHex());
51
			agent.setIs_active(true);
52
			crmServiceClient = new CRMClient().getClient();
53
			crmServiceClient.insertAgent(agent,role);
54
			SearchFilter searchfilter = new SearchFilter();
55
			searchfilter.setAgentEmailId(emailId);
56
			List<Agent> createdAgent = crmServiceClient.getAgents(searchfilter);
57
			CRMAuthorizingRealm.addAgent(createdAgent.get(0));
58
			log.info("Agent Creation complete");
59
		} catch (TException e) {
60
			log.error("Error while creating agent", e);
61
			return EXCEPTION;
62
		}
63
		return index();
64
	}
65
 
66
 
67
	public String changePassword(){
68
		try {
69
			crmServiceClient = new CRMClient().getClient();
70
			crmServiceClient.updatePasswordForAgent(emailId, new Sha256Hash(newPassword).toHex());
71
		} catch (TException e) {
72
			log.error("Error while changing password of agent", e);
73
			e.printStackTrace();
74
			return EXCEPTION;
75
		}
76
		return index();
77
	}
78
 
79
	public String deActivateAgent(){
80
		try {
81
			crmServiceClient = new CRMClient().getClient();
82
			crmServiceClient.changeAgentStatus(false, emailId);
83
			crmServiceClient.unassignAgentTickets(id);
84
			CRMAuthorizingRealm.removeAgent(new Long((long)id), emailId);
85
		} catch (TException e) {
86
			log.error("Error while deactivating agent", e);
87
			e.printStackTrace();
88
			return EXCEPTION; 
89
		}
90
		return index();
91
	}
92
 
5168 amar.kumar 93
	public String changeAgentRole(){
94
		try{
95
			log.info("Agent id : "+id +" role : " + role);
96
			crmServiceClient = new CRMClient().getClient();
97
			crmServiceClient.changeAgentRole(new Long((long)id),role);
98
		} catch (Exception e) {
99
 
100
		}
101
		return index();
102
	}
103
 
104
	public String getOpenTicketCount(long id) {
105
		try {
106
			log.info("Agent id : " + id);
107
			crmServiceClient = new CRMClient().getClient();
108
			return (new Integer(crmServiceClient.getOpenTicketCountForAgent(id))).toString();
109
		} catch (TTransportException e) {
110
			e.printStackTrace();
111
		} catch (TException e) {
112
			e.printStackTrace();
113
		}
114
		return "-1";
115
	}
116
 
4793 amar.kumar 117
	public String getName() {
118
		return name;
119
	}
120
 
121
	public void setName(String name) {
122
		this.name = name;
123
	}
124
 
125
	public String getPassword() {
126
		return password;
127
	}
128
 
129
	public void setPassword(String password) {
130
		this.password = password;
131
	}
132
 
133
	public List<String> getRole() {
134
		return role;
135
	}
136
 
137
	public void setRole(List<String> role) {
138
		this.role = role;
139
	}
140
 
141
	public String getEmailId() {
142
		return emailId;
143
	}
144
 
145
	public void setEmailId(String emailId) {
146
		this.emailId = emailId;
147
	}
148
 
149
	public String getNewPassword() {
150
		return newPassword;
151
	}
152
 
153
	public void setNewPassword(String newPassword) {
154
		this.newPassword = newPassword;
155
	}
156
 
157
	public List<Agent> getAgents() {
158
		return agents;
159
	}
160
 
161
	public void setAgents(List<Agent> agents) {
162
		this.agents = agents;
163
	}
164
 
165
	public String getManagerEmailId() {
166
		return managerEmailId;
167
	}
168
 
169
	public void setManagerEmailId(String managerEmailId) {
170
		this.managerEmailId = managerEmailId;
171
	}
172
 
173
	public int getManagerId() {
174
		return managerId;
175
	}
176
 
177
 
178
	public void setManagerId(int managerId) {
179
		this.managerId = managerId;
180
	}
181
 
182
	public int getId() {
183
		return id;
184
	}
185
 
186
	public void setId(int id) {
187
		this.id = id;
188
	}
189
}