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