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