m2u-upass-core / src / my / com / upass / maybank / MaybankFacadeImpl.java @ 41:758ee93c26ca
History | View | Annotate | Download (6.99 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 | 37:848f67a9b39c | hadi | import my.com.upass.pojo.MinimalUserBean; |
21 | 40:29d3fc38fdee | hadi | import my.com.upass.pojo.UserAppAccess; |
22 | import net.penril.generic.hibernate.GenericDAOHibernate; |
||
23 | import net.penril.generic.hibernate.HibernateUtils; |
||
24 | 30:aec0089bb43e | hadi | |
25 | import org.apache.commons.lang.NotImplementedException; |
||
26 | 40:29d3fc38fdee | hadi | import org.apache.log4j.Logger; |
27 | import org.hibernate.Session; |
||
28 | 30:aec0089bb43e | hadi | |
29 | 32:d43f37e77545 | hadi | @WebService(
|
30 | serviceName = "MaybankFacade",
|
||
31 | endpointInterface = "my.com.upass.maybank.MaybankFacade")
|
||
32 | //
|
||
33 | public class MaybankFacadeImpl |
||
34 | extends MinimalMaybankFacadeImpl
|
||
35 | implements MaybankFacade {
|
||
36 | 30:aec0089bb43e | hadi | |
37 | 40:29d3fc38fdee | hadi | private static final Logger LOGGER = Logger.getLogger(MaybankFacadeImpl.class); |
38 | |||
39 | 33:9d5b4aece71c | hadi | private final UPassControllerV2 upcV2; |
40 | |||
41 | 40:29d3fc38fdee | hadi | //
|
42 | |||
43 | 33:9d5b4aece71c | hadi | public MaybankFacadeImpl() {
|
44 | upcV2 = new UPassControllerV2();
|
||
45 | } |
||
46 | |||
47 | @Override
|
||
48 | 34:420c5039e742 | hadi | public int newAdminUser( |
49 | 39:e450611bea1f | hadi | String appAccessId, String hashedSecretKey, |
50 | 34:420c5039e742 | hadi | String username, String hashedPassword) { |
51 | 39:e450611bea1f | hadi | |
52 | 40:29d3fc38fdee | hadi | 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 | 30:aec0089bb43e | hadi | } |
62 | |||
63 | 37:848f67a9b39c | hadi | 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 | 33:9d5b4aece71c | hadi | @Override
|
79 | 39:e450611bea1f | hadi | public int convertPublicToM2u( |
80 | String appAccessId, String hashedSecretKey, |
||
81 | String username, String pan1, String pan2) { |
||
82 | |||
83 | 30:aec0089bb43e | hadi | // TODO Auto-generated method stub
|
84 | throw new NotImplementedException(); |
||
85 | } |
||
86 | |||
87 | 33:9d5b4aece71c | hadi | @Override
|
88 | 39:e450611bea1f | hadi | public ResponseElement lookupUsername(
|
89 | 40:29d3fc38fdee | hadi | String appAccessId, String hashedSecretKey, String username) { |
90 | 39:e450611bea1f | hadi | |
91 | final Response response = super.lookupUsername_internal(appAccessId, hashedSecretKey, username); |
||
92 | return new ResponseElement(response); |
||
93 | } |
||
94 | |||
95 | 40:29d3fc38fdee | hadi | @Deprecated
|
96 | @Override
|
||
97 | public Response lookupUsername_internal(
|
||
98 | String appAccessId, String hashedSecretKey, String username) { |
||
99 | |||
100 | throw new NotImplementedException(); |
||
101 | } |
||
102 | |||
103 | 39:e450611bea1f | hadi | @Override
|
104 | public ResponseElement lookupPublicUserName(
|
||
105 | 40:29d3fc38fdee | hadi | String appAccessId, String hashedSecretKey, String username) { |
106 | 39:e450611bea1f | hadi | |
107 | 40:29d3fc38fdee | hadi | return lookupUsername(appAccessId, hashedSecretKey, username);
|
108 | 30:aec0089bb43e | hadi | } |
109 | |||
110 | 33:9d5b4aece71c | hadi | @Override
|
111 | 39:e450611bea1f | hadi | public ResponseElement lookupUsernameByGroup(
|
112 | 34:420c5039e742 | hadi | String appAccessId, String hashedSecretKey, |
113 | String username) {
|
||
114 | 39:e450611bea1f | hadi | |
115 | 30:aec0089bb43e | hadi | // TODO Auto-generated method stub
|
116 | throw new NotImplementedException(); |
||
117 | } |
||
118 | |||
119 | 33:9d5b4aece71c | hadi | @Override
|
120 | 41:758ee93c26ca | hadi | public ResponseElement lookupPan1(
|
121 | 39:e450611bea1f | hadi | String appAccessId, String hashedSecretKey, |
122 | 34:420c5039e742 | hadi | String pan1) {
|
123 | 39:e450611bea1f | hadi | |
124 | 30:aec0089bb43e | hadi | // TODO Auto-generated method stub
|
125 | throw new NotImplementedException(); |
||
126 | } |
||
127 | |||
128 | 33:9d5b4aece71c | hadi | @Override
|
129 | 34:420c5039e742 | hadi | public ResponseElement lookupPan2(
|
130 | 39:e450611bea1f | hadi | String appAccessId, String hashedSecretKey, |
131 | 34:420c5039e742 | hadi | String pan2) {
|
132 | 39:e450611bea1f | hadi | |
133 | 30:aec0089bb43e | hadi | // TODO Auto-generated method stub
|
134 | throw new NotImplementedException(); |
||
135 | } |
||
136 | |||
137 | 33:9d5b4aece71c | hadi | @Override
|
138 | 34:420c5039e742 | hadi | public ResponseElement lookupPanCc(
|
139 | String appAccessId, String hashedSecretKey, |
||
140 | String panCC) {
|
||
141 | 39:e450611bea1f | hadi | |
142 | 33:9d5b4aece71c | hadi | // TODO Auto-generated method stub
|
143 | throw new NotImplementedException(); |
||
144 | } |
||
145 | |||
146 | @Override
|
||
147 | 34:420c5039e742 | hadi | public int deleteUser( |
148 | 39:e450611bea1f | hadi | String appAccessId, String hashedSecretKey, |
149 | 34:420c5039e742 | hadi | String username) {
|
150 | 39:e450611bea1f | hadi | |
151 | 30:aec0089bb43e | hadi | // TODO Auto-generated method stub
|
152 | throw new NotImplementedException(); |
||
153 | } |
||
154 | |||
155 | 33:9d5b4aece71c | hadi | @Override
|
156 | 40:29d3fc38fdee | hadi | public ResponseListElement searchUserByFilter(
|
157 | 39:e450611bea1f | hadi | String appAccessId, String hashedSecretKey, |
158 | 40:29d3fc38fdee | hadi | Map<String, String> searchFilter) { |
159 | 39:e450611bea1f | hadi | |
160 | 40:29d3fc38fdee | hadi | 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 | 39:e450611bea1f | hadi | } |
195 | |||
196 | @Override
|
||
197 | public int changeIdNo( |
||
198 | String appAccessId, String hashedSecretKey, |
||
199 | String username, String idNo) { |
||
200 | |||
201 | 40:29d3fc38fdee | hadi | 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 | 30:aec0089bb43e | hadi | } |
269 | } |