Statistics
| Branch: | Revision:

m2u-upass-core / src / my / com / upass / maybank / MaybankFacadeImpl.java @ 41:758ee93c26ca

History | View | Annotate | Download (6.99 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.MinimalUserBean;
21
import my.com.upass.pojo.UserAppAccess;
22
import net.penril.generic.hibernate.GenericDAOHibernate;
23
import net.penril.generic.hibernate.HibernateUtils;
24

    
25
import org.apache.commons.lang.NotImplementedException;
26
import org.apache.log4j.Logger;
27
import org.hibernate.Session;
28

    
29
@WebService(
30
                serviceName = "MaybankFacade",
31
                endpointInterface = "my.com.upass.maybank.MaybankFacade")
32
//
33
public class MaybankFacadeImpl
34
                extends MinimalMaybankFacadeImpl
35
                implements MaybankFacade {
36

    
37
        private static final Logger LOGGER = Logger.getLogger(MaybankFacadeImpl.class);
38

    
39
        private final UPassControllerV2 upcV2;
40

    
41
        //
42

    
43
        public MaybankFacadeImpl() {
44
                upcV2 = new UPassControllerV2();
45
        }
46

    
47
        @Override
48
        public int newAdminUser(
49
                        String appAccessId, String hashedSecretKey,
50
                        String username, String hashedPassword) {
51

    
52
                IbccUser ibccUser = new IbccUser();
53
                // ibccUser.setPanCc(panCc);
54

    
55
                MinimalUserBean minUser = new MinimalUserBean();
56
                minUser.setUsername(username);
57
                minUser.setHashedPassword(hashedPassword);
58
                ibccUser.setMinUser(minUser);
59

    
60
                return newAdminUser(appAccessId, hashedSecretKey, ibccUser);
61
        }
62

    
63
        public int newPublicUser(
64
                        String appAccessId, String hashedSecretKey,
65
                        String username, String hashedPassword, String panCc) {
66

    
67
                IbccUser ibccUser = new IbccUser();
68
                ibccUser.setPanCc(panCc);
69

    
70
                MinimalUserBean minUser = new MinimalUserBean();
71
                minUser.setUsername(username);
72
                minUser.setHashedPassword(hashedPassword);
73
                ibccUser.setMinUser(minUser);
74

    
75
                return newUser(appAccessId, hashedSecretKey, ibccUser);
76
        }
77

    
78
        @Override
79
        public int convertPublicToM2u(
80
                        String appAccessId, String hashedSecretKey,
81
                        String username, String pan1, String pan2) {
82

    
83
                // TODO Auto-generated method stub
84
                throw new NotImplementedException();
85
        }
86

    
87
        @Override
88
        public ResponseElement lookupUsername(
89
                        String appAccessId, String hashedSecretKey, String username) {
90

    
91
                final Response response = super.lookupUsername_internal(appAccessId, hashedSecretKey, username);
92
                return new ResponseElement(response);
93
        }
94

    
95
        @Deprecated
96
        @Override
97
        public Response lookupUsername_internal(
98
                        String appAccessId, String hashedSecretKey, String username) {
99

    
100
                throw new NotImplementedException();
101
        }
102

    
103
        @Override
104
        public ResponseElement lookupPublicUserName(
105
                        String appAccessId, String hashedSecretKey, String username) {
106

    
107
                return lookupUsername(appAccessId, hashedSecretKey, username);
108
        }
109

    
110
        @Override
111
        public ResponseElement lookupUsernameByGroup(
112
                        String appAccessId, String hashedSecretKey,
113
                        String username) {
114

    
115
                // TODO Auto-generated method stub
116
                throw new NotImplementedException();
117
        }
118

    
119
        @Override
120
        public ResponseElement lookupPan1(
121
                        String appAccessId, String hashedSecretKey,
122
                        String pan1) {
123

    
124
                // TODO Auto-generated method stub
125
                throw new NotImplementedException();
126
        }
127

    
128
        @Override
129
        public ResponseElement lookupPan2(
130
                        String appAccessId, String hashedSecretKey,
131
                        String pan2) {
132

    
133
                // TODO Auto-generated method stub
134
                throw new NotImplementedException();
135
        }
136

    
137
        @Override
138
        public ResponseElement lookupPanCc(
139
                        String appAccessId, String hashedSecretKey,
140
                        String panCC) {
141

    
142
                // TODO Auto-generated method stub
143
                throw new NotImplementedException();
144
        }
145

    
146
        @Override
147
        public int deleteUser(
148
                        String appAccessId, String hashedSecretKey,
149
                        String username) {
150

    
151
                // TODO Auto-generated method stub
152
                throw new NotImplementedException();
153
        }
154

    
155
        @Override
156
        public ResponseListElement searchUserByFilter(
157
                        String appAccessId, String hashedSecretKey,
158
                        Map<String, String> searchFilter) {
159

    
160
                ResponseListElement res = new ResponseListElement();
161
                final List<Map<String, String>> items = new LinkedList<Map<String, String>>();
162

    
163
                Session session = null;
164
                try {
165
                        session = HibernateUtils.currentSession();
166
                        
167
                        List<UserProfile> examples = new ArrayList<UserProfile>(5);
168
                        for (Class<? extends UserProfile> clazz : Arrays.asList(
169
                                        IbccUser.class, Im2uUser.class, M2uUser.class, StockUser.class, TicketingUser.class)) {
170

    
171
                                final UserProfile example = clazz.newInstance();
172
                                example.mapToProperties(searchFilter);
173
                                examples.add(example);
174
                        }
175
                        List<UserProfile> profiles = upcV2.listProfilesByExamples(appAccessId, hashedSecretKey, examples, session);
176
                        for (UserProfile profile : profiles)
177
                                items.add(profile.propertiesToMap());
178

    
179
                        res.setItems(items);
180
                        res.setCode(MinimalConstants.ERR_SUCCESS);
181

    
182
                } catch (UPassException e) {
183
                        LOGGER.info(e, e);
184
                        res.setCode(e.getErrorCode());
185

    
186
                } catch (Exception e) {
187
                        LOGGER.error(e, e);
188
                        res.setCode(MinimalConstants.ERR_UNKNOWN);
189

    
190
                } finally {
191
                        GenericDAOHibernate.closeSessionIfAny(session);
192
                }
193
                return res;
194
        }
195

    
196
        @Override
197
        public int changeIdNo(
198
                        String appAccessId, String hashedSecretKey,
199
                        String username, String idNo) {
200

    
201
                Session session = null;
202
                try {
203
                        session = HibernateUtils.currentSession();
204
                        session.beginTransaction();
205

    
206
                        UserProfile profile = upcV2.findProfile(
207
                                        appAccessId, hashedSecretKey, username, session);
208

    
209
                        if (profile instanceof StockUser) {
210
                                StockUser stockUser = (StockUser) profile;
211
                                stockUser.setIdNo(idNo);
212

    
213
                                int rc = upcV2.updateProfileShallowly(
214
                                                appAccessId, hashedSecretKey, stockUser, session);
215

    
216
                                session.getTransaction().commit();
217
                                return rc;
218

    
219
                        } else {
220
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
221
                                return MinimalConstants.ERR_APP_SERV_NOT_PERMITTED;
222
                        }
223
                } catch (UPassException e) {
224
                        LOGGER.info(e, e);
225
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
226
                        return e.getErrorCode();
227

    
228
                } catch (Exception e) {
229
                        LOGGER.error(e, e);
230
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
231
                        return MinimalConstants.ERR_UNKNOWN;
232

    
233
                } finally {
234
                        GenericDAOHibernate.closeSessionIfAny(session);
235
                }
236
        }
237

    
238
        // Helper methods
239

    
240
        protected int newAdminUser(
241
                        String appAccessId, String hashedSecretKey, UserProfile profile) {
242

    
243
                int rc = MinimalConstants.ERR_UNKNOWN;
244
                Session session = null;
245
                try {
246
                        session = HibernateUtils.currentSession();
247
                        session.beginTransaction();
248

    
249
                        rc = upcV2.addUser(
250
                                        appAccessId, hashedSecretKey, profile.getMinUser(), UserAppAccess.TYPE_ADMIN, session);
251

    
252
                        if (rc == MinimalConstants.ERR_SUCCESS) {
253
                                rc = upcV2.updateProfileShallowly(appAccessId, hashedSecretKey, profile, session);
254

    
255
                                session.getTransaction().commit();
256

    
257
                        } else
258
                                GenericDAOHibernate.rollbackTransactionIfAny(session);
259

    
260
                } catch (Exception e) {
261
                        GenericDAOHibernate.rollbackTransactionIfAny(session);
262
                        LOGGER.error(e, e);
263

    
264
                } finally {
265
                        GenericDAOHibernate.closeSessionIfAny(session);
266
                }
267
                return rc;
268
        }
269
}