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.SearchParam;
23  import org.kuali.student.common.search.dto.SearchRequest;
24  import org.kuali.student.common.search.dto.SearchResult;
25  import org.kuali.student.common.search.dto.SearchResultCell;
26  import org.kuali.student.common.search.dto.SearchResultRow;
27  
28  public class OrgCocValuesFinder extends StudentKeyValuesBase {
29  	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AllOrgsValuesFinder.class);
30  
31  	public static List<KeyLabelPair> findCocOrgs() {
32          List<KeyLabelPair> departments = new ArrayList<KeyLabelPair>();
33  
34          List<String> types = new ArrayList<String>();
35          types.add("kuali.org.College");
36          types.add("kuali.org.Department");
37          types.add("kuali.org.Division");
38          
39          List<SearchParam> queryParamValues = new ArrayList<SearchParam>(2);
40          SearchParam qpOrgType = new SearchParam();
41          qpOrgType.setKey("org.queryParam.relationType");
42          qpOrgType.setValue("kuali.org.CurriculumChild");
43          queryParamValues.add(qpOrgType);
44          
45          qpOrgType = new SearchParam();
46          qpOrgType.setKey("org.queryParam.orgTypeList");
47          qpOrgType.setValue(types);
48          queryParamValues.add(qpOrgType);
49          
50          qpOrgType = new SearchParam();
51          qpOrgType.setKey("org.queryParam.relatedOrgType");
52          qpOrgType.setValue("kuali.org.COC");
53          queryParamValues.add(qpOrgType);
54  
55          SearchRequest searchRequest = new SearchRequest();
56          searchRequest.setSearchKey("org.search.orgQuickViewByRelationTypeOrgTypeRelatedOrgTypeAltr");
57          searchRequest.setParams(queryParamValues);
58          
59          try {
60              SearchResult results = getOrganizationService().search(searchRequest);
61  
62              for (SearchResultRow result : results.getRows()) {
63                  String orgId = "";
64                  String orgShortName = "";
65                  for (SearchResultCell resultCell : result.getCells()) {
66                      if ("org.resultColumn.orgId".equals(resultCell
67                              .getKey())) {
68                          orgId = resultCell.getValue();
69                      } else if ("org.resultColumn.orgShortName"
70                              .equals(resultCell.getKey())) {
71                          orgShortName = resultCell.getValue();
72                      }
73                  }
74                  departments.add(buildKeyLabelPair(orgId, orgShortName, null, null));
75              }
76  
77              return departments;
78          } catch (Exception e) {
79          	LOG.error("Error building KeyValues List", e);
80              throw new RuntimeException(e);
81          }
82      }
83  
84      @Override
85      public List getKeyValues() {
86  
87          return findCocOrgs();
88      }
89  
90  }