1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.common.kitchensink;
18
19 import org.kuali.rice.core.api.criteria.Predicate;
20 import org.kuali.rice.core.api.criteria.PredicateFactory;
21 import org.kuali.rice.core.api.criteria.QueryByCriteria;
22 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
23 import org.kuali.rice.krad.lookup.LookupForm;
24 import org.kuali.rice.krad.lookup.LookupableImpl;
25 import org.kuali.student.common.util.security.ContextUtils;
26 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
27 import org.kuali.student.r2.core.population.dto.PopulationInfo;
28 import org.kuali.student.r2.core.population.service.PopulationService;
29
30 import javax.xml.namespace.QName;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40 public class KitchenSinkPopulationInfoLookupableImpl extends LookupableImpl {
41
42 private transient PopulationService populationService;
43
44 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
45
46 String keyword = fieldValues.get("keyword");
47 keyword = keyword.isEmpty() ? "*" : keyword;
48 List<Predicate> predicates = new ArrayList<Predicate>();
49 predicates.add(PredicateFactory.or(PredicateFactory.like("name", "%" + keyword + "%"),
50 PredicateFactory.like("descrPlain", "%" + keyword + "%")));
51 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
52 qbcBuilder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
53 QueryByCriteria qbc = qbcBuilder.build();
54
55
56 List<PopulationInfo> populationInfoList;
57 try {
58 populationInfoList =
59 getPopulationService().searchForPopulations(qbc, ContextUtils.createDefaultContextInfo());
60 }
61 catch (Exception e) {
62 throw new RuntimeException(e);
63 }
64
65 return populationInfoList;
66 }
67
68
69 private PopulationService getPopulationService() {
70 if (populationService == null) {
71 populationService = (PopulationService)GlobalResourceLoader
72 .getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationService"));
73 }
74 return populationService;
75 }
76
77
78
79
80
81
82
83
84
85 @Override
86 public boolean allowsMaintenanceNewOrCopyAction() {
87
88 return false;
89 }
90
91
92
93
94
95
96
97 @Override
98 public boolean allowsMaintenanceDeleteAction(Object dataObject) {
99
100 return false;
101 }
102 }