Пример #1
0
 private String getStationDescription(Station station) {
   StringBuilder result = new StringBuilder();
   result.append(station.getName());
   BigDecimal distance = station.getDistance();
   String distanceUnits = station.getUnit();
   if (distance != null && distanceUnits != null) {
     result.append(" (");
     result.append(distance.toPlainString());
     result.append(" ");
     result.append(distanceUnits);
     result.append(")");
   }
   return result.toString();
 }
Пример #2
0
  private void findStationAction(
      ConfigData configData, ResponseWriter writer, HttpServletRequest req) {
    try {
      WeatherServiceImpl ws = (WeatherServiceImpl) configData.getWeatherService();
      String key = req.getParameter(PARAM_LOCATION);
      Station[] stations = ws.findStations(isLocationKeyZipCode(key), getLocationKeyCode(key));

      for (Station station : stations) {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put(FIELD_KEY, station.getId());
        data.put(FIELD_NAME, getStationDescription(station));
        writer.appendToArray("list", data);
      }
    } catch (WeatherServiceException e) {
      writer.addError("Error getting weather service:" + e.getMessage());
      Logging.println("Error getting weather service:" + e.getMessage(), e);
    }
  }