1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
17
18 import org.kuali.rice.core.api.util.ConcreteKeyValue;
19 import org.kuali.rice.core.api.util.KeyValue;
20 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
21 import org.kuali.rice.krad.uif.view.ViewModel;
22 import org.kuali.rice.krad.util.GlobalVariables;
23 import org.kuali.rice.krad.web.form.InquiryForm;
24 import org.kuali.rice.krad.web.form.MaintenanceForm;
25 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingCreateWrapper;
26 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
27 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingConstants;
28 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
29 import org.kuali.student.enrollment.class2.courseoffering.util.ViewHelperUtil;
30 import org.kuali.student.r2.lum.course.dto.CourseInfo;
31 import org.kuali.student.r2.common.dto.ContextInfo;
32 import org.kuali.student.r2.common.dto.LocaleInfo;
33 import org.kuali.student.r2.common.util.constants.LuiServiceConstants;
34 import org.kuali.student.r2.core.class1.type.service.TypeService;
35
36 import java.io.Serializable;
37 import java.util.ArrayList;
38 import java.util.Collections;
39 import java.util.List;
40 import java.util.Locale;
41
42
43
44
45
46
47 public class GradeRosterLevelKeyValues extends UifKeyValuesFinderBase implements Serializable {
48
49 public static TypeService typeService;
50
51 @Override
52 public List<KeyValue> getKeyValues(ViewModel model) {
53 Object dataObject = null;
54 if (model instanceof MaintenanceForm) {
55 MaintenanceForm form = (MaintenanceForm)model;
56 dataObject = form.getDocument().getNewMaintainableObject().getDataObject();
57 } else if (model instanceof InquiryForm) {
58 InquiryForm form = (InquiryForm)model;
59 dataObject = form.getDataObject();
60 }
61
62 CourseInfo course;
63
64 if(dataObject instanceof CourseOfferingCreateWrapper) {
65 CourseOfferingCreateWrapper cWrapper = (CourseOfferingCreateWrapper) dataObject;
66 course = cWrapper.getCourse();
67 }
68 else if (dataObject instanceof CourseOfferingEditWrapper) {
69 CourseOfferingEditWrapper cWrapper = (CourseOfferingEditWrapper) dataObject;
70 course = cWrapper.getCourse();
71 }
72 else {
73 return Collections.emptyList();
74 }
75
76 List<KeyValue> results = new ArrayList<KeyValue>();
77
78
79 results.add(new ConcreteKeyValue(LuiServiceConstants.COURSE_OFFERING_TYPE_KEY, CourseOfferingConstants.FORMAT_OFFERING_GRADE_ROSTER_LEVEL_COURSE_DISPLAY));
80
81 ContextInfo contextInfo = getContextInfo();
82
83 results.addAll(ViewHelperUtil.collectActivityTypeKeyValues(course, getTypeService(), contextInfo));
84
85 return results;
86 }
87
88
89
90 private static TypeService getTypeService() {
91 if(typeService == null) {
92 typeService = CourseOfferingResourceLoader.loadTypeService();
93 }
94
95 return typeService;
96 }
97
98 public ContextInfo getContextInfo() {
99 ContextInfo contextInfo = new ContextInfo();
100 contextInfo.setAuthenticatedPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
101 contextInfo.setPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
102 LocaleInfo localeInfo = new LocaleInfo();
103 localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
104 localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
105 contextInfo.setLocale(localeInfo);
106 return contextInfo;
107 }
108
109 }