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.common.util.ContextBuilder;
27 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
28 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
29 import org.kuali.student.r2.common.dto.ContextInfo;
30
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40 public class ActivityOfferingLookupableImpl extends LookupableImpl {
41
42 @Override
43 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
44 List<ActivityOfferingInfo> activityOfferingInfos = new ArrayList<ActivityOfferingInfo>();
45
46 try {
47 if(hasCriteria(fieldValues)){
48 QueryByCriteria qbc = buildQueryByCriteria(fieldValues);
49 activityOfferingInfos = getCourseOfferingService().searchForActivityOfferings(qbc, getContextInfo());
50 }
51 } catch (Exception e) {
52 throw new RuntimeException(e);
53 }
54
55 return activityOfferingInfos;
56 }
57
58 private QueryByCriteria buildQueryByCriteria(Map<String, String> fieldValues){
59 String aoId = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID);
60
61 List<Predicate> predicates = new ArrayList<Predicate>();
62 if (StringUtils.isNotBlank(aoId)) {
63 predicates.add(PredicateFactory.equalIgnoreCase("id", aoId));
64 }
65
66 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
67 qbcBuilder.setPredicates(predicates.toArray(new Predicate[predicates.size()]));
68 QueryByCriteria qbc = qbcBuilder.build();
69
70 return qbc;
71 }
72
73 private boolean hasCriteria(Map<String, String> fieldValues){
74 return StringUtils.isNotBlank(fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_ID));
75 }
76
77 public CourseOfferingService getCourseOfferingService() {
78 return CourseOfferingResourceLoader.loadCourseOfferingService();
79 }
80
81 public ContextInfo getContextInfo() {
82 return ContextBuilder.loadContextInfo();
83 }
84 }