Exemple #1
0
 @Override
 public void onDestroy() {
   for (ForecastReport forecastReport : forecastReports.values()) {
     forecastReport.onDestroy();
   }
   this.forecastReports.clear();
   this.forecastReports = null;
   super.onDestroy();
 }
Exemple #2
0
 public synchronized void unsubscribe(String place) {
   if (place != null && !place.isEmpty()) {
     if (place.equals(Constants.LOCATION_CURRENT_PLACE)) {
       place = getPlaceLocation(place, false).getPlace();
     }
     ForecastReport forecastReport = forecastReports.get(place);
     if (forecastReport != null) {
       forecastReport.onDestroy();
       forecastReports.remove(forecastReport.place);
     }
   }
 }
Exemple #3
0
 public int changeForecastMode(String place) {
   if (place != null && !place.equals("")) {
     ForecastReport forecastReport = getForecastReport(place, -1, null);
     if (forecastReport != null) {
       if (forecastReport.forecastMode == Constants.WEATHER_FORECAST_DAILY) {
         forecastReport.forecastMode = Constants.WEATHER_FORECAST_HOURLY;
       } else {
         forecastReport.forecastMode = Constants.WEATHER_FORECAST_DAILY;
       }
       return forecastReport.forecastMode;
     }
   }
   return Constants.WEATHER_FORECAST_HOURLY;
 }
Exemple #4
0
 private void update(ForecastReport forecastReport) throws Exception {
   findWeatherData(new LocationVO(forecastReport.place), -1, -1, true, null, false).join();
   List results = validateRules(forecastReport);
   if (!results.isEmpty()) {
     ForecastReport fr = new ForecastReport();
     fr.place = forecastReport.place;
     for (Object result : results) {
       if (result instanceof HourWeatherVO) {
         fr.hourlyWeatherList.add((HourWeatherVO) result);
       } else if (result instanceof DayWeatherVO) {
         fr.dailyWeatherList.add((DayWeatherVO) result);
       }
     }
     forecastReport.forecastMode = -1;
     sendResponse(fr, null, false, true);
   }
 }
Exemple #5
0
  private synchronized ForecastReport getForecastReport(
      LocationVO locationVO, long refreshTime, List<WeatherProposition> rules) {

    String place =
        locationVO.getSubArea() != null
            ? locationVO.getSubArea()
            : locationVO.getCity() != null
                ? locationVO.getCity()
                : locationVO.getWoeidVO() != null && locationVO.getWoeidVO().getName() != null
                    ? locationVO.getWoeidVO().getName()
                    : null;
    if (place == null) {
      mb.send(
          WeatherEvent.build()
              .setIsError(true)
              .setErrorMessage("A place is required in order to get the forecast report."));
      return null;
    }
    ForecastReport forecastReport = forecastReports.get(place.replace(" ", "_"));
    if (forecastReport == null) {
      forecastReport = new ForecastReport(refreshTime);
      forecastReport.place = place;
      forecastReports.put(place, forecastReport);
    }
    if (locationVO == null) {
      locationVO = new LocationVO(place);
    }
    if (forecastReport.locationVO != null) {
      forecastReport.locationVO.mergeLocation(locationVO);
    } else {
      forecastReport.locationVO = locationVO;
    }

    if (refreshTime > 0 && refreshTime != forecastReport.refreshTime) {
      forecastReport.refreshTime = refreshTime;
      forecastReport.initTimer();
    }
    if (rules != null && !rules.isEmpty()) {
      forecastReport.rules = rules;
    }
    return forecastReport;
  }