1 package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
2
3 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
4 import org.kuali.rice.core.api.util.ConcreteKeyValue;
5 import org.kuali.rice.core.api.util.KeyValue;
6 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
7 import org.kuali.rice.krad.uif.view.ViewModel;
8 import org.kuali.student.enrollment.class2.courseoffering.form.RegistrationGroupManagementForm;
9 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
10 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
11 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
12 import org.kuali.student.r2.common.dto.ContextInfo;
13 import org.kuali.student.r2.common.util.ContextUtils;
14 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
15
16 import javax.xml.namespace.QName;
17 import java.io.Serializable;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 public class FormatsForCreateRGKeyValues extends UifKeyValuesFinderBase implements Serializable {
22 private transient CourseOfferingService courseOfferingService;
23 private static final long serialVersionUID = 1L;
24 @Override
25 public List<KeyValue> getKeyValues(ViewModel model) {
26 RegistrationGroupManagementForm rgForm = (RegistrationGroupManagementForm) model;
27
28 List<KeyValue> keyValues = new ArrayList<KeyValue>();
29 CourseOfferingInfo selectedCourseOffering = rgForm.getTheCourseOffering();
30
31 try {
32 String courseOfferingId = selectedCourseOffering.getId();
33 ContextInfo contextInfo = ContextUtils.createDefaultContextInfo();
34 List<FormatOfferingInfo> formatOfferingInfos =
35 getCourseOfferingService().getFormatOfferingsByCourseOffering(courseOfferingId, contextInfo);
36 for (FormatOfferingInfo formatOfferingInfo : formatOfferingInfos) {
37
38 keyValues.add(new ConcreteKeyValue(formatOfferingInfo.getId(), formatOfferingInfo.getName()));
39 }
40 } catch (Exception e) {
41 throw new RuntimeException("Error getting Formats for course offering", e);
42 }
43 return keyValues;
44 }
45
46 protected CourseOfferingService getCourseOfferingService() {
47 if (courseOfferingService == null) {
48 courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName(CourseOfferingServiceConstants.NAMESPACE, "CourseOfferingService"));
49 }
50 return courseOfferingService;
51 }
52 }
53