View Javadoc

1   /**
2    * Copyright 2012 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   * Created by vgadiyak on 6/2/12
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.InquiryForm;
25  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
26  import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
27  import org.kuali.student.r2.common.dto.ContextInfo;
28  import org.kuali.student.r2.common.util.ContextUtils;
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.lrc.service.LRCService;
32  import org.kuali.student.r2.lum.util.constants.CourseServiceConstants;
33  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
34  
35  import javax.xml.namespace.QName;
36  import java.io.Serializable;
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  //import org.kuali.student.r2.lum.lrc.service.LRCService;
41  
42  /**
43   * This class provides a key value finder for student registration options
44   *
45   * @author Kuali Student Team
46   */
47  public class StudentRegistrationOptionsKeyValues extends UifKeyValuesFinderBase implements Serializable {
48  
49      private static final long serialVersionUID = 1L;
50  
51      private transient CourseService courseService;
52      private transient LRCService lrcService;
53  
54      @Override
55      public List<KeyValue> getKeyValues(ViewModel model) {
56  
57          List<KeyValue> keyValues = new ArrayList<KeyValue>();
58  
59          CourseOfferingEditWrapper form = null;
60          if (model instanceof MaintenanceDocumentForm) {
61              MaintenanceDocumentForm form1 = (MaintenanceDocumentForm)model;
62              form = (CourseOfferingEditWrapper)form1.getDocument().getDocumentDataObject();
63          } else if (model instanceof InquiryForm) {
64              InquiryForm form1 = (InquiryForm)model;
65              form = (CourseOfferingEditWrapper)form1.getDataObject();
66          }
67  
68          if (form != null && form.getStudentRegOptions() != null) {
69              ResultValuesGroupInfo rvg;
70              try {
71                  ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
72                  for(String studentGradingOption : form.getStudentRegOptions()) {
73                      rvg = getLrcService().getResultValuesGroup(studentGradingOption, contextInfo);
74                      if (null != rvg) {
75                          keyValues.add(new ConcreteKeyValue(studentGradingOption, rvg.getName()));
76                      }
77                      else {
78                          keyValues.add(new ConcreteKeyValue(studentGradingOption, studentGradingOption));
79                      }
80                  }
81              }
82              catch (Exception e) {
83                  throw new RuntimeException("Error getting student registration options", e);
84              }
85          }
86  
87          return keyValues;
88      }
89  
90      protected CourseService getCourseService() {
91          if(courseService == null) {
92              courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService"));
93          }
94          return this.courseService;
95      }
96  
97      protected LRCService getLrcService() {
98          if(lrcService == null) {
99              lrcService = (LRCService) GlobalResourceLoader.getService(new QName(LrcServiceConstants.NAMESPACE, LrcServiceConstants.SERVICE_NAME_LOCAL_PART));
100         }
101         return this.lrcService;
102     }
103 
104 }