Subversion Repositories SmartDukaan

Rev

Rev 5168 | Go to most recent revision | Details | 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;
13
 
14
public class AgentController extends BaseController {
15
 
16
	private List<Agent>  agents = new ArrayList<Agent>();
17
	private int id;
18
	private String name;
19
	private String emailId;
20
	private String password;
21
	private List<String> role;
22
	private String managerEmailId;
23
	private String newPassword;
24
	private int managerId;
25
 
26
	private static final long serialVersionUID = 7884813082235471597L;
27
 
28
	public AgentController()	{
29
		super();
30
	}
31
 
32
	public String index() {
33
		try {
34
        	SearchFilter searchFilter = new SearchFilter();
35
        	crmServiceClient = new CRMClient().getClient();
36
        	agents = crmServiceClient.getAgents(searchFilter);
37
        } catch (TException e) {
38
            log.error("Error while getting agents", e);
39
        }
40
        return INDEX;
41
    }
42
 
43
	public String createAgent(){
44
		try{
45
			Agent agent = new Agent();
46
			agent.setName(name);
47
			agent.setEmailId(emailId);
48
			agent.setManagerId(managerId);  
49
			agent.setPassword(new Sha256Hash(password).toHex());
50
			agent.setIs_active(true);
51
			crmServiceClient = new CRMClient().getClient();
52
			crmServiceClient.insertAgent(agent,role);
53
			SearchFilter searchfilter = new SearchFilter();
54
			searchfilter.setAgentEmailId(emailId);
55
			List<Agent> createdAgent = crmServiceClient.getAgents(searchfilter);
56
			CRMAuthorizingRealm.addAgent(createdAgent.get(0));
57
			log.info("Agent Creation complete");
58
		} catch (TException e) {
59
			log.error("Error while creating agent", e);
60
			return EXCEPTION;
61
		}
62
		return index();
63
	}
64
 
65
 
66
	public String changePassword(){
67
		try {
68
			crmServiceClient = new CRMClient().getClient();
69
			crmServiceClient.updatePasswordForAgent(emailId, new Sha256Hash(newPassword).toHex());
70
		} catch (TException e) {
71
			log.error("Error while changing password of agent", e);
72
			e.printStackTrace();
73
			return EXCEPTION;
74
		}
75
		return index();
76
	}
77
 
78
	public String deActivateAgent(){
79
		try {
80
			crmServiceClient = new CRMClient().getClient();
81
			crmServiceClient.changeAgentStatus(false, emailId);
82
			crmServiceClient.unassignAgentTickets(id);
83
			CRMAuthorizingRealm.removeAgent(new Long((long)id), emailId);
84
		} catch (TException e) {
85
			log.error("Error while deactivating agent", e);
86
			e.printStackTrace();
87
			return EXCEPTION; 
88
		}
89
		return index();
90
	}
91
 
92
	public String getName() {
93
		return name;
94
	}
95
 
96
	public void setName(String name) {
97
		this.name = name;
98
	}
99
 
100
	public String getPassword() {
101
		return password;
102
	}
103
 
104
	public void setPassword(String password) {
105
		this.password = password;
106
	}
107
 
108
	public List<String> getRole() {
109
		return role;
110
	}
111
 
112
	public void setRole(List<String> role) {
113
		this.role = role;
114
	}
115
 
116
	public String getEmailId() {
117
		return emailId;
118
	}
119
 
120
	public void setEmailId(String emailId) {
121
		this.emailId = emailId;
122
	}
123
 
124
	public String getNewPassword() {
125
		return newPassword;
126
	}
127
 
128
	public void setNewPassword(String newPassword) {
129
		this.newPassword = newPassword;
130
	}
131
 
132
	public List<Agent> getAgents() {
133
		return agents;
134
	}
135
 
136
	public void setAgents(List<Agent> agents) {
137
		this.agents = agents;
138
	}
139
 
140
	public String getManagerEmailId() {
141
		return managerEmailId;
142
	}
143
 
144
	public void setManagerEmailId(String managerEmailId) {
145
		this.managerEmailId = managerEmailId;
146
	}
147
 
148
	public int getManagerId() {
149
		return managerId;
150
	}
151
 
152
 
153
	public void setManagerId(int managerId) {
154
		this.managerId = managerId;
155
	}
156
 
157
	public int getId() {
158
		return id;
159
	}
160
 
161
	public void setId(int id) {
162
		this.id = id;
163
	}
164
}