1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.group;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.criteria.Predicate;
20 import org.kuali.rice.core.api.criteria.PredicateUtils;
21 import org.kuali.rice.core.api.criteria.QueryByCriteria;
22 import org.kuali.rice.kim.api.KimConstants;
23 import org.kuali.rice.kim.api.group.Group;
24 import org.kuali.rice.kim.api.group.GroupQueryResults;
25 import org.kuali.rice.kim.api.group.GroupService;
26 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27 import org.kuali.rice.kim.impl.role.RoleBo;
28 import org.kuali.rice.kim.impl.role.RoleDao;
29 import org.kuali.rice.kim.impl.services.KimImplServiceLocator;
30 import org.kuali.rice.krad.lookup.LookupableImpl;
31 import org.kuali.rice.krad.util.KRADConstants;
32 import org.kuali.rice.krad.web.form.LookupForm;
33
34 import java.sql.Timestamp;
35 import java.util.ArrayList;
36 import java.util.Calendar;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
42 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
43 import static org.kuali.rice.core.api.criteria.PredicateFactory.lessThan;
44
45
46
47
48
49
50 public class GroupLookupableImpl extends LookupableImpl {
51 private static final long serialVersionUID = -3149952849854425077L;
52
53
54
55
56
57
58
59 @Override
60 protected List<?> getSearchResults(LookupForm form, Map<String, String> searchCriteria, boolean unbounded) {
61 Map<String, String> criteriaMap = new HashMap<String, String>(searchCriteria);
62 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
63
64 if (!criteriaMap.isEmpty()) {
65 List<Predicate> predicates = new ArrayList<Predicate>();
66
67 if (StringUtils.isNotBlank(criteriaMap.get(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME))) {
68 String principalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(
69 criteriaMap.get(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME)).getPrincipalId();
70 Timestamp currentTime = new Timestamp(Calendar.getInstance().getTimeInMillis());
71 predicates.add(and(equal("members.memberId", principalId), equal("members.typeCode",
72 KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode()), and(or(isNull(
73 "members.activeFromDateValue"), greaterThanOrEqual("members.activeFromDateValue", currentTime)),
74 or(isNull("members.activeToDateValue"), lessThan("members.activeToDateValue", currentTime)))));
75
76 }
77 criteriaMap.remove(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME);
78
79 predicates.add(PredicateUtils.convertMapToPredicate(criteriaMap));
80 criteria.setPredicates(and(predicates.toArray(new Predicate[predicates.size()])));
81 }
82
83 GroupQueryResults groupResults = getGroupService().findGroups(criteria.build());
84 List<Group> groups = groupResults.getResults();
85
86
87 List<GroupBo> groupBos = new ArrayList<GroupBo>(groups.size());
88 for (Group group : groups) {
89 groupBos.add(GroupBo.from(group));
90 }
91
92 return groupBos;
93 }
94
95 public GroupService getGroupService() {
96 return KimApiServiceLocator.getGroupService();
97 }
98 }