View Javadoc

1   /**
2    * Copyright 2010 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.rice.student.lookup.keyvalues;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.rice.core.util.KeyLabelPair;
22  import org.kuali.student.common.search.dto.SearchRequest;
23  import org.kuali.student.common.search.dto.SearchResultCell;
24  import org.kuali.student.common.search.dto.SearchResultRow;
25  
26  public class AllOrgsValuesFinder extends StudentKeyValuesBase {
27  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AllOrgsValuesFinder.class);
28  
29  	public List<KeyLabelPair> getKeyValues() {
30          List<KeyLabelPair> departments = new ArrayList<KeyLabelPair>();
31  
32          SearchRequest searchRequest = new SearchRequest();
33          searchRequest.setSearchKey("org.search.generic");
34  
35          try {
36              for (SearchResultRow result : getOrganizationService().search(searchRequest).getRows()) {
37                  String orgId = "";
38                  String orgShortName = "";
39                  String orgOptionalLongName = "";
40                  String orgType = "";
41                  for (SearchResultCell resultCell : result.getCells()) {
42                      if ("org.resultColumn.orgId".equals(resultCell.getKey())) {
43                          orgId = resultCell.getValue();
44                      } else if ("org.resultColumn.orgShortName".equals(resultCell.getKey())) {
45                          orgShortName = resultCell.getValue();
46                      } else if ("org.resultColumn.orgOptionalLongName".equals(resultCell.getKey())) {
47                      	orgOptionalLongName = resultCell.getValue();
48                      } else if ("org.resultColumn.orgType".equals(resultCell.getKey())) {
49                      	orgType = resultCell.getValue();
50                      }
51                  }
52                  departments.add(buildKeyLabelPair(orgId, orgShortName, orgOptionalLongName, orgType));
53              }
54  
55              return departments;
56          } catch (Exception e) {
57          	LOG.error("Error building KeyValues List", e);
58              throw new RuntimeException(e);
59          }
60      }
61  
62  }