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.apache.commons.lang.StringUtils;
22  import org.kuali.rice.core.api.util.ConcreteKeyValue;
23  import org.kuali.rice.core.api.util.KeyValue;
24  import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
25  import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
26  import org.kuali.student.r2.core.search.dto.SearchResultInfo;
27  import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
28  import org.kuali.student.common.util.security.ContextUtils;
29  
30  public abstract class CocValuesFinder extends StudentKeyValuesBase {
31  
32  	/**
33  	 * Find the curriculum committee Orgs with specified orgType.
34  	 * Each org should have a kuali.org.CurriculumParent relationship with
35  	 * an org with kuali.org.COC type.
36  	 * 
37  	 * @param orgType
38  	 * @return
39  	 */
40  	public static List<KeyValue> findCocOrgs(String orgType) {
41  		List<KeyValue> orgEntities = new ArrayList<KeyValue>();
42  
43  		SearchRequestInfo searchRequest = new SearchRequestInfo("org.search.orgQuickViewByRelationTypeOrgTypeRelatedOrgType");
44  		searchRequest.addParam("org.queryParam.relationType","kuali.org.CurriculumParent");
45  		searchRequest.addParam("org.queryParam.orgType",orgType);
46  		searchRequest.addParam("org.queryParam.relatedOrgType","kuali.org.COC");
47  
48  		try {
49  			SearchResultInfo results = null;
50  			results = getOrganizationService().search(searchRequest, ContextUtils.getContextInfo());
51  			for (SearchResultRowInfo result : results.getRows()) {
52  				String orgId = "";
53  				String orgShortName = "";
54  				String orgLongName = "";
55  				for (SearchResultCellInfo resultCell : result.getCells()) {
56  					if ("org.resultColumn.orgId".equals(resultCell.getKey())) {
57  						orgId = resultCell.getValue();
58  					} else if ("org.resultColumn.orgShortName".equals(resultCell.getKey())) {
59  						orgShortName = resultCell.getValue();
60  					} else if("org.resultColumn.orgLongName".equals(resultCell.getKey())){
61  						orgLongName = resultCell.getValue();
62  					}
63  				}
64  		        if (StringUtils.isBlank(orgLongName)) {
65  		           //use shortName when longName is blank
66  		            orgEntities.add(buildKeyLabelPair(orgId, orgShortName, null, null));
67  		        }
68  		        else {
69  		            /*
70  		             * The requirement is that in the RICE portal, when we add a principal to a role
71  		             * the drop-down list for DepartmentCoC or DivisionCoC should display the full/long 
72  		             * names instead of short names.
73  		             */
74  		            orgEntities.add(new ConcreteKeyValue(orgId, orgLongName));
75  		        }
76  			}
77  
78  			return orgEntities;
79  		} catch (Exception e) {
80  			throw new RuntimeException(e);
81  		}
82  	}
83  }