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.krad.lookup.LookupableImpl;
28 import org.kuali.rice.krad.lookup.LookupForm;
29
30 import java.sql.Timestamp;
31 import java.util.ArrayList;
32 import java.util.Calendar;
33 import java.util.Collection;
34 import java.util.HashMap;
35 import java.util.List;
36 import java.util.Map;
37
38 import static org.kuali.rice.core.api.criteria.PredicateFactory.*;
39 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
40 import static org.kuali.rice.core.api.criteria.PredicateFactory.lessThan;
41
42
43
44
45
46
47 public class GroupLookupableImpl extends LookupableImpl {
48 private static final long serialVersionUID = -3149952849854425077L;
49
50
51
52
53
54
55
56 @Override
57 protected Collection<?> executeSearch(Map<String, String> adjustedSearchCriteria,
58 List<String> wildcardAsLiteralSearchCriteria, boolean bounded, Integer searchResultsLimit) {
59 Map<String, String> criteriaMap = new HashMap<String, String>(adjustedSearchCriteria);
60 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
61
62 if (!criteriaMap.isEmpty()) {
63 List<Predicate> predicates = new ArrayList<Predicate>();
64
65 if (StringUtils.isNotBlank(criteriaMap.get(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME))) {
66 String principalId = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(
67 criteriaMap.get(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME)).getPrincipalId();
68 Timestamp currentTime = new Timestamp(Calendar.getInstance().getTimeInMillis());
69 predicates.add(and(equal("members.memberId", principalId), equal("members.typeCode",
70 KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode()), and(or(isNull(
71 "members.activeFromDateValue"), greaterThanOrEqual("members.activeFromDateValue", currentTime)),
72 or(isNull("members.activeToDateValue"), lessThan("members.activeToDateValue", currentTime)))));
73
74 }
75 criteriaMap.remove(KimConstants.UniqueKeyConstants.PRINCIPAL_NAME);
76
77 predicates.add(PredicateUtils.convertMapToPredicate(criteriaMap));
78 criteria.setPredicates(and(predicates.toArray(new Predicate[predicates.size()])));
79 }
80
81 GroupQueryResults groupResults = getGroupService().findGroups(criteria.build());
82 List<Group> groups = groupResults.getResults();
83
84
85 List<GroupBo> groupBos = new ArrayList<GroupBo>(groups.size());
86 for (Group group : groups) {
87 groupBos.add(GroupBo.from(group));
88 }
89
90 return groupBos;
91 }
92
93 public GroupService getGroupService() {
94 return KimApiServiceLocator.getGroupService();
95 }
96 }