View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
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   * Build key-value pairs for the Grade Roster Level dropdown when creating Format Offerings
44   *
45   * @author andrewlubbers
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          // Always include an option for Course
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 }