1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.framework.state; |
18 | |
|
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.shareddata.api.services.SharedDataApiServiceLocator; |
23 | |
import org.kuali.rice.shareddata.api.state.State; |
24 | |
|
25 | |
import java.util.ArrayList; |
26 | |
import java.util.Collections; |
27 | |
import java.util.Comparator; |
28 | |
import java.util.List; |
29 | |
|
30 | 0 | public class StateValuesFinder extends KeyValuesBase { |
31 | |
|
32 | 0 | private String countryCode = "US"; |
33 | |
|
34 | |
@Override |
35 | |
public List<KeyValue> getKeyValues() { |
36 | 0 | List<KeyValue> labels = new ArrayList<KeyValue>(); |
37 | 0 | List<State> baseCodes = SharedDataApiServiceLocator.getStateService().findAllStatesInCountry(countryCode); |
38 | 0 | List<State> codes = new ArrayList<State>( baseCodes ); |
39 | 0 | Collections.sort(codes, new Comparator<State> () { |
40 | |
@Override |
41 | |
public int compare(State o1, State o2) { |
42 | 0 | return o1.getName().compareTo(o2.getName()); |
43 | |
} |
44 | |
}); |
45 | |
|
46 | 0 | List<KeyValue> newLabels = new ArrayList<KeyValue>(); |
47 | 0 | newLabels.add(new ConcreteKeyValue("", "")); |
48 | 0 | for (State state : codes) { |
49 | 0 | if(state.isActive()) { |
50 | 0 | newLabels.add(new ConcreteKeyValue(state.getCode(), state.getName())); |
51 | |
} |
52 | |
} |
53 | 0 | labels = newLabels; |
54 | |
|
55 | 0 | return labels; |
56 | |
} |
57 | |
|
58 | |
public void setCountryCode(String countryCode) { |
59 | 0 | this.countryCode = countryCode; |
60 | 0 | } |
61 | |
|
62 | |
|
63 | |
@Override |
64 | |
public void clearInternalCache() { |
65 | 0 | } |
66 | |
} |