1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
17
18 import org.apache.commons.lang.StringUtils;
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.krad.lookup.LookupableImpl;
23 import org.kuali.rice.krad.web.form.LookupForm;
24 import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
25 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
26 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
27 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
28 import org.kuali.student.r2.common.util.ContextUtils;
29
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37
38
39 public class ActivityOfferingLookupableImpl extends LookupableImpl {
40
41 @Override
42 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
43 List<ActivityOfferingInfo> activityOfferingInfos = new ArrayList<ActivityOfferingInfo>();
44
45 try {
46 if(hasCriteria(fieldValues)){
47 QueryByCriteria qbc = buildQueryByCriteria(fieldValues);
48 activityOfferingInfos = getCourseOfferingService().searchForActivityOfferings(qbc, ContextUtils.createDefaultContextInfo());
49 }
50 } catch (Exception e) {
51 throw new RuntimeException(e);
52 }
53
54 return activityOfferingInfos;
55 }
56
57 private QueryByCriteria buildQueryByCriteria(Map<String, String> fieldValues){
58 String aoId = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID);
59
60 List<Predicate> predicates = new ArrayList<Predicate>();
61 if (StringUtils.isNotBlank(aoId)) {
62 predicates.add(PredicateFactory.equalIgnoreCase("id", aoId));
63 }
64
65 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
66 qbcBuilder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
67 QueryByCriteria qbc = qbcBuilder.build();
68
69 return qbc;
70 }
71
72 private boolean hasCriteria(Map<String, String> fieldValues){
73 return StringUtils.isNotBlank(fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID));
74 }
75
76 public CourseOfferingService getCourseOfferingService() {
77 return CourseOfferingResourceLoader.loadCourseOfferingService();
78 }
79 }