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.PredicateFactory;
20 import org.kuali.rice.core.api.criteria.QueryByCriteria;
21 import org.kuali.rice.krad.lookup.LookupableImpl;
22 import org.kuali.rice.krad.web.form.LookupForm;
23 import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
24 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
25 import org.kuali.student.enrollment.class2.courseoffering.util.FormatOfferingConstants;
26 import org.kuali.student.common.util.ContextBuilder;
27 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
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.util.ContextUtils;
31
32 import java.util.ArrayList;
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36
37
38
39
40
41
42 public class FormatOfferingInfoLookupableImpl extends LookupableImpl {
43 private static final long serialVersionUID = 1L;
44 public final static String COURSE_OFFER_ID = "courseOfferingId";
45
46 private transient CourseOfferingService courseOfferingService;
47
48 @Override
49 protected List<?> getSearchResults(LookupForm lookupForm, Map<String, String> fieldValues, boolean unbounded) {
50 List<FormatOfferingInfo> formatOfferingInfos = null;
51
52 String typeKey = fieldValues.get(FormatOfferingConstants.FORMAT_OFFERING_TYPE_KEY);
53 String courseOfferingId = fieldValues.get(ActivityOfferingConstants.ACTIVITYOFFERING_COURSE_OFFERING_ID);
54 try {
55 if (StringUtils.isNotBlank(courseOfferingId)) {
56 formatOfferingInfos = getCourseOfferingService().getFormatOfferingsByCourseOffering(fieldValues.get(COURSE_OFFER_ID), ContextUtils.createDefaultContextInfo());
57 } else if (StringUtils.isNotBlank(typeKey)) {
58 formatOfferingInfos = getSearchResultsByType (typeKey);
59 }
60 } catch (Exception e) {
61 throw new RuntimeException("Error getting FormatOfferingInfo.", e);
62 }
63
64 return formatOfferingInfos;
65 }
66
67 public CourseOfferingService getCourseOfferingService() {
68 if(courseOfferingService == null)
69 courseOfferingService= CourseOfferingResourceLoader.loadCourseOfferingService();
70 return courseOfferingService;
71 }
72
73 public ContextInfo getContextInfo() {
74 ContextInfo contextInfo = new ContextInfo();
75 if (contextInfo == null){
76 contextInfo = ContextBuilder.loadContextInfo();
77 }
78 return contextInfo;
79 }
80
81 public static int getLineNumber() {
82 return Thread.currentThread().getStackTrace()[2].getLineNumber();
83 }
84
85 private List<FormatOfferingInfo> getSearchResultsByType (String typeKey){
86 List<FormatOfferingInfo> formatOfferingInfos = null;
87 try {
88 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
89 qbcBuilder.setPredicates(PredicateFactory.and(
90 PredicateFactory.equalIgnoreCase(FormatOfferingConstants.FORMAT_OFFERING_LUI_TYPE, typeKey)));
91 QueryByCriteria criteria = qbcBuilder.build();
92
93 List<String> listFormatOfferingIDs = getCourseOfferingService().searchForFormatOfferingIds(criteria, getContextInfo());
94 if (listFormatOfferingIDs != null) {
95 String formatOfferingID = null;
96 formatOfferingInfos = new ArrayList<FormatOfferingInfo>();
97 for(Iterator i = listFormatOfferingIDs.iterator(); i.hasNext();){
98 formatOfferingID = (String) i.next();
99 formatOfferingInfos.add ((FormatOfferingInfo) getCourseOfferingService().getFormatOffering(formatOfferingID, getContextInfo()));
100 }
101 }
102 } catch (Exception e) {
103 throw new RuntimeException("Error getting FormatOfferingInfo.getSearchResultsByType.errorLineNumber=" + getLineNumber(), e);
104 }
105 return formatOfferingInfos;
106 }
107 }