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