001    package org.kuali.rice.student.lookup.keyvalues;
002    
003    import org.kuali.rice.core.api.util.ConcreteKeyValue;
004    import org.kuali.rice.core.api.util.KeyValue;
005    import org.kuali.student.r2.common.util.ContextUtils;
006    import org.kuali.student.r2.core.search.dto.SearchRequestInfo;
007    import org.kuali.student.r2.core.search.dto.SearchResultCellInfo;
008    import org.kuali.student.r2.core.search.dto.SearchResultInfo;
009    import org.kuali.student.r2.core.search.dto.SearchResultRowInfo;
010    import org.kuali.student.r2.core.search.dto.SortDirection;
011    
012    import java.util.ArrayList;
013    import java.util.List;
014    
015    /**
016     * Created with IntelliJ IDEA.
017     * User: Daniel
018     * Date: 2/25/13
019     * Time: 11:27 AM
020     * To change this template use File | Settings | File Templates.
021     */
022    public class SubjectAreaValuesFinder extends OrgsOfTypeValuesFinder{
023    
024        /**
025         * Find the Orgs with specified orgType.
026         *
027         * @param orgType
028         * @return
029         */
030        public static List<KeyValue> findOrgs(String orgType) {
031            List<KeyValue> orgEntities = new ArrayList<KeyValue>();
032            SearchRequestInfo searchRequest = new SearchRequestInfo("org.search.generic");
033            searchRequest.addParam("org.queryParam.orgOptionalType",orgType);
034            searchRequest.setSortColumn("org.resultColumn.orgOptionalLongName");
035            searchRequest.setSortDirection(SortDirection.ASC);
036            try {
037                SearchResultInfo results = getOrganizationService().search(searchRequest, ContextUtils.getContextInfo());
038    
039                for (SearchResultRowInfo result : results.getRows()) {
040                    String orgShortName = "";
041                    for (SearchResultCellInfo resultCell : result.getCells()) {
042                        if ("org.resultColumn.orgShortName".equals(resultCell.getKey())) {
043                            orgShortName = resultCell.getValue();
044                        }
045                    }
046                    orgEntities.add(new ConcreteKeyValue(orgShortName, orgShortName));
047                }
048                return orgEntities;
049            } catch (Exception e) {
050                throw new RuntimeException(e);
051            }
052        }
053    
054        @Override
055        public List<KeyValue> getKeyValues() {
056            return findOrgs("kuali.org.SubjectCode");
057        }
058    }
059