Coverage Report - org.kuali.rice.kns.bo.options.AbstractCountryValuesFinderBase
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractCountryValuesFinderBase
0%
0/11
0%
0/4
1.667
AbstractCountryValuesFinderBase$1
0%
0/4
N/A
1.667
 
 1  
 /*
 2  
  * Copyright 2007-2009 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kns.bo.options;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.Comparator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.commons.lang.StringUtils;
 24  
 import org.kuali.rice.core.util.KeyLabelPair;
 25  
 import org.kuali.rice.kns.bo.Country;
 26  
 import org.kuali.rice.kns.lookup.keyvalues.KeyValuesBase;
 27  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 28  
 
 29  
 /**
 30  
  * This is a description of what this class does - wliang don't forget to fill this in. 
 31  
  * 
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public abstract class AbstractCountryValuesFinderBase extends KeyValuesBase {
 36  
         /**
 37  
          * Returns a list of countries that will be added to the result of {@link #getKeyValues()}.  Note that the result may
 38  
          * be filtered by active status
 39  
          * 
 40  
          * @return
 41  
          */
 42  
         protected abstract List<Country> retrieveCountriesForValuesFinder();
 43  
         
 44  
     public List<KeyLabelPair> getKeyValues() {
 45  0
                 List<Country> boList = retrieveCountriesForValuesFinder();
 46  0
                 final Country defaultCountry = KNSServiceLocator.getCountryService().getDefaultCountry();
 47  0
                 List<KeyLabelPair> labels = new ArrayList<KeyLabelPair>( boList.size() + 1 );
 48  
                 
 49  0
         labels.add(new KeyLabelPair("", ""));
 50  0
                labels.add(new KeyLabelPair(defaultCountry.getPostalCountryCode(), defaultCountry.getPostalCountryName()));
 51  
                 
 52  0
         Collections.sort(boList, new Comparator<Country>() {
 53  
                         public int compare(Country o1, Country o2) {
 54  
                                 // some institutions may prefix the country name with an asterisk if the country no longer exists
 55  
                                 // the country names will be compared without the asterisk
 56  0
                                 String sortValue1 = StringUtils.trim(StringUtils.removeStart(o1.getPostalCountryName(), "*"));
 57  0
                                 String sortValue2 = StringUtils.trim(StringUtils.removeStart(o2.getPostalCountryName(), "*"));
 58  0
                                 return sortValue1.compareToIgnoreCase(sortValue2);
 59  
                         }
 60  
                 
 61  
         });
 62  
         
 63  
         // the default country may show up twice, but that's fine
 64  0
         for (Country country : boList) {
 65  0
                 if (country.isActive()) {
 66  0
                         labels.add(new KeyLabelPair(country.getPostalCountryCode(), country.getPostalCountryName()));
 67  
                 }
 68  
         }
 69  0
         return labels;
 70  
     }
 71  
 }