예제 #1
0
 /**
  * Create a StateCodeDataType.Enum as defined in UniversalCodes 2.0 from the given name of the
  * state.
  *
  * @param StateCode The state name
  * @return The StateCodeDataType type corresponding to the given State code.
  */
 public StateCodeDataType.Enum getStateCodeDataType(
     String countryAlternateCode, String stateName) {
   StateCodeDataType.Enum stateCodeDataType = null;
   State state = s2sUtilService.getStateFromName(countryAlternateCode, stateName);
   if (state != null) {
     StringBuilder stateDetail = new StringBuilder();
     stateDetail.append(state.getCode());
     stateDetail.append(": ");
     stateDetail.append(WordUtils.capitalizeFully(state.getName()));
     stateCodeDataType = StateCodeDataType.Enum.forString(stateDetail.toString());
   }
   return stateCodeDataType;
 }
  @Override
  public List<KeyValue> getKeyValues() {
    List<KeyValue> labels = new ArrayList<KeyValue>();
    List<State> baseCodes;
    if (StringUtils.isEmpty(countryCode)) {
      findCurrentPersonCountryCode();
      if (StringUtils.isEmpty(countryCode)) {
        labels.add(new ConcreteKeyValue("", ""));
        return labels;
      } else {
        baseCodes = LocationApiServiceLocator.getStateService().findAllStatesInCountry(countryCode);
      }
    } else {
      baseCodes = LocationApiServiceLocator.getStateService().findAllStatesInCountry(countryCode);
    }

    List<State> codes = new ArrayList<State>(baseCodes);
    Collections.sort(
        codes,
        new Comparator<State>() {
          @Override
          public int compare(State o1, State o2) {
            int countryCompare = o1.getCountryCode().compareTo(o2.getCountryCode());
            if (countryCompare == 0) {
              int stateCompare = o1.getName().compareTo(o2.getName());
              return stateCompare;
            } else {
              return countryCompare;
            }
          }
        });

    List<KeyValue> newLabels = new ArrayList<KeyValue>();
    newLabels.add(new ConcreteKeyValue("", ""));
    for (State state : codes) {
      if (state.isActive()) {
        newLabels.add(
            new ConcreteKeyValue(
                state.getCode(), state.getCountryCode() + " - " + state.getName()));
      }
    }
    labels = newLabels;

    clearInternalCache();
    return labels;
  }
  public static List<KeyValue> getKeyValues(String countryCodePassedIn) {
    List<KeyValue> labels = new ArrayList<KeyValue>();
    if (StringUtils.isNotEmpty(countryCodePassedIn)) {
      String determinedCountryCode;
      if (countryCodePassedIn.length() == 2) {
        determinedCountryCode = countryCodePassedIn;
      } else {
        ProposalCountryService proposalCountryService =
            KraServiceLocator.getService(ProposalCountryService.class);
        determinedCountryCode =
            proposalCountryService.convertAltCountryCodeToRealCountryCode(countryCodePassedIn);
      }

      List<State> baseCodes =
          LocationApiServiceLocator.getStateService().findAllStatesInCountry(determinedCountryCode);
      List<State> codes = new ArrayList<State>(baseCodes);
      Collections.sort(
          codes,
          new Comparator<State>() {
            @Override
            public int compare(State o1, State o2) {
              int countryCompare = o1.getCountryCode().compareTo(o2.getCountryCode());
              if (countryCompare == 0) {
                int stateCompare = o1.getName().compareTo(o2.getName());
                return stateCompare;
              } else {
                return countryCompare;
              }
            }
          });

      List<KeyValue> newLabels = new ArrayList<KeyValue>();
      newLabels.add(new ConcreteKeyValue("", ""));
      for (State state : codes) {
        if (state.isActive()) {
          newLabels.add(
              new ConcreteKeyValue(
                  state.getCode(), state.getCountryCode() + " - " + state.getName()));
        }
      }
      labels = newLabels;
    }

    return labels;
  }