View Javadoc

1   package org.kuali.rice.student.lookup.keyvalues;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import javax.xml.namespace.QName;
7   
8   import org.kuali.rice.core.resourceloader.GlobalResourceLoader;
9   import org.kuali.rice.core.util.KeyLabelPair;
10  import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase;
11  import org.kuali.student.common.search.dto.SearchRequest;
12  import org.kuali.student.common.search.dto.SearchResult;
13  import org.kuali.student.common.search.dto.SearchResultCell;
14  import org.kuali.student.common.search.dto.SearchResultRow;
15  import org.kuali.student.core.organization.service.OrganizationService;
16  
17  public class DepartmentValuesFinder extends KeyValuesBase {
18  	private static OrganizationService organizationService;
19  
20  	protected static OrganizationService getOrganizationService() {
21  		if (organizationService == null) {
22  			organizationService = (OrganizationService) GlobalResourceLoader
23  					.getService(new QName(
24  							"http://student.kuali.org/wsdl/organization",
25  							"OrganizationService"));
26  		}
27  		return organizationService;
28  	}
29  
30  	@Override
31  	public List getKeyValues() {
32  		List<KeyLabelPair> orgEntities = new ArrayList<KeyLabelPair>();
33  
34  		SearchRequest searchRequest = new SearchRequest("org.search.generic");
35  		List<String> orgTypes = new ArrayList<String>();
36  		orgTypes.add("kuali.org.Department");
37  		orgTypes.add("kuali.org.College");
38  		orgTypes.add("kuali.org.Division");
39  		orgTypes.add("kuali.org.Office");
40  		orgTypes.add("kuali.org.School");
41  		searchRequest.addParam("org.queryParam.orgOptionalType", orgTypes);
42  		searchRequest.setSortColumn("org.resultColumn.orgOptionalLongName");
43  		try {
44  			SearchResult results = getOrganizationService().search(searchRequest);
45  
46  			for (SearchResultRow result : results.getRows()) {
47  				String orgId = null;
48  				String orgLongName = null;
49  				for (SearchResultCell resultCell : result.getCells()) {
50  					if ("org.resultColumn.orgId".equals(resultCell.getKey())) {
51  						orgId = resultCell.getValue();
52  					} else if ("org.resultColumn.orgOptionalLongName".equals(resultCell.getKey())) {
53  						orgLongName = resultCell.getValue();
54  					}					
55  				}
56  	            orgEntities.add(new KeyLabelPair(orgId, orgLongName));
57  			}
58  
59  			return orgEntities;
60  		} catch (Exception e) {
61  			throw new RuntimeException(e);
62  		}
63  	}
64  }