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