1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.appointment.service.impl;
18
19 import org.kuali.rice.core.api.criteria.Predicate;
20 import org.kuali.rice.core.api.criteria.QueryByCriteria;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.krad.lookup.LookupableImpl;
23 import org.kuali.rice.krad.web.form.LookupForm;
24 import org.kuali.student.enrollment.class2.appointment.dto.StudentGroupWrapper;
25 import org.kuali.student.r2.common.constants.CommonServiceConstants;
26 import org.kuali.student.r2.common.dto.ContextInfo;
27 import org.kuali.student.r2.core.constants.PopulationServiceConstants;
28 import org.kuali.student.r2.core.population.dto.PopulationInfo;
29 import org.kuali.student.r2.core.population.service.PopulationService;
30
31 import javax.xml.namespace.QName;
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Map;
35
36 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
37 import static org.kuali.rice.core.api.criteria.PredicateFactory.like;
38
39
40
41
42
43
44 public class StudentGroupWrapperLookupableImpl extends LookupableImpl {
45 private transient PopulationService populationService;
46 private static final long serialVersionUID = 1L;
47 @Override
48 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
49 List<StudentGroupWrapper> results = new ArrayList<StudentGroupWrapper>();
50 ContextInfo context = new ContextInfo();
51
52 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
53 List<Predicate> pList = new ArrayList<Predicate>();
54 qBuilder.setPredicates();
55
56 for(String key : fieldValues.keySet()){
57 Predicate words = like(key,fieldValues.get(key));
58 pList.add(words);
59 }
60 if (!pList.isEmpty()){
61 Predicate[] preds = new Predicate[pList.size()];
62 pList.toArray(preds);
63 qBuilder.setPredicates(and(preds));
64 }
65
66 try {
67
68 java.util.List<PopulationInfo> populationInfos = getPopulationService().searchForPopulations(qBuilder.build(), context);
69 for(PopulationInfo populationInfo:populationInfos){
70 StudentGroupWrapper studentGroupWrapper = new StudentGroupWrapper();
71 studentGroupWrapper.setId(populationInfo.getId());
72 studentGroupWrapper.setName(populationInfo.getName());
73 studentGroupWrapper.setDescription(populationInfo.getDescr().getPlain());
74 results.add(studentGroupWrapper);
75 }
76 } catch (Exception e) {
77 throw new RuntimeException("Error Performing Search", e);
78 }
79 return results;
80 }
81
82 protected PopulationService getPopulationService() {
83
84 if (populationService == null) {
85
86 populationService = (PopulationService) GlobalResourceLoader.getService(new QName(PopulationServiceConstants.NAMESPACE, "PopulationMockService"));
87
88 }
89 return populationService;
90 }
91
92 }