m2u-upass-core / src / my / com / upass / maybank / MaybankFacadeImpl.java @ 44:7a7fb8fcfd6e
History | View | Annotate | Download (9.21 KB)
1 |
package my.com.upass.maybank; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Arrays; |
5 |
import java.util.LinkedList; |
6 |
import java.util.List; |
7 |
import java.util.Map; |
8 |
|
9 |
import javax.jws.WebService; |
10 |
|
11 |
import my.com.upass.MinimalConstants; |
12 |
import my.com.upass.UPassControllerV2; |
13 |
import my.com.upass.UPassException; |
14 |
import my.com.upass.maybank.entities.IbccUser; |
15 |
import my.com.upass.maybank.entities.Im2uUser; |
16 |
import my.com.upass.maybank.entities.M2uUser; |
17 |
import my.com.upass.maybank.entities.StockUser; |
18 |
import my.com.upass.maybank.entities.TicketingUser; |
19 |
import my.com.upass.maybank.entities.UserProfile; |
20 |
import my.com.upass.pojo.ClientApp; |
21 |
import my.com.upass.pojo.MinimalUserBean; |
22 |
import my.com.upass.pojo.UserAppAccess; |
23 |
import net.penril.generic.hibernate.GenericDAOHibernate; |
24 |
import net.penril.generic.hibernate.HibernateUtils; |
25 |
|
26 |
import org.apache.commons.lang.NotImplementedException; |
27 |
import org.apache.log4j.Logger; |
28 |
import org.hibernate.Session; |
29 |
|
30 |
/**
|
31 |
* @author Hadi
|
32 |
*
|
33 |
*/
|
34 |
@WebService(
|
35 |
serviceName = "MaybankFacade",
|
36 |
endpointInterface = "my.com.upass.maybank.MaybankFacade")
|
37 |
//
|
38 |
public class MaybankFacadeImpl |
39 |
extends MinimalMaybankFacadeImpl
|
40 |
implements MaybankFacade {
|
41 |
|
42 |
private static final Logger LOGGER = Logger.getLogger(MaybankFacadeImpl.class); |
43 |
|
44 |
private final UPassControllerV2 upcV2; |
45 |
|
46 |
//
|
47 |
|
48 |
public MaybankFacadeImpl() {
|
49 |
upcV2 = new UPassControllerV2();
|
50 |
} |
51 |
|
52 |
@Override
|
53 |
public int newAdminUser( |
54 |
String appAccessId, String hashedSecretKey, |
55 |
String username, String hashedPassword) { |
56 |
|
57 |
IbccUser ibccUser = new IbccUser();
|
58 |
// ibccUser.setPanCc(panCc);
|
59 |
|
60 |
MinimalUserBean minUser = new MinimalUserBean();
|
61 |
minUser.setUsername(username); |
62 |
minUser.setHashedPassword(hashedPassword); |
63 |
ibccUser.setMinUser(minUser); |
64 |
|
65 |
return newAdminUser(appAccessId, hashedSecretKey, ibccUser);
|
66 |
} |
67 |
|
68 |
public int newPublicUser( |
69 |
String appAccessId, String hashedSecretKey, |
70 |
String username, String hashedPassword, String panCc) { |
71 |
|
72 |
IbccUser ibccUser = new IbccUser();
|
73 |
ibccUser.setPanCc(panCc); |
74 |
|
75 |
MinimalUserBean minUser = new MinimalUserBean();
|
76 |
minUser.setUsername(username); |
77 |
minUser.setHashedPassword(hashedPassword); |
78 |
ibccUser.setMinUser(minUser); |
79 |
|
80 |
return newUser(appAccessId, hashedSecretKey, ibccUser);
|
81 |
} |
82 |
|
83 |
@Override
|
84 |
public int convertPublicToM2u( |
85 |
String appAccessId, String hashedSecretKey, |
86 |
String username, String pan1, String pan2) { |
87 |
|
88 |
// TODO Auto-generated method stub
|
89 |
throw new NotImplementedException(); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* @deprecated
|
94 |
* @see #lookupUsername(String, String, String)
|
95 |
*/
|
96 |
@Override
|
97 |
public Response lookupUsername_internal(
|
98 |
String appAccessId, String hashedSecretKey, String username) { |
99 |
|
100 |
throw new java.lang.UnsupportedOperationException(); |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public ResponseElement lookupUsername(
|
105 |
String appAccessId, String hashedSecretKey, String username) { |
106 |
|
107 |
final Response response = super.lookupUsername_internal(appAccessId, hashedSecretKey, username); |
108 |
return new ResponseElement(response); |
109 |
} |
110 |
|
111 |
/**
|
112 |
* @deprecated
|
113 |
* @see #lookupPublicUsername(String, String, String)
|
114 |
*/
|
115 |
@Override
|
116 |
public Response lookupPublicUsername_internal(
|
117 |
String appAccessId, String hashedSecretKey, String username) { |
118 |
|
119 |
throw new java.lang.UnsupportedOperationException(); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public ResponseElement lookupPublicUsername(
|
124 |
String appAccessId, String hashedSecretKey, String username) { |
125 |
|
126 |
final Response response = super.lookupPublicUsername_internal(appAccessId, hashedSecretKey, username); |
127 |
return new ResponseElement(response); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* @deprecated
|
132 |
* @see #lookupPan1(String, String, String)
|
133 |
*/
|
134 |
@Override
|
135 |
public Response lookupPan1_internal(
|
136 |
String appAccessId, String hashedSecretKey, String pan1) { |
137 |
|
138 |
throw new java.lang.UnsupportedOperationException(); |
139 |
} |
140 |
|
141 |
@Override
|
142 |
public ResponseElement lookupPan1(
|
143 |
String appAccessId, String hashedSecretKey, String pan1) { |
144 |
|
145 |
final Response response = super.lookupPan1_internal(appAccessId, hashedSecretKey, pan1); |
146 |
return new ResponseElement(response); |
147 |
} |
148 |
|
149 |
/**
|
150 |
* @deprecated
|
151 |
* @see #lookupPan2(String, String, String)
|
152 |
*/
|
153 |
@Override
|
154 |
public Response lookupPan2_internal(
|
155 |
String appAccessId, String hashedSecretKey, String pan1) { |
156 |
|
157 |
throw new java.lang.UnsupportedOperationException(); |
158 |
} |
159 |
|
160 |
@Override
|
161 |
public ResponseElement lookupPan2(
|
162 |
String appAccessId, String hashedSecretKey, String pan2) { |
163 |
|
164 |
final Response response = super.lookupPan2_internal(appAccessId, hashedSecretKey, pan2); |
165 |
return new ResponseElement(response); |
166 |
} |
167 |
|
168 |
/**
|
169 |
* @deprecated
|
170 |
* @see #lookupPanCc(String, String, String)
|
171 |
*/
|
172 |
@Override
|
173 |
public Response lookupPanCc_internal(
|
174 |
String appAccessId, String hashedSecretKey, String panCc) { |
175 |
|
176 |
throw new java.lang.UnsupportedOperationException(); |
177 |
} |
178 |
|
179 |
@Override
|
180 |
public ResponseElement lookupPanCc(
|
181 |
String appAccessId, String hashedSecretKey, String panCc) { |
182 |
|
183 |
final Response response = super.lookupPanCc_internal(appAccessId, hashedSecretKey, panCc); |
184 |
return new ResponseElement(response); |
185 |
} |
186 |
|
187 |
@Override
|
188 |
public ResponseElement lookupUsernameByGroup(
|
189 |
String appAccessId, String hashedSecretKey, |
190 |
String username) {
|
191 |
|
192 |
// TODO Auto-generated method stub
|
193 |
throw new NotImplementedException(); |
194 |
} |
195 |
|
196 |
@Override
|
197 |
public int deleteUser( |
198 |
String appAccessId, String hashedSecretKey, |
199 |
String username) {
|
200 |
|
201 |
int rc = MinimalConstants.ERR_UNKNOWN;
|
202 |
Session session = null;
|
203 |
try {
|
204 |
session = HibernateUtils.currentSession(); |
205 |
session.beginTransaction(); |
206 |
|
207 |
rc = upcV2.deleteUserWithTheProfile(appAccessId, hashedSecretKey, username, session); |
208 |
|
209 |
if (rc == MinimalConstants.ERR_SUCCESS)
|
210 |
session.getTransaction().commit(); |
211 |
else
|
212 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
213 |
|
214 |
} catch (UPassException e) {
|
215 |
rc = e.getErrorCode(); |
216 |
e.printStackTrace(); |
217 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
218 |
|
219 |
} catch (Exception e) { |
220 |
LOGGER.error(e, e); |
221 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
222 |
|
223 |
} finally {
|
224 |
GenericDAOHibernate.closeSessionIfAny(session); |
225 |
} |
226 |
return rc;
|
227 |
} |
228 |
|
229 |
@Override
|
230 |
public ResponseListElement searchUserByFilter(
|
231 |
String appAccessId, String hashedSecretKey, |
232 |
Map<String, String> searchFilter) { |
233 |
|
234 |
ResponseListElement res = new ResponseListElement();
|
235 |
final List<Map<String, String>> items = new LinkedList<Map<String, String>>(); |
236 |
|
237 |
Session session = null;
|
238 |
try {
|
239 |
session = HibernateUtils.currentSession(); |
240 |
|
241 |
List<UserProfile> examples = new ArrayList<UserProfile>(5); |
242 |
for (Class<? extends UserProfile> clazz : Arrays.asList( |
243 |
IbccUser.class, Im2uUser.class, M2uUser.class, StockUser.class, TicketingUser.class)) { |
244 |
|
245 |
final UserProfile example = clazz.newInstance();
|
246 |
example.mapToProperties(searchFilter); |
247 |
examples.add(example); |
248 |
} |
249 |
List<UserProfile> profiles = upcV2.listProfilesByExamples(
|
250 |
appAccessId, hashedSecretKey, examples, session); |
251 |
|
252 |
for (UserProfile profile : profiles)
|
253 |
items.add(profile.propertiesToMap()); |
254 |
|
255 |
res.setItems(items); |
256 |
res.setCode(MinimalConstants.ERR_SUCCESS); |
257 |
|
258 |
} catch (UPassException e) {
|
259 |
LOGGER.info(e, e); |
260 |
res.setCode(e.getErrorCode()); |
261 |
|
262 |
} catch (Exception e) { |
263 |
LOGGER.error(e, e); |
264 |
res.setCode(MinimalConstants.ERR_UNKNOWN); |
265 |
|
266 |
} finally {
|
267 |
GenericDAOHibernate.closeSessionIfAny(session); |
268 |
} |
269 |
return res;
|
270 |
} |
271 |
|
272 |
@Override
|
273 |
public int changeIdNo( |
274 |
String appAccessId, String hashedSecretKey, |
275 |
String username, String idNo) { |
276 |
|
277 |
Session session = null;
|
278 |
try {
|
279 |
session = HibernateUtils.currentSession(); |
280 |
session.beginTransaction(); |
281 |
|
282 |
UserProfile profile = upcV2.findProfile( |
283 |
appAccessId, hashedSecretKey, username, ClientApp.APP_ID_ONLINE_STOCK, session); |
284 |
|
285 |
if (profile instanceof StockUser) { |
286 |
StockUser stockUser = (StockUser) profile; |
287 |
stockUser.setIdNo(idNo); |
288 |
|
289 |
int rc = upcV2.updateProfileShallowly(
|
290 |
appAccessId, hashedSecretKey, stockUser, session); |
291 |
|
292 |
if (rc == MinimalConstants.ERR_SUCCESS)
|
293 |
session.getTransaction().commit(); |
294 |
else
|
295 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
296 |
|
297 |
return rc;
|
298 |
|
299 |
} else {
|
300 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
301 |
return MinimalConstants.ERR_INVALID_INPUT;
|
302 |
} |
303 |
} catch (UPassException e) {
|
304 |
LOGGER.info(e, e); |
305 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
306 |
return e.getErrorCode();
|
307 |
|
308 |
} catch (Exception e) { |
309 |
LOGGER.error(e, e); |
310 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
311 |
return MinimalConstants.ERR_UNKNOWN;
|
312 |
|
313 |
} finally {
|
314 |
GenericDAOHibernate.closeSessionIfAny(session); |
315 |
} |
316 |
} |
317 |
|
318 |
// Helper methods
|
319 |
|
320 |
protected int newAdminUser( |
321 |
String appAccessId, String hashedSecretKey, UserProfile profile) { |
322 |
|
323 |
int rc = MinimalConstants.ERR_UNKNOWN;
|
324 |
Session session = null;
|
325 |
try {
|
326 |
session = HibernateUtils.currentSession(); |
327 |
session.beginTransaction(); |
328 |
|
329 |
rc = upcV2.addUser( |
330 |
appAccessId, hashedSecretKey, profile.getMinUser(), UserAppAccess.TYPE_ADMIN, session); |
331 |
|
332 |
if (rc == MinimalConstants.ERR_SUCCESS) {
|
333 |
rc = upcV2.updateProfileShallowly(appAccessId, hashedSecretKey, profile, session); |
334 |
|
335 |
if (rc == MinimalConstants.ERR_SUCCESS)
|
336 |
session.getTransaction().commit(); |
337 |
else
|
338 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
339 |
|
340 |
} else
|
341 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
342 |
|
343 |
} catch (Exception e) { |
344 |
GenericDAOHibernate.rollbackTransactionIfAny(session); |
345 |
LOGGER.error(e, e); |
346 |
|
347 |
} finally {
|
348 |
GenericDAOHibernate.closeSessionIfAny(session); |
349 |
} |
350 |
return rc;
|
351 |
} |
352 |
} |