1 package org.kuali.student.lum.bo.options;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.xml.namespace.QName;
7
8 import org.apache.commons.lang.StringUtils;
9 import org.apache.log4j.Logger;
10 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
11 import org.kuali.rice.core.api.util.ConcreteKeyValue;
12 import org.kuali.rice.core.api.util.KeyValue;
13 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
14 import org.kuali.student.r1.common.search.dto.SearchRequest;
15 import org.kuali.student.r1.common.search.dto.SearchResult;
16 import org.kuali.student.r1.common.search.dto.SearchResultCell;
17 import org.kuali.student.r1.common.search.dto.SearchResultRow;
18 import org.kuali.student.r2.core.organization.service.OrganizationService;
19
20 public class RemoteOrganizationValuesFinder extends KeyValuesBase {
21
22 private static final Logger LOG = Logger.getLogger(RemoteOrganizationValuesFinder.class);
23
24 private OrganizationService organizationService;
25
26 @Override
27 public List<KeyValue> getKeyValues() {
28 List<KeyValue> departments = new ArrayList<KeyValue>();
29
30 SearchRequest searchRequest = new SearchRequest();
31 searchRequest.setSearchKey("org.search.generic");
32
33 try {
34 SearchResult results = getOrganizationService().search(searchRequest);
35 for (SearchResultRow result : results.getRows()) {
36 String orgId = "";
37 String orgShortName = "";
38 String orgOptionalLongName = "";
39 String orgType = "";
40 for (SearchResultCell resultCell : result.getCells()) {
41 if ("org.resultColumn.orgId".equals(resultCell.getKey())) {
42 orgId = resultCell.getValue();
43 } else if ("org.resultColumn.orgShortName".equals(resultCell.getKey())) {
44 orgShortName = resultCell.getValue();
45 } else if ("org.resultColumn.orgOptionalLongName".equals(resultCell.getKey())) {
46 orgOptionalLongName = resultCell.getValue();
47 } else if ("org.resultColumn.orgType".equals(resultCell.getKey())) {
48 orgType = resultCell.getValue();
49 }
50 }
51 departments.add(buildKeyValue(orgId, orgShortName, orgOptionalLongName, orgType));
52 }
53
54 } catch (Exception e) {
55 LOG.error("Error building KeyValues List", e);
56
57
58 }
59
60 return departments;
61 }
62
63 protected OrganizationService getOrganizationService() {
64 if (organizationService == null) {
65 organizationService = (OrganizationService)
66 GlobalResourceLoader
67 .getService(new QName("http://student.kuali.org/wsdl/organization", "OrganizationService"));
68 }
69 return organizationService;
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83 protected KeyValue buildKeyValue(String orgId, String orgShortName, String orgLongName, String orgType) {
84 if (StringUtils.isBlank(orgShortName)) {
85 throw new IllegalArgumentException("Blank value for orgShortName is invalid.");
86 }
87
88 return new ConcreteKeyValue(orgId, (StringUtils.isNotBlank(orgLongName) ? orgLongName : orgShortName) );
89 }
90 }