View Javadoc

1   /**
2    * Copyright 2011 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  
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   * This class retrieves Formats based on the course and returns a key-value pair list of
37   * the Activity Type name and the Activity Id
38   *
39   * @author andrewlubbers
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      // Get the first Format Offering Key from the database by using the search service to get all FOs for a CO and picking the first one.
80      // This will be used as the default value for the Format Offering dropdown in the Add Activity popover,
81      // and to determine the default value for the Activity Type and Cluster dropdowns to ensure there are no mismatches.
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 }