Revision 44:7a7fb8fcfd6e src/my/com/upass/services/DeleteUserService.java
src/my/com/upass/services/DeleteUserService.java | ||
---|---|---|
3 | 3 |
import java.text.SimpleDateFormat; |
4 | 4 |
import java.util.Date; |
5 | 5 |
|
6 |
import org.hibernate.Session; |
|
7 |
|
|
6 | 8 |
import my.com.upass.Constants; |
9 |
import my.com.upass.MinimalConstants; |
|
7 | 10 |
import my.com.upass.dao.DAOFactoryProvider; |
8 | 11 |
import my.com.upass.dao.UserDAO; |
12 |
import my.com.upass.maybank.entities.UserProfile; |
|
9 | 13 |
import my.com.upass.pojo.MinimalUserBean; |
10 | 14 |
import my.com.upass.pojo.UserBeanBackup; |
11 | 15 |
import my.com.upass.pojo.UserMasterBeanBackup; |
... | ... | |
15 | 19 |
public DeleteUserService() { |
16 | 20 |
} |
17 | 21 |
|
18 |
public int deleteUser(String userAlias) { |
|
22 |
public int deleteUser(String userAlias, Session txSession) {
|
|
19 | 23 |
|
20 | 24 |
int rc = Constants.ERR_SYSTEM_NOT_READY; |
21 | 25 |
|
22 | 26 |
if (userAlias == null) { |
23 | 27 |
return Constants.ERR_INVALID_INPUT; |
24 | 28 |
} |
25 |
|
|
26 | 29 |
UserDAO userDao; |
27 |
|
|
28 | 30 |
try { |
29 | 31 |
userDao = DAOFactoryProvider.getDAOFactory().getUserDAO(); |
30 | 32 |
UserBeanBackup ubBackup = null; |
31 |
|
|
32 |
// UserBean ubClone = userDao.getUserFromStore (userAlias); |
|
33 |
|
|
34 |
MinimalUserBean ub = userDao.getUserFromStore(userAlias, null); |
|
33 |
MinimalUserBean ub = userDao.getUserFromStore(userAlias, txSession); |
|
35 | 34 |
|
36 | 35 |
if (ub == null) { |
37 | 36 |
return Constants.ERR_INVALID_INPUT; |
38 | 37 |
} |
39 |
|
|
40 | 38 |
String concatedUser = concatUser(userAlias); |
41 | 39 |
|
42 | 40 |
if (!userAlias.equalsIgnoreCase(concatedUser)) { |
43 |
|
|
44 | 41 |
ubBackup = new UserBeanBackup(); |
45 | 42 |
ubBackup.setUserID(ub.getUserID()); |
46 | 43 |
ubBackup.setUserAlias(concatedUser); |
... | ... | |
66 | 63 |
masterBackup.setUserID(ub.getUserID()); |
67 | 64 |
ubBackup.setUpassUserMasterBackup(masterBackup); |
68 | 65 |
} |
69 |
if (userDao.insertUserToBackupStore(ubBackup, null)) {
|
|
66 |
if (userDao.insertUserToBackupStore(ubBackup, txSession)) {
|
|
70 | 67 |
rc = Constants.ERR_SUCCESS; |
71 | 68 |
|
72 | 69 |
} else { |
... | ... | |
77 | 74 |
// master.setUserID(ub.getUserID()); |
78 | 75 |
// ub.setUpassUserMaster (master); |
79 | 76 |
|
80 |
if (userDao.deleteUser(ub, null)) {
|
|
77 |
if (userDao.deleteUser(ub, txSession)) {
|
|
81 | 78 |
rc = Constants.ERR_SUCCESS; |
82 | 79 |
|
83 | 80 |
} else { |
84 | 81 |
rc = Constants.ERR_SYSTEM_NOT_READY; |
85 | 82 |
} |
83 |
} catch (Exception e) { |
|
84 |
e.printStackTrace(); |
|
85 |
} |
|
86 |
return rc; |
|
87 |
} |
|
88 |
|
|
89 |
public int deleteUser( |
|
90 |
String username, Integer targetAppId, Session txSession) { |
|
91 |
|
|
92 |
int rc = Constants.ERR_SYSTEM_NOT_READY; |
|
93 |
|
|
94 |
if (username == null) { |
|
95 |
return Constants.ERR_INVALID_INPUT; |
|
96 |
} |
|
97 |
try { |
|
98 |
UserDAO userDao = DAOFactoryProvider.getDAOFactory().getUserDAO(); |
|
99 |
|
|
100 |
final Class<UserProfile> profileClass = (Class<UserProfile>) |
|
101 |
AppAccessMgtService.appToProfileMap.get(targetAppId); |
|
102 |
|
|
103 |
boolean profileDeleted = userDao.deleteProfile(username, profileClass, txSession); |
|
104 |
|
|
105 |
if (profileDeleted) |
|
106 |
rc = deleteUser(username, txSession); |
|
107 |
else |
|
108 |
rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
|
86 | 109 |
|
87 | 110 |
} catch (Exception e) { |
88 | 111 |
e.printStackTrace(); |
... | ... | |
94 | 117 |
SimpleDateFormat dateFormat = new SimpleDateFormat("ddMMyyyyHHmmss"); |
95 | 118 |
return userAlias.concat("-").concat(dateFormat.format(new Date())); |
96 | 119 |
} |
120 |
|
|
97 | 121 |
} |
Also available in: Unified diff