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/25/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.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   * This class provides a key value finder for credit options
41   *
42   * @author Kuali Student Team
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  }