Revision 51:ae80384d4b76
src/main/java/my/com/upass/MinimalUPassControllerV2.java | ||
---|---|---|
1 | 1 |
package my.com.upass; |
2 | 2 |
|
3 |
import java.util.Date; |
|
3 | 4 |
import java.util.HashMap; |
4 | 5 |
import java.util.Iterator; |
5 | 6 |
import java.util.List; |
... | ... | |
631 | 632 |
} |
632 | 633 |
} |
633 | 634 |
|
635 |
public List/* <UserProfile> */listProfilesByExamples( |
|
636 |
String appAccessId, String hashedSecretKey, |
|
637 |
List/* <UserProfile> */exampleProfiles, Date fromDate, Date toDate, Session txSession) |
|
638 |
throws UPassException { |
|
639 |
|
|
640 |
try { |
|
641 |
AccessCheckResult checkResult = checkAppAccess(appAccessId, hashedSecretKey, txSession); |
|
642 |
final boolean upassAdmin = checkResult.hasUPassAdminAccess(); |
|
643 |
if (!upassAdmin) { |
|
644 |
if (checkResult.invokerAppId == null) |
|
645 |
throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED); |
|
646 |
} |
|
647 |
List profiles = modifyUserService.listProfilesByExamples(exampleProfiles, fromDate, toDate, txSession); |
|
648 |
|
|
649 |
return profiles; |
|
650 |
|
|
651 |
} catch (MultipleAppAccessesFound e) { |
|
652 |
throw new UPassException(MinimalConstants.ERR_APP_SERV_NOT_PERMITTED, e); |
|
653 |
} |
|
654 |
} |
|
655 |
|
|
634 | 656 |
public static MaybankLdapDAO getMaybankLdapDAO() { |
635 | 657 |
synchronized (CONFIG_LOCK) { |
636 | 658 |
if (maybankLdapDAO == null) { |
src/main/java/my/com/upass/dao/UserDAO.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
package my.com.upass.dao; |
13 | 13 |
|
14 |
import java.util.Date; |
|
14 | 15 |
import java.util.List; |
15 | 16 |
|
16 | 17 |
import my.com.upass.maybank.entities.UserProfile; |
... | ... | |
85 | 86 |
List/* <UserProfile> */listProfilesByExamples( |
86 | 87 |
List/* <UserProfile> */exampleProfiles, final Session txSession) |
87 | 88 |
throws Exception; |
89 |
|
|
90 |
List/* <UserProfile> */listProfilesByExamples( |
|
91 |
List/* <UserProfile> */exampleProfiles, Date fromDate, Date toDate, final Session txSession) |
|
92 |
throws Exception; |
|
88 | 93 |
|
89 | 94 |
} |
src/main/java/my/com/upass/dao/hibernate/UserDAOHibernate.java | ||
---|---|---|
12 | 12 |
package my.com.upass.dao.hibernate; |
13 | 13 |
|
14 | 14 |
import java.util.ArrayList; |
15 |
import java.util.Calendar; |
|
16 |
import java.util.Date; |
|
17 |
import java.util.GregorianCalendar; |
|
15 | 18 |
import java.util.Iterator; |
16 | 19 |
import java.util.List; |
17 | 20 |
|
... | ... | |
494 | 497 |
|
495 | 498 |
for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) { |
496 | 499 |
UserProfile example = (UserProfile) iter.next(); |
497 |
|
|
500 |
|
|
498 | 501 |
Criteria c = session.createCriteria(example.getClass()) |
499 | 502 |
.add(Example.create(example).ignoreCase().enableLike()); |
500 | 503 |
|
... | ... | |
510 | 513 |
} |
511 | 514 |
c.add(Restrictions.ilike(MU + ".userAlias", username)); |
512 | 515 |
} |
516 |
|
|
517 |
profiles.addAll(c.list()); |
|
518 |
} |
|
519 |
} finally { |
|
520 |
if (txSession == null) |
|
521 |
closeSessionIfAny(session); |
|
522 |
} |
|
523 |
return profiles; |
|
524 |
} |
|
525 |
|
|
526 |
public List/* <UserProfile> */listProfilesByExamples( |
|
527 |
List/* <UserProfile> */exampleProfiles, Date fromDate, Date toDate, Session txSession) |
|
528 |
throws Exception { |
|
529 |
|
|
530 |
List profiles = new ArrayList(); |
|
531 |
Session session = null; |
|
532 |
try { |
|
533 |
session = txSession != null ? txSession : getSession(); |
|
534 |
|
|
535 |
for (Iterator iter = exampleProfiles.iterator(); iter.hasNext();) { |
|
536 |
UserProfile example = (UserProfile) iter.next(); |
|
537 |
|
|
538 |
Criteria c = session.createCriteria(example.getClass()) |
|
539 |
.add(Example.create(example).ignoreCase().enableLike()); |
|
540 |
|
|
541 |
final String MU = "mu"; |
|
542 |
if (example instanceof StockUser || example instanceof Im2uUser) { |
|
543 |
c.createAlias("m2uUser", "m2u"); |
|
544 |
c.createAlias("m2u.minUser", MU); |
|
545 |
|
|
546 |
} else { |
|
547 |
c.createAlias("minUser", MU); |
|
548 |
} |
|
549 |
|
|
550 |
final String username = example.getMinUser().getUsername(); |
|
551 |
if (username != null) { |
|
552 |
c.add(Restrictions.ilike(MU + ".userAlias", username)); |
|
553 |
} |
|
554 |
|
|
555 |
Integer userStatus = null; |
|
556 |
boolean userStatusSelected = true; |
|
557 |
try{ |
|
558 |
userStatus = Integer.valueOf(example.getMinUser().getUstate()); |
|
559 |
}catch (NumberFormatException e){ |
|
560 |
userStatusSelected = false; |
|
561 |
} |
|
562 |
if (userStatusSelected) { |
|
563 |
c.add(Restrictions.eq(MU + ".ustate", userStatus)); |
|
564 |
} |
|
565 |
|
|
566 |
Calendar calender = new GregorianCalendar(); |
|
567 |
if (fromDate != null) { |
|
568 |
calender.setTime(fromDate); |
|
569 |
calender.add(Calendar.DATE, -1); |
|
570 |
c.add(Restrictions.gt(MU + ".udateCreated", calender.getTime())); |
|
571 |
} |
|
572 |
else if (toDate != null){ |
|
573 |
calender.setTime(toDate); |
|
574 |
calender.add(Calendar.DATE, 1); |
|
575 |
c.add(Restrictions.lt(MU + ".udateCreated", calender.getTime())); |
|
576 |
} |
|
577 |
|
|
513 | 578 |
profiles.addAll(c.list()); |
514 | 579 |
} |
515 | 580 |
} finally { |
src/main/java/my/com/upass/services/ModifyUserService.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
package my.com.upass.services; |
13 | 13 |
|
14 |
import java.util.Date; |
|
14 | 15 |
import java.util.HashMap; |
15 | 16 |
import java.util.List; |
16 | 17 |
import java.util.Map; |
... | ... | |
198 | 199 |
} |
199 | 200 |
return null; |
200 | 201 |
} |
202 |
|
|
203 |
public List/* <UserProfile> */listProfilesByExamples( |
|
204 |
List/* <UserProfile> */exampleProfiles, Date fromDate, Date toDate, Session txSession) throws UPassException { |
|
205 |
|
|
206 |
// int rc = MinimalConstants.ERR_SYSTEM_NOT_READY; |
|
207 |
if (exampleProfiles == null) { |
|
208 |
throw new UPassException(MinimalConstants.ERR_INVALID_INPUT); |
|
209 |
} |
|
210 |
try { |
|
211 |
UserDAO userDao = MinimalDAOFactory.minimalInstance().getUserDAO(); |
|
212 |
return userDao.listProfilesByExamples(exampleProfiles, fromDate, toDate, txSession); |
|
213 |
|
|
214 |
} catch (Exception e) { |
|
215 |
if (e instanceof UPassException) { |
|
216 |
UPassException upassEx = (UPassException) e; |
|
217 |
throw upassEx; |
|
218 |
|
|
219 |
} else |
|
220 |
e.printStackTrace(); |
|
221 |
} |
|
222 |
return null; |
|
223 |
} |
|
201 | 224 |
|
202 | 225 |
} |
Also available in: Unified diff