1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
18
19 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20 import org.kuali.rice.core.api.util.ConcreteKeyValue;
21 import org.kuali.rice.core.api.util.KeyValue;
22 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
23 import org.kuali.rice.krad.uif.view.ViewModel;
24 import org.kuali.rice.krad.web.form.MaintenanceForm;
25 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
26 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
27 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
28 import org.kuali.student.mock.utilities.TestHelper;
29 import org.kuali.student.r2.common.dto.ContextInfo;
30 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
31 import org.kuali.student.r2.lum.course.dto.CourseInfo;
32 import org.kuali.student.r2.lum.course.dto.FormatInfo;
33 import org.kuali.student.r2.lum.course.service.CourseService;
34 import org.kuali.student.r2.lum.util.constants.CourseServiceConstants;
35
36 import javax.xml.namespace.QName;
37 import java.io.Serializable;
38 import java.util.ArrayList;
39 import java.util.List;
40
41 public class CourseOfferingIdFormatKeyValues extends UifKeyValuesFinderBase implements Serializable {
42
43 private static final long serialVersionUID = 1L;
44
45 private transient CourseOfferingService courseOfferingService;
46 private transient CourseService courseService;
47
48 @Override
49 public List<KeyValue> getKeyValues(ViewModel model) {
50
51 List<KeyValue> keyValues = new ArrayList<KeyValue>();
52
53 MaintenanceForm form1 = (MaintenanceForm)model;
54 FormatOfferingInfo form = (FormatOfferingInfo)form1.getDocument().getDocumentDataObject();
55
56 ContextInfo context = TestHelper.getContext1();
57 String courseOfferingId = form.getCourseOfferingId();
58
59 if (courseOfferingId != null) {
60 List<FormatInfo> formats;
61 try {
62 CourseOfferingInfo courseOfferingInfo = getCourseOfferingService().getCourseOffering(courseOfferingId, context);
63 CourseInfo courseInfo = getCourseService().getCourse(courseOfferingInfo.getCourseId(), context);
64 formats = courseInfo.getFormats();
65 } catch (DoesNotExistException e) {
66 throw new RuntimeException("No subject areas found! There should be some in the database", e);
67 } catch (Exception e) {
68 throw new RuntimeException("Error looking up subject areas", e);
69 }
70
71 for(FormatInfo format : formats) {
72 keyValues.add(new ConcreteKeyValue(format.getId(), format.getType()));
73 }
74 }
75
76 return keyValues;
77 }
78
79 protected CourseOfferingService getCourseOfferingService() {
80 if(courseOfferingService == null) {
81 courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOffering", "CourseOfferingService"));
82 }
83 return this.courseOfferingService;
84 }
85
86 protected CourseService getCourseService() {
87 if(courseService == null) {
88 courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService"));
89 }
90 return this.courseService;
91 }
92 }