1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.acal.service.impl;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.criteria.Predicate;
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.LookupableImpl;
24 import org.kuali.rice.krad.web.form.LookupForm;
25 import org.kuali.student.r2.core.acal.dto.AcalEventInfo;
26 import org.kuali.student.r2.core.acal.service.AcademicCalendarService;
27 import org.kuali.student.r2.common.dto.ContextInfo;
28 import javax.xml.namespace.QName;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32
33 import static org.kuali.rice.core.api.criteria.PredicateFactory.and;
34 import static org.kuali.rice.core.api.criteria.PredicateFactory.like;
35
36
37
38
39
40
41
42 public class AcalEventInfoLookupableImpl extends LookupableImpl {
43 private AcademicCalendarService academicCalendarService;
44 ContextInfo contextInfo = new ContextInfo();
45
46 @Override
47 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
48 List<AcalEventInfo> results = new ArrayList<AcalEventInfo>();
49 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
50 List<Predicate> pList = new ArrayList<Predicate>();
51 Predicate p;
52
53 String name = fieldValues.get("name");
54
55 qBuilder.setPredicates();
56 if (StringUtils.isNotBlank(name)){
57 p = like("name", "%" + name + "%");
58 pList.add(p);
59 }
60
61 if (!pList.isEmpty()){
62 Predicate[] preds = new Predicate[pList.size()];
63 pList.toArray(preds);
64 qBuilder.setPredicates(and(preds));
65 }
66
67 try {
68 QueryByCriteria query = qBuilder.build();
69
70 academicCalendarService= getAcademicCalendarService();
71
72
73 List<AcalEventInfo> acalEventInfos = academicCalendarService.searchForAcalEvents(query, getContextInfo());
74 if (!acalEventInfos.isEmpty()){
75 results.addAll(acalEventInfos);
76 }
77 } catch (Exception e) {
78 e.printStackTrace();
79 throw new RuntimeException("Error Performing Search",e);
80 }
81 return results;
82 }
83
84 protected AcademicCalendarService getAcademicCalendarService() {
85 if(academicCalendarService == null) {
86 academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/acal", "AcademicCalendarService"));
87 }
88 return academicCalendarService;
89 }
90
91 public ContextInfo getContextInfo() {
92 if (contextInfo == null){
93 contextInfo = org.kuali.student.enrollment.common.util.ContextBuilder.loadContextInfo();
94 }
95 return contextInfo;
96 }
97 }