1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.courseoffering.keyvalue;
17
18 import org.kuali.rice.core.api.util.ConcreteKeyValue;
19 import org.kuali.rice.core.api.util.KeyValue;
20 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
21 import org.kuali.rice.krad.uif.view.ViewModel;
22 import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingManagementForm;
23 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingManagementUtil;
24 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
25 import org.kuali.student.r2.core.class1.search.ActivityOfferingSearchServiceImpl;
26 import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
27 import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
28 import org.kuali.student.r2.core.search.dto.SearchResultInfo;
29 import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
30
31 import java.io.Serializable;
32 import java.util.ArrayList;
33 import java.util.List;
34
35
36
37
38
39
40
41
42 public class FormatsForCreateAOKeyValues extends UifKeyValuesFinderBase implements Serializable {
43
44 @Override
45 public List<KeyValue> getKeyValues(ViewModel model) {
46 CourseOfferingManagementForm coForm = (CourseOfferingManagementForm) model;
47
48 List<KeyValue> keyValues = new ArrayList<KeyValue>();
49 CourseOfferingInfo selectedCourseOffering = coForm.getCurrentCourseOfferingWrapper().getCourseOfferingInfo();
50
51 try {
52 SearchRequestInfo sr = new SearchRequestInfo(ActivityOfferingSearchServiceImpl.FO_BY_CO_ID_SEARCH_KEY);
53 sr.addParam(ActivityOfferingSearchServiceImpl.SearchParameters.CO_ID, selectedCourseOffering.getId());
54
55 SearchResultInfo results = CourseOfferingManagementUtil.getSearchService().search(sr, null);
56
57 for(SearchResultRowInfo row:results.getRows()){
58 String foId = null;
59 String foName = null;
60
61
62 for(SearchResultCellInfo cell:row.getCells()){
63 if(ActivityOfferingSearchServiceImpl.SearchResultColumns.FO_ID.equals(cell.getKey())){
64 foId = cell.getValue();
65 }else if(ActivityOfferingSearchServiceImpl.SearchResultColumns.FO_NAME.equals(cell.getKey())){
66 foName = cell.getValue();
67 }
68 }
69 keyValues.add(new ConcreteKeyValue(foId, foName));
70
71 }
72
73 } catch (Exception e) {
74 throw new RuntimeException(e);
75 }
76 return keyValues;
77 }
78
79
80
81
82 public String getFirstKey(ViewModel model){
83 CourseOfferingManagementForm coForm = (CourseOfferingManagementForm) model;
84 String foId = null;
85 CourseOfferingInfo selectedCourseOffering = coForm.getCurrentCourseOfferingWrapper().getCourseOfferingInfo();
86 try {
87 SearchRequestInfo sr = new SearchRequestInfo(ActivityOfferingSearchServiceImpl.FO_BY_CO_ID_SEARCH_KEY);
88 sr.addParam(ActivityOfferingSearchServiceImpl.SearchParameters.CO_ID, selectedCourseOffering.getId());
89
90 SearchResultInfo results = CourseOfferingManagementUtil.getSearchService().search(sr, null);
91
92 for(SearchResultCellInfo cell:results.getRows().get(0).getCells()){
93 if(ActivityOfferingSearchServiceImpl.SearchResultColumns.FO_ID.equals(cell.getKey())){
94 foId = cell.getValue();
95 }
96 }
97
98 } catch (Exception e) {
99 throw new RuntimeException(e);
100 }
101 return foId;
102 }
103
104
105
106
107
108
109 }