Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / maybank / MaybankFacadeImpl.java @ 51:74be74b4d46a

History | View | Annotate | Download (11.3 KB)

1 30:aec0089bb43e hadi
package my.com.upass.maybank;
2
3 50:4121579eae5e hadi
import java.text.ParseException;
4 40:29d3fc38fdee hadi
import java.util.ArrayList;
5
import java.util.Arrays;
6 51:74be74b4d46a hadi
import java.util.HashMap;
7 40:29d3fc38fdee hadi
import java.util.LinkedList;
8
import java.util.List;
9
import java.util.Map;
10
11 51:74be74b4d46a hadi
import javax.jws.WebParam;
12
import javax.jws.WebResult;
13 30:aec0089bb43e hadi
import javax.jws.WebService;
14
15 40:29d3fc38fdee hadi
import my.com.upass.MinimalConstants;
16 33:9d5b4aece71c hadi
import my.com.upass.UPassControllerV2;
17 40:29d3fc38fdee hadi
import my.com.upass.UPassException;
18 46:8f67d8567943 hadi
import my.com.upass.generic.hibernate.GenericDAOHibernate;
19
import my.com.upass.generic.hibernate.HibernateUtils;
20 37:848f67a9b39c hadi
import my.com.upass.maybank.entities.IbccUser;
21 40:29d3fc38fdee hadi
import my.com.upass.maybank.entities.Im2uUser;
22
import my.com.upass.maybank.entities.M2uUser;
23
import my.com.upass.maybank.entities.StockUser;
24
import my.com.upass.maybank.entities.TicketingUser;
25
import my.com.upass.maybank.entities.UserProfile;
26 42:d32be3a379fb hadi
import my.com.upass.pojo.ClientApp;
27 37:848f67a9b39c hadi
import my.com.upass.pojo.MinimalUserBean;
28 40:29d3fc38fdee hadi
import my.com.upass.pojo.UserAppAccess;
29 30:aec0089bb43e hadi
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 51:74be74b4d46a hadi
                final IbccUser ibccUser = new IbccUser();
61 40:29d3fc38fdee hadi
                // ibccUser.setPanCc(panCc);
62
63 51:74be74b4d46a hadi
                final MinimalUserBean minUser = new MinimalUserBean();
64 40:29d3fc38fdee hadi
                minUser.setUsername(username);
65 51:74be74b4d46a 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 51:74be74b4d46a hadi
        @Override
73 37:848f67a9b39c hadi
        public int newPublicUser(
74
                        String appAccessId, String hashedSecretKey,
75
                        String username, String hashedPassword, String panCc) {
76
77 51:74be74b4d46a hadi
                final IbccUser ibccUser = new IbccUser();
78 37:848f67a9b39c hadi
                ibccUser.setPanCc(panCc);
79
80 51:74be74b4d46a hadi
                final MinimalUserBean minUser = new MinimalUserBean();
81 37:848f67a9b39c hadi
                minUser.setUsername(username);
82
                minUser.setHashedPassword(hashedPassword);
83
                ibccUser.setMinUser(minUser);
84
85
                return newUser(appAccessId, hashedSecretKey, ibccUser);
86
        }
87
88 51:74be74b4d46a hadi
        @Override
89
        public int newTicketingUser(
90
                        String appAccessId, String hashedSecretKey,
91
                        String username, String hashedPassword,
92
                        String fullName, String firstName, String lastName, String payeeCode) {
93
94
                final TicketingUser ticketingUser = new TicketingUser();
95
                ticketingUser.setFullName(fullName);
96
                ticketingUser.setFirstName(firstName);
97
                ticketingUser.setLastName(lastName);
98
                ticketingUser.setPayeeCode(payeeCode);
99
100
                final MinimalUserBean minUser = new MinimalUserBean();
101
                minUser.setUsername(username);
102
                minUser.setHashedPassword(hashedPassword);
103
                ticketingUser.setMinUser(minUser);
104
105
                return newUser(appAccessId, hashedSecretKey, ticketingUser);
106
        }
107 43:78b1d801d083 hadi
        /**
108
         * @deprecated
109
         * @see #lookupUsername(String, String, String)
110
         */
111
        @Override
112
        public Response lookupUsername_internal(
113
                        String appAccessId, String hashedSecretKey, String username) {
114
115
                throw new java.lang.UnsupportedOperationException();
116
        }
117
118 33:9d5b4aece71c hadi
        @Override
119 39:e450611bea1f hadi
        public ResponseElement lookupUsername(
120 40:29d3fc38fdee hadi
                        String appAccessId, String hashedSecretKey, String username) {
121 39:e450611bea1f hadi
122
                final Response response = super.lookupUsername_internal(appAccessId, hashedSecretKey, username);
123
                return new ResponseElement(response);
124
        }
125
126 43:78b1d801d083 hadi
        /**
127
         * @deprecated
128
         * @see #lookupPublicUsername(String, String, String)
129
         */
130 40:29d3fc38fdee hadi
        @Override
131 43:78b1d801d083 hadi
        public Response lookupPublicUsername_internal(
132 40:29d3fc38fdee hadi
                        String appAccessId, String hashedSecretKey, String username) {
133
134 42:d32be3a379fb hadi
                throw new java.lang.UnsupportedOperationException();
135 40:29d3fc38fdee hadi
        }
136
137 39:e450611bea1f hadi
        @Override
138 42:d32be3a379fb hadi
        public ResponseElement lookupPublicUsername(
139 40:29d3fc38fdee hadi
                        String appAccessId, String hashedSecretKey, String username) {
140 39:e450611bea1f hadi
141 42:d32be3a379fb hadi
                final Response response = super.lookupPublicUsername_internal(appAccessId, hashedSecretKey, username);
142
                return new ResponseElement(response);
143
        }
144
145 43:78b1d801d083 hadi
        /**
146
         * @deprecated
147
         * @see #lookupPan1(String, String, String)
148
         */
149 42:d32be3a379fb hadi
        @Override
150
        public Response lookupPan1_internal(
151
                        String appAccessId, String hashedSecretKey, String pan1) {
152
153
                throw new java.lang.UnsupportedOperationException();
154
        }
155
156
        @Override
157
        public ResponseElement lookupPan1(
158
                        String appAccessId, String hashedSecretKey, String pan1) {
159
160
                final Response response = super.lookupPan1_internal(appAccessId, hashedSecretKey, pan1);
161
                return new ResponseElement(response);
162
        }
163
164 43:78b1d801d083 hadi
        /**
165
         * @deprecated
166
         * @see #lookupPan2(String, String, String)
167
         */
168 42:d32be3a379fb hadi
        @Override
169
        public Response lookupPan2_internal(
170
                        String appAccessId, String hashedSecretKey, String pan1) {
171
172
                throw new java.lang.UnsupportedOperationException();
173
        }
174
175
        @Override
176
        public ResponseElement lookupPan2(
177
                        String appAccessId, String hashedSecretKey, String pan2) {
178
179
                final Response response = super.lookupPan2_internal(appAccessId, hashedSecretKey, pan2);
180
                return new ResponseElement(response);
181
        }
182
183 43:78b1d801d083 hadi
        /**
184
         * @deprecated
185
         * @see #lookupPanCc(String, String, String)
186
         */
187 42:d32be3a379fb hadi
        @Override
188
        public Response lookupPanCc_internal(
189
                        String appAccessId, String hashedSecretKey, String panCc) {
190
191
                throw new java.lang.UnsupportedOperationException();
192
        }
193
194
        @Override
195
        public ResponseElement lookupPanCc(
196
                        String appAccessId, String hashedSecretKey, String panCc) {
197
198
                final Response response = super.lookupPanCc_internal(appAccessId, hashedSecretKey, panCc);
199
                return new ResponseElement(response);
200 30:aec0089bb43e hadi
        }
201
202 33:9d5b4aece71c hadi
        @Override
203 34:420c5039e742 hadi
        public int deleteUser(
204 39:e450611bea1f hadi
                        String appAccessId, String hashedSecretKey,
205 34:420c5039e742 hadi
                        String username) {
206 39:e450611bea1f hadi
207 43:78b1d801d083 hadi
                int rc = MinimalConstants.ERR_UNKNOWN;
208
                Session session = null;
209
                try {
210
                        session = HibernateUtils.currentSession();
211
                        session.beginTransaction();
212
213 44:7a7fb8fcfd6e hadi
                        rc = upcV2.deleteUserWithTheProfile(appAccessId, hashedSecretKey, username, session);
214
215
                        if (rc == MinimalConstants.ERR_SUCCESS)
216
                                session.getTransaction().commit();
217
                        else
218
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
219
220
                } catch (UPassException e) {
221
                        rc = e.getErrorCode();
222
                        e.printStackTrace();
223
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
224 43:78b1d801d083 hadi
225
                } catch (Exception e) {
226
                        LOGGER.error(e, e);
227
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
228
229
                } finally {
230
                        GenericDAOHibernate.closeSessionIfAny(session);
231
                }
232
                return rc;
233 30:aec0089bb43e hadi
        }
234
235 33:9d5b4aece71c hadi
        @Override
236 40:29d3fc38fdee hadi
        public ResponseListElement searchUserByFilter(
237 39:e450611bea1f hadi
                        String appAccessId, String hashedSecretKey,
238 40:29d3fc38fdee hadi
                        Map<String, String> searchFilter) {
239 39:e450611bea1f hadi
240 40:29d3fc38fdee hadi
                ResponseListElement res = new ResponseListElement();
241
                final List<Map<String, String>> items = new LinkedList<Map<String, String>>();
242
243
                Session session = null;
244
                try {
245
                        session = HibernateUtils.currentSession();
246 42:d32be3a379fb hadi
247 40:29d3fc38fdee hadi
                        List<UserProfile> examples = new ArrayList<UserProfile>(5);
248
                        for (Class<? extends UserProfile> clazz : Arrays.asList(
249
                                        IbccUser.class, Im2uUser.class, M2uUser.class, StockUser.class, TicketingUser.class)) {
250
251
                                final UserProfile example = clazz.newInstance();
252
                                example.mapToProperties(searchFilter);
253
                                examples.add(example);
254
                        }
255 42:d32be3a379fb hadi
                        List<UserProfile> profiles = upcV2.listProfilesByExamples(
256
                                        appAccessId, hashedSecretKey, examples, session);
257
258 40:29d3fc38fdee hadi
                        for (UserProfile profile : profiles)
259
                                items.add(profile.propertiesToMap());
260
261
                        res.setItems(items);
262
                        res.setCode(MinimalConstants.ERR_SUCCESS);
263
264
                } catch (UPassException e) {
265
                        LOGGER.info(e, e);
266
                        res.setCode(e.getErrorCode());
267
268 50:4121579eae5e hadi
                } catch (ParseException e) {
269
                        LOGGER.error(e, e);
270
                        res.setCode(MinimalConstants.ERR_INVALID_INPUT);
271
272 40:29d3fc38fdee hadi
                } catch (Exception e) {
273
                        LOGGER.error(e, e);
274
                        res.setCode(MinimalConstants.ERR_UNKNOWN);
275
276
                } finally {
277
                        GenericDAOHibernate.closeSessionIfAny(session);
278
                }
279
                return res;
280 39:e450611bea1f hadi
        }
281
282
        @Override
283
        public int changeIdNo(
284
                        String appAccessId, String hashedSecretKey,
285
                        String username, String idNo) {
286
287 40:29d3fc38fdee hadi
                Session session = null;
288
                try {
289
                        session = HibernateUtils.currentSession();
290
                        session.beginTransaction();
291
292
                        UserProfile profile = upcV2.findProfile(
293 42:d32be3a379fb hadi
                                        appAccessId, hashedSecretKey, username, ClientApp.APP_ID_ONLINE_STOCK, session);
294 40:29d3fc38fdee hadi
295
                        if (profile instanceof StockUser) {
296
                                StockUser stockUser = (StockUser) profile;
297
                                stockUser.setIdNo(idNo);
298
299
                                int rc = upcV2.updateProfileShallowly(
300
                                                appAccessId, hashedSecretKey, stockUser, session);
301
302 44:7a7fb8fcfd6e hadi
                                if (rc == MinimalConstants.ERR_SUCCESS)
303
                                        session.getTransaction().commit();
304
                                else
305
                                        GenericDAOHibernate.rollbackTransactionIfAny(session);
306
307 40:29d3fc38fdee hadi
                                return rc;
308
309
                        } else {
310
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
311 42:d32be3a379fb hadi
                                return MinimalConstants.ERR_INVALID_INPUT;
312 40:29d3fc38fdee hadi
                        }
313
                } catch (UPassException e) {
314
                        LOGGER.info(e, e);
315
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
316
                        return e.getErrorCode();
317
318
                } catch (Exception e) {
319
                        LOGGER.error(e, e);
320
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
321
                        return MinimalConstants.ERR_UNKNOWN;
322
323
                } finally {
324
                        GenericDAOHibernate.closeSessionIfAny(session);
325
                }
326
        }
327
328 51:74be74b4d46a hadi
        @Override
329
        public CountResponseElement getFailedLoginsCount(
330
                        String appAccessId, String hashedSecretKey, String username) {
331
332
                CountResponse response = super.getFailedLoginsCount(appAccessId, hashedSecretKey, username);
333
                return new CountResponseElement(response);
334
        }
335
336
        @Override
337
        public int updateUserAttributes(
338
                        String appAccessId, String hashedSecretKey,
339
                        String username, Map<String, String> attributes) {
340
341
                Session session = null;
342
                try {
343
                        session = HibernateUtils.currentSession();
344
                        session.beginTransaction();
345
346
                        UserProfile profile = upcV2.findProfile(
347
                                        appAccessId, hashedSecretKey, username, ClientApp.APP_ID_M2U, session);
348
349
                        if (profile != null) {
350
                                final HashMap<String, String> tempMap = new HashMap<String, String>();
351
                                tempMap.putAll(profile.propertiesToMap());
352
353
                                attributes.remove("username");
354
                                tempMap.putAll(attributes);
355
356
                                profile.mapToProperties(tempMap);
357
358
                                int rc = upcV2.updateProfileShallowly(
359
                                                appAccessId, hashedSecretKey, profile, session);
360
361
                                if (rc == MinimalConstants.ERR_SUCCESS) {
362
                                        session.getTransaction().commit();
363
364
                                } else {
365
                                        LOGGER.warn("Unable to update user profile.");
366
                                        GenericDAOHibernate.rollbackTransactionIfAny(session);
367
                                }
368
                                return rc;
369
370
                        } else {
371
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
372
                                return MinimalConstants.ERR_INVALID_INPUT;
373
                        }
374
                } catch (UPassException e) {
375
                        LOGGER.info(e, e);
376
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
377
                        return e.getErrorCode();
378
379
                } catch (Exception e) {
380
                        LOGGER.error(e, e);
381
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
382
                        return MinimalConstants.ERR_UNKNOWN;
383
384
                } finally {
385
                        GenericDAOHibernate.closeSessionIfAny(session);
386
                }
387
        }
388
389 40:29d3fc38fdee hadi
        // Helper methods
390
391
        protected int newAdminUser(
392
                        String appAccessId, String hashedSecretKey, UserProfile profile) {
393
394
                int rc = MinimalConstants.ERR_UNKNOWN;
395
                Session session = null;
396
                try {
397
                        session = HibernateUtils.currentSession();
398
                        session.beginTransaction();
399
400
                        rc = upcV2.addUser(
401
                                        appAccessId, hashedSecretKey, profile.getMinUser(), UserAppAccess.TYPE_ADMIN, session);
402
403
                        if (rc == MinimalConstants.ERR_SUCCESS) {
404
                                rc = upcV2.updateProfileShallowly(appAccessId, hashedSecretKey, profile, session);
405
406 44:7a7fb8fcfd6e hadi
                                if (rc == MinimalConstants.ERR_SUCCESS)
407
                                        session.getTransaction().commit();
408
                                else
409
                                        GenericDAOHibernate.rollbackTransactionIfAny(session);
410 40:29d3fc38fdee hadi
411
                        } else
412
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
413
414
                } catch (Exception e) {
415
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
416
                        LOGGER.error(e, e);
417
418
                } finally {
419
                        GenericDAOHibernate.closeSessionIfAny(session);
420
                }
421
                return rc;
422 30:aec0089bb43e hadi
        }
423
}