| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RemoteOrganizationValuesFinder |
|
| 4.666666666666667;4.667 |
| 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.common.search.dto.SearchRequest; | |
| 15 | import org.kuali.student.common.search.dto.SearchResultCell; | |
| 16 | import org.kuali.student.common.search.dto.SearchResultRow; | |
| 17 | import org.kuali.student.core.organization.service.OrganizationService; | |
| 18 | ||
| 19 | 0 | public class RemoteOrganizationValuesFinder extends KeyValuesBase { |
| 20 | ||
| 21 | 0 | private static final Logger LOG = Logger.getLogger(RemoteOrganizationValuesFinder.class); |
| 22 | ||
| 23 | private OrganizationService organizationService; | |
| 24 | ||
| 25 | @Override | |
| 26 | public List<KeyValue> getKeyValues() { | |
| 27 | 0 | List<KeyValue> departments = new ArrayList<KeyValue>(); |
| 28 | ||
| 29 | 0 | SearchRequest searchRequest = new SearchRequest(); |
| 30 | 0 | searchRequest.setSearchKey("org.search.generic"); |
| 31 | ||
| 32 | try { | |
| 33 | 0 | for (SearchResultRow result : getOrganizationService().search(searchRequest).getRows()) { |
| 34 | 0 | String orgId = ""; |
| 35 | 0 | String orgShortName = ""; |
| 36 | 0 | String orgOptionalLongName = ""; |
| 37 | 0 | String orgType = ""; |
| 38 | 0 | for (SearchResultCell resultCell : result.getCells()) { |
| 39 | 0 | if ("org.resultColumn.orgId".equals(resultCell.getKey())) { |
| 40 | 0 | orgId = resultCell.getValue(); |
| 41 | 0 | } else if ("org.resultColumn.orgShortName".equals(resultCell.getKey())) { |
| 42 | 0 | orgShortName = resultCell.getValue(); |
| 43 | 0 | } else if ("org.resultColumn.orgOptionalLongName".equals(resultCell.getKey())) { |
| 44 | 0 | orgOptionalLongName = resultCell.getValue(); |
| 45 | 0 | } else if ("org.resultColumn.orgType".equals(resultCell.getKey())) { |
| 46 | 0 | orgType = resultCell.getValue(); |
| 47 | } | |
| 48 | } | |
| 49 | 0 | departments.add(buildKeyValue(orgId, orgShortName, orgOptionalLongName, orgType)); |
| 50 | 0 | } |
| 51 | ||
| 52 | 0 | } catch (Exception e) { |
| 53 | 0 | LOG.error("Error building KeyValues List", e); |
| 54 | // swallow exception for now, in case we want to run without ks up | |
| 55 | // throw new RuntimeException(e); | |
| 56 | 0 | } |
| 57 | ||
| 58 | 0 | return departments; |
| 59 | } | |
| 60 | ||
| 61 | protected OrganizationService getOrganizationService() { | |
| 62 | 0 | if (organizationService == null) { |
| 63 | 0 | organizationService = (OrganizationService) GlobalResourceLoader |
| 64 | .getService(new QName("http://student.kuali.org/wsdl/organization","OrganizationService")); | |
| 65 | } | |
| 66 | 0 | return organizationService; |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * Builds a valid {@link KeyValue} object for use in Student system KeyValue classes. Will throw an {@link IllegalArgumentException} | |
| 71 | * if the parameters needed are not passed. | |
| 72 | * | |
| 73 | * @param orgId | |
| 74 | * @param orgShortName | |
| 75 | * @param orgLongName | |
| 76 | * @param orgType | |
| 77 | * @return | |
| 78 | */ | |
| 79 | protected KeyValue buildKeyValue(String orgId, String orgShortName, String orgLongName, String orgType) { | |
| 80 | 0 | if (StringUtils.isBlank(orgShortName)) { |
| 81 | 0 | throw new IllegalArgumentException("Blank value for orgShortName is invalid."); |
| 82 | } | |
| 83 | ||
| 84 | 0 | return new ConcreteKeyValue(orgId, (StringUtils.isNotBlank(orgLongName) ? orgLongName : orgShortName) ); |
| 85 | } | |
| 86 | ||
| 87 | } |