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