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.KeyValue;
19  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
20  import org.kuali.rice.krad.uif.view.ViewModel;
21  import org.kuali.rice.krad.web.form.InquiryForm;
22  import org.kuali.rice.krad.web.form.MaintenanceForm;
23  import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingCreateWrapper;
24  import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
25  import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
26  import org.kuali.student.enrollment.class2.courseoffering.util.ViewHelperUtil;
27  import org.kuali.student.r2.common.util.ContextUtils;
28  import org.kuali.student.r2.core.class1.type.service.TypeService;
29  import org.kuali.student.r2.lum.course.dto.CourseInfo;
30  
31  import java.io.Serializable;
32  import java.util.ArrayList;
33  import java.util.Collections;
34  import java.util.List;
35  
36  /**
37   * Build key-value pairs for the Final Exam Driver dropdown when creating Format Offerings
38   *
39   * @author andrewlubbers
40   */
41  public class FinalExamDriverKeyValues extends UifKeyValuesFinderBase implements Serializable {
42  
43      private static TypeService typeService;
44  
45      @Override
46      public List<KeyValue> getKeyValues(ViewModel model) {
47          Object dataObject = null;
48          if (model instanceof MaintenanceForm) {
49              MaintenanceForm form = (MaintenanceForm)model;
50              dataObject = form.getDocument().getNewMaintainableObject().getDataObject();
51          } else if (model instanceof InquiryForm) {
52              InquiryForm form = (InquiryForm)model;
53              dataObject = form.getDataObject();
54          }
55  
56          CourseInfo course;
57  
58          if(dataObject instanceof CourseOfferingCreateWrapper) {
59              CourseOfferingCreateWrapper cWrapper = (CourseOfferingCreateWrapper) dataObject;
60              course = cWrapper.getCourse();
61          }
62          else if (dataObject instanceof CourseOfferingEditWrapper) {
63              CourseOfferingEditWrapper cWrapper = (CourseOfferingEditWrapper) dataObject;
64              course = cWrapper.getCourse();
65          }
66          else {
67              return Collections.emptyList();
68          }
69  
70          List<KeyValue> results = new ArrayList<KeyValue>();
71  
72          results.addAll(ViewHelperUtil.collectActivityTypeKeyValues(course, getTypeService(), ContextUtils.createDefaultContextInfo()));
73  
74          return results;
75      }
76  
77      private static TypeService getTypeService() {
78          if(typeService == null) {
79              typeService = CourseOfferingResourceLoader.loadTypeService();
80          }
81  
82          return typeService;
83      }
84  
85  }