// Path: src/main/java/org/chorem/ecd/model/settings/Location.java
// public class Location {
//     private int id;
// 
//     private String name;
// 
//     private String weatherForecastUrl;
// 
//     public Location() {
//     }
// 
//     public Location(String name, String weatherForecastUrl) {
//         this.name = name;
//         this.weatherForecastUrl = weatherForecastUrl;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getWeatherForecastUrl() {
//         return weatherForecastUrl;
//     }
// 
//     public void setWeatherForecastUrl(String weatherForecastUrl) {
//         this.weatherForecastUrl = weatherForecastUrl;
//     }
// 
// }
// 
// Path: src/main/java/org/chorem/ecd/service/LocationService.java
// @ApplicationScoped
// public class LocationService {
// 
//     private static final Logger logger = LoggerFactory.getLogger(LocationService.class);
// 
//     @Inject
//     protected SettingsDao settingsDao;
// 
//     @Inject
//     protected EcdConfig config;
// 
//     @Inject
//     protected JsonService jsonService;
// 
//     @Inject
//     protected PeriodicTasksExecutorService periodicTasksExecutorService;
// 
//     @PostConstruct
//     public void init() {
//         periodicTasksExecutorService.schedule(getWeatherForecastBuilderTask());
//     }
// 
//     public WeatherForecast getWeatherForecast() {
//         try {
//             WeatherForecast weatherForecast = jsonService.loadFromJson(WeatherForecast.class, config.getWeatherForecastPath());
//             return Optional.ofNullable(weatherForecast).orElse(new WeatherForecast());
//         } catch (IOException e) {
//             logger.error(e.getMessage(), e);
//             return null;
//         }
//     }
// 
//     public Location getLocation() {
//         return settingsDao.getLocation();
//     }
// 
//     @TransactionRequired
//     public void setLocation(Location location) {
//         String weatherForecastUrl = location.getWeatherForecastUrl().replace("/meteo/localite/", "/services/json/");
//         location.setWeatherForecastUrl(weatherForecastUrl);
//         settingsDao.setLocation(location);
// 
//         periodicTasksExecutorService.schedule(getWeatherForecastBuilderTask());
//     }
// 
//     private WeatherForecastBuilderPeriodicTask getWeatherForecastBuilderTask() {
//         String forecastUrl = settingsDao.getLocation().getWeatherForecastUrl();
//         WeatherForecastBuilderPeriodicTask task = new WeatherForecastBuilderPeriodicTask(forecastUrl);
//         task.setConfig(config);
//         task.setJsonService(jsonService);
//         return task;
//     }
// 
// }


import org.chorem.ecd.model.settings.Location;
import org.chorem.ecd.service.LocationService;
import spark.Request;
import spark.Response;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
package org.chorem.ecd.endpoint;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@ApplicationScoped
public class LocationEndpoint extends Endpoint {

    @Inject
// Path: src/main/java/org/chorem/ecd/model/settings/Location.java
// public class Location {
//     private int id;
// 
//     private String name;
// 
//     private String weatherForecastUrl;
// 
//     public Location() {
//     }
// 
//     public Location(String name, String weatherForecastUrl) {
//         this.name = name;
//         this.weatherForecastUrl = weatherForecastUrl;
//     }
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(String name) {
//         this.name = name;
//     }
// 
//     public String getWeatherForecastUrl() {
//         return weatherForecastUrl;
//     }
// 
//     public void setWeatherForecastUrl(String weatherForecastUrl) {
//         this.weatherForecastUrl = weatherForecastUrl;
//     }
// 
// }
// 
// Path: src/main/java/org/chorem/ecd/service/LocationService.java
// @ApplicationScoped
// public class LocationService {
// 
//     private static final Logger logger = LoggerFactory.getLogger(LocationService.class);
// 
//     @Inject
//     protected SettingsDao settingsDao;
// 
//     @Inject
//     protected EcdConfig config;
// 
//     @Inject
//     protected JsonService jsonService;
// 
//     @Inject
//     protected PeriodicTasksExecutorService periodicTasksExecutorService;
// 
//     @PostConstruct
//     public void init() {
//         periodicTasksExecutorService.schedule(getWeatherForecastBuilderTask());
//     }
// 
//     public WeatherForecast getWeatherForecast() {
//         try {
//             WeatherForecast weatherForecast = jsonService.loadFromJson(WeatherForecast.class, config.getWeatherForecastPath());
//             return Optional.ofNullable(weatherForecast).orElse(new WeatherForecast());
//         } catch (IOException e) {
//             logger.error(e.getMessage(), e);
//             return null;
//         }
//     }
// 
//     public Location getLocation() {
//         return settingsDao.getLocation();
//     }
// 
//     @TransactionRequired
//     public void setLocation(Location location) {
//         String weatherForecastUrl = location.getWeatherForecastUrl().replace("/meteo/localite/", "/services/json/");
//         location.setWeatherForecastUrl(weatherForecastUrl);
//         settingsDao.setLocation(location);
// 
//         periodicTasksExecutorService.schedule(getWeatherForecastBuilderTask());
//     }
// 
//     private WeatherForecastBuilderPeriodicTask getWeatherForecastBuilderTask() {
//         String forecastUrl = settingsDao.getLocation().getWeatherForecastUrl();
//         WeatherForecastBuilderPeriodicTask task = new WeatherForecastBuilderPeriodicTask(forecastUrl);
//         task.setConfig(config);
//         task.setJsonService(jsonService);
//         return task;
//     }
// 
// }


// Path: src/main/java/org/chorem/ecd/endpoint/LocationEndpoint.java
import org.chorem.ecd.model.settings.Location;
import org.chorem.ecd.service.LocationService;
import spark.Request;
import spark.Response;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

package org.chorem.ecd.endpoint;



/**
 * @author Julien Gaston (gaston@codelutin.com)
 */
@ApplicationScoped
public class LocationEndpoint extends Endpoint {

    @Inject
    protected LocationService locationService;