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.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
22 import org.kuali.rice.krad.uif.view.ViewModel;
23 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
24 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
25 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
26 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
27 import org.kuali.student.mock.utilities.TestHelper;
28 import org.kuali.student.r2.common.dto.ContextInfo;
29 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
30 import org.kuali.student.r2.lum.course.dto.CourseInfo;
31 import org.kuali.student.r2.lum.course.dto.FormatInfo;
32
33 import javax.xml.namespace.QName;
34 import java.io.Serializable;
35 import java.util.ArrayList;
36 import java.util.List;
37
38 public class CourseOfferingIdFormatKeyValues extends UifKeyValuesFinderBase implements Serializable {
39
40 private static final long serialVersionUID = 1L;
41
42 @Override
43 public List<KeyValue> getKeyValues(ViewModel model) {
44
45 List<KeyValue> keyValues = new ArrayList<KeyValue>();
46
47 MaintenanceDocumentForm form1 = (MaintenanceDocumentForm)model;
48 FormatOfferingInfo form = (FormatOfferingInfo)form1.getDocument().getDocumentDataObject();
49
50 ContextInfo context = TestHelper.getContext1();
51 String courseOfferingId = form.getCourseOfferingId();
52
53 if (courseOfferingId != null) {
54 List<FormatInfo> formats;
55 try {
56 CourseOfferingInfo courseOfferingInfo = CourseOfferingManagementUtil.getCourseOfferingService().getCourseOffering(courseOfferingId, context);
57 CourseInfo courseInfo = CourseOfferingManagementUtil.getCourseService().getCourse(courseOfferingInfo.getCourseId(), context);
58 formats = courseInfo.getFormats();
59 } catch (DoesNotExistException e) {
60 throw new RuntimeException("No subject areas found! There should be some in the database", e);
61 } catch (Exception e) {
62 throw new RuntimeException("Error looking up subject areas", e);
63 }
64
65 for(FormatInfo format : formats) {
66 keyValues.add(new ConcreteKeyValue(format.getId(), format.getTypeKey()));
67 }
68 }
69
70 return keyValues;
71 }
72 }