m2u-upass-core / src / my / com / upass / services / LockUserService.java @ 68:805ffcfa8c6f
History | View | Annotate | Download (2.18 KB)
1 |
/**
|
---|---|
2 |
* Copyright (c) 2010 Penril Datability (M) Sdn Bhd All rights reserved.
|
3 |
*
|
4 |
* This software is copyrighted. Under the copyright laws, this software
|
5 |
* may not be copied, in whole or in part, without prior written consent
|
6 |
* of Penril Datability (M) Sdn Bhd or its assignees. This software is
|
7 |
* provided under the terms of a license between Penril Datability (M)
|
8 |
* Sdn Bhd and the recipient, and its use is subject to the terms of that
|
9 |
* license.
|
10 |
*/
|
11 |
|
12 |
package my.com.upass.services; |
13 |
|
14 |
import java.util.Calendar; |
15 |
import java.util.Date; |
16 |
|
17 |
import my.com.upass.Constants; |
18 |
import my.com.upass.dao.DAOFactoryProvider; |
19 |
import my.com.upass.dao.UserDAO; |
20 |
import my.com.upass.pojo.MinimalUserBean; |
21 |
|
22 |
/**
|
23 |
* PROGRAMMER: Danniell
|
24 |
* CHANGE-NO:
|
25 |
* TASK-NO:
|
26 |
* DATE CREATED: Dec 28, 2011
|
27 |
* TAG AS:
|
28 |
* REASON(S):
|
29 |
* MODIFICATION:
|
30 |
*/
|
31 |
|
32 |
/**
|
33 |
* <Class description>
|
34 |
*/
|
35 |
public class LockUserService |
36 |
{ |
37 |
public int lockUser (String userAlias) |
38 |
{ |
39 |
return lockUser (userAlias, Constants.UID_STATE_LOCKED, null, 0); |
40 |
} |
41 |
|
42 |
public int lockUser (String userAlias, int mode, Date fromDate, int nMinutes) |
43 |
{ |
44 |
int rc = Constants.ERR_SYSTEM_NOT_READY;
|
45 |
|
46 |
if (userAlias == null) |
47 |
{ |
48 |
return Constants.ERR_INVALID_INPUT;
|
49 |
} |
50 |
|
51 |
UserDAO userDao; |
52 |
|
53 |
try
|
54 |
{ |
55 |
userDao = DAOFactoryProvider.getDAOFactory ().getUserDAO (); |
56 |
MinimalUserBean ub = userDao.getUserFromStore (userAlias, null);
|
57 |
|
58 |
if (ub == null) |
59 |
{ |
60 |
return Constants.ERR_USERALIAS_NOT_FOUND;
|
61 |
} |
62 |
|
63 |
Date now = new Date (); |
64 |
|
65 |
if (mode == Constants.UID_STATE_LOCKED)
|
66 |
{ |
67 |
ub.setUstate (Constants.UID_STATE_LOCKED); |
68 |
} |
69 |
else
|
70 |
{ |
71 |
ub.setUstate (Constants.UID_STATE_TMP_LOCKED); |
72 |
ub.setUdateLockedFrom (fromDate); |
73 |
|
74 |
Calendar expiryDate = Calendar.getInstance (); |
75 |
expiryDate.setTime (fromDate); // set expiry date to fromDate
|
76 |
expiryDate.add (Calendar.MINUTE, +nMinutes);
|
77 |
ub.setUdateLockedTo (expiryDate.getTime ()); |
78 |
} |
79 |
|
80 |
ub.setUdateLastLocked (now); |
81 |
|
82 |
if (userDao.updateUserToStore (ub, null)) |
83 |
{ |
84 |
rc = Constants.ERR_SUCCESS; |
85 |
} |
86 |
else
|
87 |
{ |
88 |
rc = Constants.ERR_UNKNOWN; |
89 |
} |
90 |
} |
91 |
catch (Exception e) |
92 |
{ |
93 |
e.printStackTrace (); |
94 |
} |
95 |
return rc;
|
96 |
} |
97 |
} |