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.util.ConcreteKeyValue;
20  import org.kuali.rice.core.api.util.KeyValue;
21  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
22  import org.kuali.rice.krad.uif.view.ViewModel;
23  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
24  import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
25  import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
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.lrc.dto.ResultValuesGroupInfo;
30  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
31  
32  import javax.xml.namespace.QName;
33  import java.io.Serializable;
34  import java.util.ArrayList;
35  import java.util.List;
36  
37  /**
38   * This class provides a key value finder for credit options
39   *
40   * @author Kuali Student Team
41   */
42  public class CreditOptionsKeyValues extends UifKeyValuesFinderBase implements Serializable {
43  
44      private static final long serialVersionUID = 1L;
45  
46      @Override
47      public List<KeyValue> getKeyValues(ViewModel model) {
48  
49          List<KeyValue> keyValues = new ArrayList<KeyValue>();
50  
51          MaintenanceDocumentForm form1 = (MaintenanceDocumentForm)model;
52          CourseOfferingEditWrapper form = (CourseOfferingEditWrapper)form1.getDocument().getDocumentDataObject();
53  
54          String courseId = form.getCourseOfferingInfo().getCourseId();
55          List<ResultValuesGroupInfo> creditOptions;
56  
57          if (courseId != null) {
58              try {
59                  CourseInfo courseInfo = CourseOfferingManagementUtil.getCourseService().getCourse(courseId, ContextUtils.getContextInfo());
60                  creditOptions = courseInfo.getCreditOptions();
61              } catch (DoesNotExistException e) {
62                  throw new RuntimeException("No subject areas found! There should be some in the database", e);
63              } catch (Exception e) {
64                  throw new RuntimeException("Error finding subject Areas", e);
65              }
66  
67              for (ResultValuesGroupInfo rVGI : creditOptions) {
68                  String typeKey =  rVGI.getTypeKey();
69                  if(typeKey.equals(LrcServiceConstants.R1_RESULT_COMPONENT_TYPE_KEY_FIXED)||typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED)) {
70                      keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, "Fixed"));
71                  } else if (typeKey.equals(LrcServiceConstants.R1_RESULT_COMPONENT_TYPE_KEY_RANGE) || typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE)) {
72                      keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, "Fixed"));
73                      keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_RANGE, "Variable"));
74                      keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, "Multiple"));
75                  } else if (typeKey.equals(LrcServiceConstants.R1_RESULT_COMPONENT_TYPE_KEY_MULTIPLE) || typeKey.equals(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE)) {
76                      keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED, "Fixed"));
77                      keyValues.add(new ConcreteKeyValue(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE, "Multiple"));
78                  } else {
79                      keyValues.add(new ConcreteKeyValue(typeKey, "Unknown Type"));
80                  }
81              }
82          }
83  
84          return keyValues;
85      }
86  }