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