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 5/23/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.util.CourseOfferingManagementUtil;
25  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
26  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
27  import org.kuali.student.mock.utilities.TestHelper;
28  import org.kuali.student.r2.common.dto.ContextInfo;
29  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
30  import org.kuali.student.r2.lum.course.dto.CourseInfo;
31  import org.kuali.student.r2.lum.course.dto.FormatInfo;
32  
33  import javax.xml.namespace.QName;
34  import java.io.Serializable;
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  public class CourseOfferingIdFormatKeyValues extends UifKeyValuesFinderBase implements Serializable {
39  
40      private static final long serialVersionUID = 1L;
41  
42      @Override
43      public List<KeyValue> getKeyValues(ViewModel model) {
44  
45          List<KeyValue> keyValues = new ArrayList<KeyValue>();
46  
47          MaintenanceDocumentForm form1 = (MaintenanceDocumentForm)model;
48          FormatOfferingInfo form = (FormatOfferingInfo)form1.getDocument().getDocumentDataObject();
49  
50          ContextInfo context = TestHelper.getContext1();
51          String courseOfferingId = form.getCourseOfferingId();
52  
53          if (courseOfferingId != null) {
54              List<FormatInfo> formats;
55              try {
56                  CourseOfferingInfo courseOfferingInfo = CourseOfferingManagementUtil.getCourseOfferingService().getCourseOffering(courseOfferingId, context);
57                  CourseInfo courseInfo = CourseOfferingManagementUtil.getCourseService().getCourse(courseOfferingInfo.getCourseId(), context);
58                  formats = courseInfo.getFormats();
59              } catch (DoesNotExistException e) {
60                  throw new RuntimeException("No subject areas found! There should be some in the database", e);
61              } catch (Exception e) {
62                  throw new RuntimeException("Error looking up subject areas", e);
63              }
64  
65              for(FormatInfo format : formats) {
66                  keyValues.add(new ConcreteKeyValue(format.getId(), format.getTypeKey()));
67              }
68          }
69  
70          return keyValues;
71      }
72  }