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.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 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.and; |
36 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.like; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class StudentGroupWrapperLookupableImpl extends LookupableImpl { |
44 | |
private transient PopulationService populationService; |
45 | |
@Override |
46 | |
protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) { |
47 | 0 | List<StudentGroupWrapper> results = new ArrayList<StudentGroupWrapper>(); |
48 | 0 | ContextInfo context = new ContextInfo(); |
49 | |
|
50 | 0 | QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create(); |
51 | 0 | List<Predicate> pList = new ArrayList<Predicate>(); |
52 | 0 | qBuilder.setPredicates(); |
53 | |
|
54 | 0 | for(String key : fieldValues.keySet()){ |
55 | 0 | if(key.equalsIgnoreCase("name")){ |
56 | 0 | Predicate grpName = like(key,fieldValues.get(key)); |
57 | 0 | pList.add(grpName); |
58 | 0 | } else{ |
59 | 0 | Predicate words = like(key,fieldValues.get(key)); |
60 | 0 | pList.add(words); |
61 | 0 | } |
62 | |
} |
63 | 0 | if (!pList.isEmpty()){ |
64 | 0 | Predicate[] preds = new Predicate[pList.size()]; |
65 | 0 | pList.toArray(preds); |
66 | 0 | qBuilder.setPredicates(and(preds)); |
67 | |
} |
68 | |
|
69 | |
try { |
70 | |
|
71 | 0 | java.util.List<PopulationInfo> populationInfos = getPopulationService().searchForPopulations(qBuilder.build(), context); |
72 | 0 | if(!populationInfos.isEmpty()){ |
73 | 0 | for(PopulationInfo populationInfo:populationInfos){ |
74 | 0 | StudentGroupWrapper studentGroupWrapper = new StudentGroupWrapper(); |
75 | 0 | studentGroupWrapper.setId(populationInfo.getId()); |
76 | 0 | studentGroupWrapper.setName(populationInfo.getName()); |
77 | 0 | studentGroupWrapper.setDescription(populationInfo.getDescr().getPlain()); |
78 | 0 | results.add(studentGroupWrapper); |
79 | 0 | } |
80 | |
} |
81 | 0 | } catch (Exception e) { |
82 | 0 | throw new RuntimeException("Error Performing Search",e); |
83 | 0 | } |
84 | 0 | return results; |
85 | |
} |
86 | |
|
87 | |
protected PopulationService getPopulationService() { |
88 | |
|
89 | 0 | if(populationService == null) { |
90 | 0 | populationService = (PopulationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX+"population", "PopulationService")); |
91 | |
|
92 | |
} |
93 | 0 | return populationService; |
94 | |
} |
95 | |
|
96 | |
public static void main(String[] args){ |
97 | 0 | StudentGroupWrapperLookupableImpl studentWrapper = new StudentGroupWrapperLookupableImpl(); |
98 | 0 | studentWrapper.getPopulationService(); |
99 | |
|
100 | 0 | } |
101 | |
} |