private void updateWeatherForecasts(Event e) throws InvalidInputException, NotFoundException { if (e.getStatus() != EventStatus.PLANNED) { return; } // Ask new weather forecasts List<WeatherForecast> newForecasts = weatherForecastFacade.askWeatherForecasts(e.getId()); boolean newForecastsGood = e.areForecastsGood(newForecasts); if (e.getWeatherForecasts() != null && e.getWeatherForecasts().size() != 0) { // Check good/ bad boolean currentForecastsGood = e.areCurrentForecastsGood(); // Disable current weather forecasts disableWeatherForecasts(e); // Produce notification if good -> bad, bad -> good if (newForecastsGood != currentForecastsGood) { // Produce notification notificationFacade.createNotificationForWeatherConditions(e.getId(), newForecastsGood); } } else if (!newForecastsGood) { // Produce notification notificationFacade.createNotificationForWeatherConditions(e.getId(), newForecastsGood); } // Update event with new forecasts e.setWeatherForecasts(newForecasts); weatherForecastFacade.save(newForecasts); if (!newForecastsGood && needsSuggestedScheduling(e)) { // TODO check suggested scheduling updateSuggestedScheduling(e); } }
private void updateSuggestedScheduling(Event e) throws NotFoundException, InvalidInputException { List<WeatherForecastBase> suggestion = weatherForecastFacade.askSuggestion(e.getId()); if (suggestion != null) { e.setSuggestedChangeAvailable(true); if (!e.isSuggestedChangeProvided()) { notificationFacade.createNotificationForSuggestedChange(e.getId()); e.setSuggestedChangeProvided(true); } } else { e.setSuggestedChangeAvailable(false); } }
@Override public List<WeatherForecastBase> askSuggestedChange(int eventID) throws NotFoundException { Event e = eventDAO.retrieve(eventID); if (!needsSuggestedScheduling(e)) { return null; } try { return weatherForecastFacade.askSuggestion(eventID); } catch (InvalidInputException ex) { Logger.getLogger(EventFacadeImplementation.class.getName()).log(Level.SEVERE, null, ex); } return null; }
private void disableWeatherForecasts(Event e) { for (WeatherForecast wf : e.getWeatherForecasts()) { weatherForecastFacade.disable(wf); } }