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 java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import javax.xml.namespace.QName;
24  
25  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26  import org.kuali.rice.core.api.util.ConcreteKeyValue;
27  import org.kuali.rice.core.api.util.KeyValue;
28  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
29  import org.kuali.rice.krad.uif.view.ViewModel;
30  import org.kuali.rice.krad.web.form.MaintenanceForm;
31  import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
32  import org.kuali.student.r2.lum.course.dto.CourseInfo;
33  import org.kuali.student.r2.lum.course.dto.FormatInfo;
34  import org.kuali.student.r2.lum.course.service.CourseService;
35  import org.kuali.student.r2.lum.util.constants.CourseServiceConstants;
36  import org.kuali.student.mock.utilities.TestHelper;
37  import org.kuali.student.r2.common.exceptions.DoesNotExistException;
38  import org.kuali.student.r2.common.exceptions.InvalidParameterException;
39  import org.kuali.student.r2.common.exceptions.MissingParameterException;
40  import org.kuali.student.r2.common.exceptions.OperationFailedException;
41  import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
42  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
43  import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
44  import org.kuali.student.r2.common.dto.ContextInfo;
45  
46  public class CourseOfferingIdFormatKeyValues extends UifKeyValuesFinderBase implements Serializable {
47  
48      private static final long serialVersionUID = 1L;
49  
50      private CourseOfferingService courseOfferingService;
51      private CourseService courseService;
52  
53      @Override
54      public List<KeyValue> getKeyValues(ViewModel model) {
55  
56          List<FormatInfo> formats = new ArrayList<FormatInfo>();
57          List<KeyValue> keyValues = new ArrayList<KeyValue>();
58  
59          MaintenanceForm form1 = (MaintenanceForm)model;
60          FormatOfferingInfo form = (FormatOfferingInfo)form1.getDocument().getDocumentDataObject();
61  
62          ContextInfo context = TestHelper.getContext1();
63          String courseOfferingId = form.getCourseOfferingId();
64  
65          if (courseOfferingId != null) {
66              try {
67                  CourseOfferingInfo courseOfferingInfo = (CourseOfferingInfo) getCourseOfferingService().getCourseOffering(courseOfferingId, context);
68                  CourseInfo courseInfo = (CourseInfo) getCourseService().getCourse(courseOfferingInfo.getCourseId(), context);
69                  formats = courseInfo.getFormats();
70              } catch (DoesNotExistException e) {
71                  throw new RuntimeException("No subject areas found! There should be some in the database", e);
72              } catch (InvalidParameterException e) {
73                  throw new RuntimeException(e);
74              } catch (MissingParameterException e) {
75                  throw new RuntimeException(e);
76              } catch (OperationFailedException e) {
77                  throw new RuntimeException(e);
78              } catch (PermissionDeniedException e) {
79                  throw new RuntimeException(e);
80              }
81  
82              for(FormatInfo format : formats) {
83                  keyValues.add(new ConcreteKeyValue(format.getId(), format.getType()));
84              }
85          }
86  
87          return keyValues;
88      }
89  
90      protected CourseOfferingService getCourseOfferingService() {
91          if(courseOfferingService == null) {
92              courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOffering", "CourseOfferingService"));
93          }
94          return this.courseOfferingService;
95      }
96  
97      protected CourseService getCourseService() {
98          if(courseService == null) {
99              courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService"));
100         }
101         return this.courseService;
102     }
103 }