Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / maybank / MaybankFacadeImpl.java @ 44:7a7fb8fcfd6e

History | View | Annotate | Download (9.21 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 30:aec0089bb43e hadi
import javax.jws.WebService;
10
11 40:29d3fc38fdee hadi
import my.com.upass.MinimalConstants;
12 33:9d5b4aece71c hadi
import my.com.upass.UPassControllerV2;
13 40:29d3fc38fdee hadi
import my.com.upass.UPassException;
14 37:848f67a9b39c hadi
import my.com.upass.maybank.entities.IbccUser;
15 40:29d3fc38fdee hadi
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 42:d32be3a379fb hadi
import my.com.upass.pojo.ClientApp;
21 37:848f67a9b39c hadi
import my.com.upass.pojo.MinimalUserBean;
22 40:29d3fc38fdee hadi
import my.com.upass.pojo.UserAppAccess;
23
import net.penril.generic.hibernate.GenericDAOHibernate;
24
import net.penril.generic.hibernate.HibernateUtils;
25 30:aec0089bb43e hadi
26
import org.apache.commons.lang.NotImplementedException;
27 40:29d3fc38fdee hadi
import org.apache.log4j.Logger;
28
import org.hibernate.Session;
29 30:aec0089bb43e hadi
30 43:78b1d801d083 hadi
/**
31
 * @author Hadi
32
 *
33
 */
34 32:d43f37e77545 hadi
@WebService(
35
                serviceName = "MaybankFacade",
36
                endpointInterface = "my.com.upass.maybank.MaybankFacade")
37
//
38
public class MaybankFacadeImpl
39
                extends MinimalMaybankFacadeImpl
40
                implements MaybankFacade {
41 30:aec0089bb43e hadi
42 40:29d3fc38fdee hadi
        private static final Logger LOGGER = Logger.getLogger(MaybankFacadeImpl.class);
43
44 33:9d5b4aece71c hadi
        private final UPassControllerV2 upcV2;
45
46 40:29d3fc38fdee hadi
        //
47
48 33:9d5b4aece71c hadi
        public MaybankFacadeImpl() {
49
                upcV2 = new UPassControllerV2();
50
        }
51
52
        @Override
53 34:420c5039e742 hadi
        public int newAdminUser(
54 39:e450611bea1f hadi
                        String appAccessId, String hashedSecretKey,
55 34:420c5039e742 hadi
                        String username, String hashedPassword) {
56 39:e450611bea1f hadi
57 40:29d3fc38fdee hadi
                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 30:aec0089bb43e hadi
        }
67
68 37:848f67a9b39c hadi
        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 33:9d5b4aece71c hadi
        @Override
84 39:e450611bea1f hadi
        public int convertPublicToM2u(
85
                        String appAccessId, String hashedSecretKey,
86
                        String username, String pan1, String pan2) {
87
88 30:aec0089bb43e hadi
                // TODO Auto-generated method stub
89
                throw new NotImplementedException();
90
        }
91
92 43:78b1d801d083 hadi
        /**
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 33:9d5b4aece71c hadi
        @Override
104 39:e450611bea1f hadi
        public ResponseElement lookupUsername(
105 40:29d3fc38fdee hadi
                        String appAccessId, String hashedSecretKey, String username) {
106 39:e450611bea1f hadi
107
                final Response response = super.lookupUsername_internal(appAccessId, hashedSecretKey, username);
108
                return new ResponseElement(response);
109
        }
110
111 43:78b1d801d083 hadi
        /**
112
         * @deprecated
113
         * @see #lookupPublicUsername(String, String, String)
114
         */
115 40:29d3fc38fdee hadi
        @Override
116 43:78b1d801d083 hadi
        public Response lookupPublicUsername_internal(
117 40:29d3fc38fdee hadi
                        String appAccessId, String hashedSecretKey, String username) {
118
119 42:d32be3a379fb hadi
                throw new java.lang.UnsupportedOperationException();
120 40:29d3fc38fdee hadi
        }
121
122 39:e450611bea1f hadi
        @Override
123 42:d32be3a379fb hadi
        public ResponseElement lookupPublicUsername(
124 40:29d3fc38fdee hadi
                        String appAccessId, String hashedSecretKey, String username) {
125 39:e450611bea1f hadi
126 42:d32be3a379fb hadi
                final Response response = super.lookupPublicUsername_internal(appAccessId, hashedSecretKey, username);
127
                return new ResponseElement(response);
128
        }
129
130 43:78b1d801d083 hadi
        /**
131
         * @deprecated
132
         * @see #lookupPan1(String, String, String)
133
         */
134 42:d32be3a379fb hadi
        @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 43:78b1d801d083 hadi
        /**
150
         * @deprecated
151
         * @see #lookupPan2(String, String, String)
152
         */
153 42:d32be3a379fb hadi
        @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 43:78b1d801d083 hadi
        /**
169
         * @deprecated
170
         * @see #lookupPanCc(String, String, String)
171
         */
172 42:d32be3a379fb hadi
        @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 30:aec0089bb43e hadi
        }
186
187 33:9d5b4aece71c hadi
        @Override
188 39:e450611bea1f hadi
        public ResponseElement lookupUsernameByGroup(
189 34:420c5039e742 hadi
                        String appAccessId, String hashedSecretKey,
190
                        String username) {
191 39:e450611bea1f hadi
192 30:aec0089bb43e hadi
                // TODO Auto-generated method stub
193
                throw new NotImplementedException();
194
        }
195
196 33:9d5b4aece71c hadi
        @Override
197 34:420c5039e742 hadi
        public int deleteUser(
198 39:e450611bea1f hadi
                        String appAccessId, String hashedSecretKey,
199 34:420c5039e742 hadi
                        String username) {
200 39:e450611bea1f hadi
201 43:78b1d801d083 hadi
                int rc = MinimalConstants.ERR_UNKNOWN;
202
                Session session = null;
203
                try {
204
                        session = HibernateUtils.currentSession();
205
                        session.beginTransaction();
206
207 44:7a7fb8fcfd6e hadi
                        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 43:78b1d801d083 hadi
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 30:aec0089bb43e hadi
        }
228
229 33:9d5b4aece71c hadi
        @Override
230 40:29d3fc38fdee hadi
        public ResponseListElement searchUserByFilter(
231 39:e450611bea1f hadi
                        String appAccessId, String hashedSecretKey,
232 40:29d3fc38fdee hadi
                        Map<String, String> searchFilter) {
233 39:e450611bea1f hadi
234 40:29d3fc38fdee hadi
                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 42:d32be3a379fb hadi
241 40:29d3fc38fdee hadi
                        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 42:d32be3a379fb hadi
                        List<UserProfile> profiles = upcV2.listProfilesByExamples(
250
                                        appAccessId, hashedSecretKey, examples, session);
251
252 40:29d3fc38fdee hadi
                        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 39:e450611bea1f hadi
        }
271
272
        @Override
273
        public int changeIdNo(
274
                        String appAccessId, String hashedSecretKey,
275
                        String username, String idNo) {
276
277 40:29d3fc38fdee hadi
                Session session = null;
278
                try {
279
                        session = HibernateUtils.currentSession();
280
                        session.beginTransaction();
281
282
                        UserProfile profile = upcV2.findProfile(
283 42:d32be3a379fb hadi
                                        appAccessId, hashedSecretKey, username, ClientApp.APP_ID_ONLINE_STOCK, session);
284 40:29d3fc38fdee hadi
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 44:7a7fb8fcfd6e hadi
                                if (rc == MinimalConstants.ERR_SUCCESS)
293
                                        session.getTransaction().commit();
294
                                else
295
                                        GenericDAOHibernate.rollbackTransactionIfAny(session);
296
297 40:29d3fc38fdee hadi
                                return rc;
298
299
                        } else {
300
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
301 42:d32be3a379fb hadi
                                return MinimalConstants.ERR_INVALID_INPUT;
302 40:29d3fc38fdee hadi
                        }
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 44:7a7fb8fcfd6e hadi
                                if (rc == MinimalConstants.ERR_SUCCESS)
336
                                        session.getTransaction().commit();
337
                                else
338
                                        GenericDAOHibernate.rollbackTransactionIfAny(session);
339 40:29d3fc38fdee hadi
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 30:aec0089bb43e hadi
        }
352
}