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.MaintenanceDocumentForm;
25 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
26 import org.kuali.student.r2.common.exceptions.DoesNotExistException;
27 import org.kuali.student.r2.common.util.ContextUtils;
28 import org.kuali.student.r2.lum.course.dto.CourseInfo;
29 import org.kuali.student.r2.lum.course.service.CourseService;
30 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
31 import org.kuali.student.r2.lum.util.constants.CourseServiceConstants;
32 import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
33
34 import javax.xml.namespace.QName;
35 import java.io.Serializable;
36 import java.util.ArrayList;
37 import java.util.List;
38
39
40
41
42
43
44 public class CreditOptionsKeyValues extends UifKeyValuesFinderBase implements Serializable {
45
46 private static final long serialVersionUID = 1L;
47
48 private transient CourseService courseService;
49
50 @Override
51 public List<KeyValue> getKeyValues(ViewModel model) {
52
53 List<KeyValue> keyValues = new ArrayList<KeyValue>();
54
55 MaintenanceDocumentForm form1 = (MaintenanceDocumentForm)model;
56 CourseOfferingEditWrapper form = (CourseOfferingEditWrapper)form1.getDocument().getDocumentDataObject();
57
58 String courseId = form.getCourseOfferingInfo().getCourseId();
59 List<ResultValuesGroupInfo> creditOptions;
60
61 if (courseId != null) {
62 try {
63 CourseInfo courseInfo = getCourseService().getCourse(courseId, ContextUtils.getContextInfo());
64 creditOptions = courseInfo.getCreditOptions();
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 finding subject Areas", e);
69 }
70
71 for (ResultValuesGroupInfo rVGI : creditOptions) {
72 String typeKey = rVGI.getTypeKey();
73 if(typeKey.equals(LrcServiceConstants.R1_RESULT_COMPONENT_TYPE_KEY_FIXED)||typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED)) {
74 keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, "Fixed"));
75 } else if (typeKey.equals(LrcServiceConstants.R1_RESULT_COMPONENT_TYPE_KEY_RANGE) || typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {
76 keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, "Fixed"));
77 keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE, "Variable"));
78 keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, "Multiple"));
79 } else if (typeKey.equals(LrcServiceConstants.R1_RESULT_COMPONENT_TYPE_KEY_MULTIPLE) || typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE)) {
80 keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, "Fixed"));
81 keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, "Multiple"));
82 } else {
83 keyValues.add(new ConcreteKeyValue(typeKey, "Unknown Type"));
84 }
85 }
86 }
87
88 return keyValues;
89 }
90
91 protected CourseService getCourseService() {
92 if(courseService == null) {
93 courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService"));
94 }
95 return this.courseService;
96 }
97 }