Subversion Repositories SmartDukaan

Rev

Rev 4793 | Rev 7059 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4793 Rev 5286
Line 39... Line 39...
39
public class CRMAuthorizingRealm extends AuthorizingRealm {
39
public class CRMAuthorizingRealm extends AuthorizingRealm {
40
    private static final Log   log = LogFactory
40
    private static final Log   log = LogFactory
41
                                           .getLog(CRMAuthorizingRealm.class);
41
                                           .getLog(CRMAuthorizingRealm.class);
42
    private static Map<Long, Agent>   agentsMapById;
42
    private static Map<Long, Agent>   agentsMapById;
43
    private static Map<String, Agent> agentsMapByEmailId;
43
    private static Map<String, Agent> agentsMapByEmailId;
-
 
44
    private static Map<Long, Agent>   inactiveAgentsMapById;
-
 
45
    private static Map<String, Agent> inactiveAgentsMapByEmailId;
44
 
46
    
45
    @Override
47
    @Override
46
    protected AuthorizationInfo doGetAuthorizationInfo(
48
    protected AuthorizationInfo doGetAuthorizationInfo(
47
            PrincipalCollection principals) {
49
            PrincipalCollection principals) {
48
        // null usernames are invalid
50
        // null usernames are invalid
49
        if (principals == null) {
51
        if (principals == null) {
Line 101... Line 103...
101
 
103
 
102
        return info;
104
        return info;
103
    }
105
    }
104
 
106
 
105
    public static Agent getAgent(String username) throws TException {
107
    public static Agent getAgent(String username) throws TException {
106
        if (agentsMapByEmailId == null || !agentsMapByEmailId.containsKey(username)) {
108
        if (agentsMapByEmailId == null || (!agentsMapByEmailId.containsKey(username)
-
 
109
        		&&!inactiveAgentsMapByEmailId.containsKey(username))) {
107
            loadAgents();
110
            loadAgents();
108
        }
111
        }
109
 
-
 
-
 
112
        if(agentsMapByEmailId.get(username)!=null) {
110
        return agentsMapByEmailId.get(username);
113
        	return agentsMapByEmailId.get(username);
-
 
114
        } else {
-
 
115
        	return inactiveAgentsMapByEmailId.get(username);
-
 
116
        }
111
    }
117
    }
112
 
118
 
113
    public static Agent getAgent(long agentId) throws TException {
119
    public static Agent getAgent(long agentId) throws TException {
114
        if (agentsMapById == null || !agentsMapById.containsKey(agentId)) {
120
        if (agentsMapById == null || (!agentsMapById.containsKey(agentId)
-
 
121
        		&&!inactiveAgentsMapById.containsKey(agentId))) {
115
            loadAgents();
122
            loadAgents();
116
        }
123
        }
117
 
124
        
-
 
125
        if(agentsMapById.get(agentId)!=null) {
118
        return agentsMapById.get(agentId);
126
        	return agentsMapById.get(agentId);
-
 
127
        } else {
-
 
128
        	return inactiveAgentsMapById.get(agentId);
-
 
129
        }
119
    }
130
    }
120
 
131
 
121
    private static void loadAgents() throws TException {
132
    private static void loadAgents() throws TException {
122
        Client crmServiceClient = new CRMClient().getClient();
133
        Client crmServiceClient = new CRMClient().getClient();
123
        List<Agent> agents = crmServiceClient.getAgents(new SearchFilter());
134
        List<Agent> agents = crmServiceClient.getAgents(new SearchFilter());
-
 
135
        List<Agent> inactiveAgents = crmServiceClient.getInactiveAgents(new SearchFilter());
124
        Map<Long, Agent> agentsMapByIdLocal = new HashMap<Long, Agent>();
136
        Map<Long, Agent> agentsMapByIdLocal = new HashMap<Long, Agent>();
125
        Map<String, Agent> agentsMapByEmailIdLocal = new HashMap<String, Agent>();
137
        Map<String, Agent> agentsMapByEmailIdLocal = new HashMap<String, Agent>();
-
 
138
        Map<Long, Agent> inactiveAgentsMapByIdLocal = new HashMap<Long, Agent>();
-
 
139
        Map<String, Agent> inactiveAgentsMapByEmailIdLocal = new HashMap<String, Agent>();
126
 
140
 
127
        for (Agent agent : agents) {
141
        for (Agent agent : agents) {
128
            agentsMapByIdLocal.put(agent.getId(), agent);
142
            agentsMapByIdLocal.put(agent.getId(), agent);
129
            agentsMapByEmailIdLocal.put(agent.getEmailId(), agent);
143
            agentsMapByEmailIdLocal.put(agent.getEmailId(), agent);
130
        }
144
        }
-
 
145
        
-
 
146
        for (Agent agent : inactiveAgents) {
-
 
147
            inactiveAgentsMapByIdLocal.put(agent.getId(), agent);
-
 
148
            inactiveAgentsMapByEmailIdLocal.put(agent.getEmailId(), agent);
-
 
149
        }
131
 
150
 
132
        synchronized(CRMAuthorizingRealm.class) {
151
        synchronized(CRMAuthorizingRealm.class) {
133
            agentsMapById = agentsMapByIdLocal;
152
            agentsMapById = agentsMapByIdLocal;
134
            agentsMapByEmailId = agentsMapByEmailIdLocal;
153
            agentsMapByEmailId = agentsMapByEmailIdLocal;
-
 
154
            inactiveAgentsMapById = inactiveAgentsMapByIdLocal;
-
 
155
            inactiveAgentsMapByEmailId = inactiveAgentsMapByEmailIdLocal;
135
        }
156
        }
136
    }
157
    }
137
 
158
 
138
    public static List<Agent> getAgents() {
159
    public static List<Agent> getAgents() {
139
        return new ArrayList<Agent>(agentsMapById.values());
160
        return new ArrayList<Agent>(agentsMapById.values());
140
    }
161
    }
141
    
162
    
142
    public static void removeAgent(Long id, String emailId) {
163
    public static void removeAgent(Long id, String emailId) {
-
 
164
    	inactiveAgentsMapById.put(id, agentsMapById.get(id));
-
 
165
    	inactiveAgentsMapByEmailId.put(emailId, agentsMapByEmailId.get(emailId));
143
    	agentsMapById.remove(id);
166
    	agentsMapById.remove(id);
144
    	agentsMapByEmailId.remove(emailId);
167
    	agentsMapByEmailId.remove(emailId);
145
    }
168
    }
146
    
169
    
147
    public static void addAgent(Agent agent) {
170
    public static void addAgent(Agent agent) {