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