1 package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
2
3 import org.kuali.rice.core.api.util.ConcreteKeyValue;
4 import org.kuali.rice.core.api.util.KeyValue;
5 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
6 import org.kuali.rice.krad.uif.view.ViewModel;
7 import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingManagementForm;
8 import org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingManagementViewHelperServiceImpl;
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
14 import java.io.Serializable;
15 import java.util.ArrayList;
16 import java.util.List;
17
18 public class FormatsForCreateRGKeyValues extends UifKeyValuesFinderBase implements Serializable {
19
20 @Override
21 public List<KeyValue> getKeyValues(ViewModel model) {
22 CourseOfferingManagementForm coForm = (CourseOfferingManagementForm) model;
23 CourseOfferingManagementViewHelperServiceImpl helperService = ((CourseOfferingManagementViewHelperServiceImpl)coForm.getView().getViewHelperService());
24
25 List<KeyValue> keyValues = new ArrayList<KeyValue>();
26 CourseOfferingInfo selectedCourseOffering = coForm.getTheCourseOffering();
27
28 try {
29 String courseOfferingId = selectedCourseOffering.getId();
30 ContextInfo contextInfo = helperService.getContextInfo();
31 CourseOfferingService courseOfferingService = helperService.getCourseOfferingService();
32 List<FormatOfferingInfo> formatOfferingInfos =
33 courseOfferingService.getFormatOfferingsByCourseOffering(courseOfferingId, contextInfo);
34 for (FormatOfferingInfo formatOfferingInfo : formatOfferingInfos) {
35
36 keyValues.add(new ConcreteKeyValue(formatOfferingInfo.getId(), formatOfferingInfo.getName()));
37 }
38 } catch (Exception e) {
39 throw new RuntimeException();
40 }
41 return keyValues;
42 }
43 }
44