Subversion Repositories SmartDukaan

Rev

Rev 5168 | Rev 5937 | 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());
5286 amar.kumar 71
 
72
			// Dummy call to reload agents
73
	        CRMAuthorizingRealm.getAgent(-1);
4793 amar.kumar 74
		} catch (TException e) {
75
			log.error("Error while changing password of agent", e);
76
			e.printStackTrace();
77
			return EXCEPTION;
78
		}
79
		return index();
80
	}
81
 
82
	public String deActivateAgent(){
83
		try {
84
			crmServiceClient = new CRMClient().getClient();
85
			crmServiceClient.changeAgentStatus(false, emailId);
86
			crmServiceClient.unassignAgentTickets(id);
87
			CRMAuthorizingRealm.removeAgent(new Long((long)id), emailId);
88
		} catch (TException e) {
89
			log.error("Error while deactivating agent", e);
90
			e.printStackTrace();
91
			return EXCEPTION; 
92
		}
93
		return index();
94
	}
95
 
5168 amar.kumar 96
	public String changeAgentRole(){
97
		try{
98
			log.info("Agent id : "+id +" role : " + role);
99
			crmServiceClient = new CRMClient().getClient();
100
			crmServiceClient.changeAgentRole(new Long((long)id),role);
101
		} catch (Exception e) {
102
 
103
		}
104
		return index();
105
	}
106
 
107
	public String getOpenTicketCount(long id) {
108
		try {
109
			crmServiceClient = new CRMClient().getClient();
110
			return (new Integer(crmServiceClient.getOpenTicketCountForAgent(id))).toString();
111
		} catch (TTransportException e) {
112
			e.printStackTrace();
113
		} catch (TException e) {
114
			e.printStackTrace();
115
		}
116
		return "-1";
117
	}
118
 
4793 amar.kumar 119
	public String getName() {
120
		return name;
121
	}
122
 
123
	public void setName(String name) {
124
		this.name = name;
125
	}
126
 
127
	public String getPassword() {
128
		return password;
129
	}
130
 
131
	public void setPassword(String password) {
132
		this.password = password;
133
	}
134
 
135
	public List<String> getRole() {
136
		return role;
137
	}
138
 
139
	public void setRole(List<String> role) {
140
		this.role = role;
141
	}
142
 
143
	public String getEmailId() {
144
		return emailId;
145
	}
146
 
147
	public void setEmailId(String emailId) {
148
		this.emailId = emailId;
149
	}
150
 
151
	public String getNewPassword() {
152
		return newPassword;
153
	}
154
 
155
	public void setNewPassword(String newPassword) {
156
		this.newPassword = newPassword;
157
	}
158
 
159
	public List<Agent> getAgents() {
160
		return agents;
161
	}
162
 
163
	public void setAgents(List<Agent> agents) {
164
		this.agents = agents;
165
	}
166
 
167
	public String getManagerEmailId() {
168
		return managerEmailId;
169
	}
170
 
171
	public void setManagerEmailId(String managerEmailId) {
172
		this.managerEmailId = managerEmailId;
173
	}
174
 
175
	public int getManagerId() {
176
		return managerId;
177
	}
178
 
179
 
180
	public void setManagerId(int managerId) {
181
		this.managerId = managerId;
182
	}
183
 
184
	public int getId() {
185
		return id;
186
	}
187
 
188
	public void setId(int id) {
189
		this.id = id;
190
	}
5286 amar.kumar 191
 
192
	public static void main(String args[]) throws TException {
193
		SearchFilter searchFilter = new SearchFilter();
194
		searchFilter.setAgentId(10);
195
		in.shop2020.crm.CRMService.Client crmServiceClient = new CRMClient().getClient();
196
    	List<Agent> agents = crmServiceClient.getAgents(searchFilter);
197
    	System.out.println(agents);
198
	}
4793 amar.kumar 199
}