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.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.MaintenanceForm;
25  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
26  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
27  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
28  import org.kuali.student.mock.utilities.TestHelper;
29  import org.kuali.student.r2.common.dto.ContextInfo;
30  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
31  import org.kuali.student.r2.lum.course.dto.CourseInfo;
32  import org.kuali.student.r2.lum.course.dto.FormatInfo;
33  import org.kuali.student.r2.lum.course.service.CourseService;
34  import org.kuali.student.r2.lum.util.constants.CourseServiceConstants;
35  
36  import javax.xml.namespace.QName;
37  import java.io.Serializable;
38  import java.util.ArrayList;
39  import java.util.List;
40  
41  public class CourseOfferingIdFormatKeyValues extends UifKeyValuesFinderBase implements Serializable {
42  
43      private static final long serialVersionUID = 1L;
44  
45      private transient CourseOfferingService courseOfferingService;
46      private transient CourseService courseService;
47  
48      @Override
49      public List<KeyValue> getKeyValues(ViewModel model) {
50  
51          List<KeyValue> keyValues = new ArrayList<KeyValue>();
52  
53          MaintenanceForm form1 = (MaintenanceForm)model;
54          FormatOfferingInfo form = (FormatOfferingInfo)form1.getDocument().getDocumentDataObject();
55  
56          ContextInfo context = TestHelper.getContext1();
57          String courseOfferingId = form.getCourseOfferingId();
58  
59          if (courseOfferingId != null) {
60              List<FormatInfo> formats;
61              try {
62                  CourseOfferingInfo courseOfferingInfo = getCourseOfferingService().getCourseOffering(courseOfferingId, context);
63                  CourseInfo courseInfo = getCourseService().getCourse(courseOfferingInfo.getCourseId(), context);
64                  formats = courseInfo.getFormats();
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 looking up subject areas", e);
69              }
70  
71              for(FormatInfo format : formats) {
72                  keyValues.add(new ConcreteKeyValue(format.getId(), format.getType()));
73              }
74          }
75  
76          return keyValues;
77      }
78  
79      protected CourseOfferingService getCourseOfferingService() {
80          if(courseOfferingService == null) {
81              courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOffering", "CourseOfferingService"));
82          }
83          return this.courseOfferingService;
84      }
85  
86      protected CourseService getCourseService() {
87          if(courseService == null) {
88              courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService"));
89          }
90          return this.courseService;
91      }
92  }