1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.location.framework.country;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.util.ConcreteKeyValue;
20 import org.kuali.rice.core.api.util.KeyValue;
21 import org.kuali.rice.krad.keyvalues.KeyValuesBase;
22 import org.kuali.rice.location.api.country.Country;
23 import org.kuali.rice.location.api.services.LocationApiServiceLocator;
24
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.Comparator;
28 import java.util.List;
29
30
31
32
33
34
35
36
37 public abstract class AbstractCountryValuesFinderBase extends KeyValuesBase {
38
39 @Override
40 public List<KeyValue> getKeyValues() {
41 Country defaultCountry = getDefaultCountry();
42 List<Country> countries = new ArrayList<Country>(retrieveCountriesForValuesFinder());
43
44 List<KeyValue> values = new ArrayList<KeyValue>(countries.size() + 1);
45 values.add(new ConcreteKeyValue("", ""));
46 if (defaultCountry != null) {
47 values.add(new ConcreteKeyValue(defaultCountry.getCode(), defaultCountry.getName()));
48 }
49
50 Collections.sort(countries, new Comparator<Country>() {
51 @Override
52 public int compare(Country country1, Country country2) {
53
54
55 String sortValue1 = StringUtils.trim(StringUtils.removeStart(country1.getName(), "*"));
56 String sortValue2 = StringUtils.trim(StringUtils.removeStart(country2.getName(), "*"));
57 return sortValue1.compareToIgnoreCase(sortValue2);
58 }
59
60 });
61
62
63 for (Country country : countries) {
64 if (country.isActive()) {
65 values.add(new ConcreteKeyValue(country.getCode(), country.getName()));
66 }
67 }
68 return values;
69 }
70
71
72
73
74
75
76
77 protected abstract List<Country> retrieveCountriesForValuesFinder();
78
79
80
81
82
83
84
85 protected Country getDefaultCountry() {
86 return LocationApiServiceLocator.getCountryService().getDefaultCountry();
87 }
88
89 }